diff --git a/app/Http/Livewire/News/ArticleOverview.php b/app/Http/Livewire/News/ArticleOverview.php index 187d0725..e8510057 100644 --- a/app/Http/Livewire/News/ArticleOverview.php +++ b/app/Http/Livewire/News/ArticleOverview.php @@ -4,6 +4,7 @@ namespace App\Http\Livewire\News; use App\Models\LibraryItem; use App\Traits\TwitterTrait; +use Illuminate\Support\Facades\Process; use Livewire\Component; use RalphJSmit\Laravel\SEO\Support\SEOData; use WireUi\Traits\Actions; @@ -31,7 +32,7 @@ class ArticleOverview extends Component if ($libraryItem->lecturer->twitter_username && $libraryItem->type !== 'markdown_article') { $libraryItemName .= ' von @'.$libraryItem->lecturer->twitter_username; } - if (! $libraryItem->lecturer->twitter_username) { + if (!$libraryItem->lecturer->twitter_username) { $libraryItemName .= ' von '.$libraryItem->lecturer->name; } @@ -39,7 +40,7 @@ class ArticleOverview extends Component if (config('feeds.services.twitterAccountId')) { $this->setNewAccessToken(1); - if (! $libraryItem->approved) { + if (!$libraryItem->approved) { $this->notification() ->error(__('Article not approved yet')); @@ -68,6 +69,42 @@ class ArticleOverview extends Component } } + public function nostr($id) + { + $libraryItem = LibraryItem::query() + ->with([ + 'lecturer', + ]) + ->find($id); + $libraryItem->setStatus('published'); + $libraryItemName = $libraryItem->name; + if (!$libraryItem->lecturer->nostr) { + $libraryItemName .= ' von @'.$libraryItem->nostr->name; + } else { + $libraryItemName .= ' von '.$libraryItem->lecturer->name; + } + $text = sprintf("Ein neuer News-Artikel wurde verfasst:\n\n%s\n\n%s\n\n#Bitcoin #News #Einundzwanzig #gesundesgeld", + $libraryItemName, + url()->route('article.view', + ['libraryItem' => $libraryItem->slug]), + ); + + //noscl publish "Good morning!" + $result = Process::run('noscl publish "'.$text.'"'); + + if ($result->successful()) { + $libraryItem->nostr = $result->output(); + $libraryItem->save(); + $this->notification() + ->success(title: __('Published on Nostr'), description: $result->output()); + } + if ($result->failed()) { + $this->notification() + ->error(title: __('Failed'), + description: 'Exit Code: '.$result->exitCode().' Reason: '.$result->errorOutput()); + } + } + public function approve($id) { $libraryItem = LibraryItem::find($id); diff --git a/database/migrations/2023_02_23_195737_add_nostr_field_to_library_items_table.php b/database/migrations/2023_02_23_195737_add_nostr_field_to_library_items_table.php new file mode 100644 index 00000000..3b08492d --- /dev/null +++ b/database/migrations/2023_02_23_195737_add_nostr_field_to_library_items_table.php @@ -0,0 +1,28 @@ +text('nostr') + ->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('library_items', function (Blueprint $table) { + // + }); + } +}; diff --git a/docker-compose.yml b/docker-compose.yml index e2ed6728..e6a4b8e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' + NOSTR_PRIVATE_KEY: '${NOSTR_PRIVATE_KEY}' image: sail-8.2/app extra_hosts: - 'host.docker.internal:host-gateway' @@ -41,7 +42,7 @@ services: networks: - sail healthcheck: - test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}"] + test: [ "CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}" ] retries: 3 timeout: 5s redis: @@ -53,7 +54,7 @@ services: networks: - sail healthcheck: - test: ["CMD", "redis-cli", "ping"] + test: [ "CMD", "redis-cli", "ping" ] retries: 3 timeout: 5s meilisearch: @@ -65,7 +66,7 @@ services: networks: - sail healthcheck: - test: ["CMD", "wget", "--no-verbose", "--spider", "http://localhost:7700/health"] + test: [ "CMD", "wget", "--no-verbose", "--spider", "http://localhost:7700/health" ] retries: 3 timeout: 5s networks: diff --git a/docker/8.2/Dockerfile b/docker/8.2/Dockerfile index 8f38f28d..89bc08e4 100644 --- a/docker/8.2/Dockerfile +++ b/docker/8.2/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:22.04 LABEL maintainer="Taylor Otwell" +ARG NOSTR_PRIVATE_KEY ARG WWWGROUP ARG NODE_VERSION=18 ARG POSTGRES_VERSION=14 @@ -14,7 +15,7 @@ ENV TZ=UTC RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN apt-get update \ - && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils \ + && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils golang wget \ && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \ && echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \ && apt-get update \ @@ -48,6 +49,14 @@ RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.2 RUN groupadd --force -g $WWWGROUP sail RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail +RUN wget https://github.com/fiatjaf/noscl/releases/download/v0.6.0/noscl -O /usr/local/bin/noscl \ + && chmod +x /usr/local/bin/noscl \ + && mkdir -p /home/sail/.config/nostr +COPY nostr.json /home/sail/.config/nostr/config.json +RUN chown -R sail:sail /home/sail/.config +RUN sed -i 's/NOSTR_PRIVATE_KEY/'"$NOSTR_PRIVATE_KEY"'/g' /home/sail/.config/nostr/config.json +# noscl publish "Publish event from https://portal.einundzwanzig.portal - developing a bot for Einundzwanzig Portal" + COPY start-container /usr/local/bin/start-container COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY php.ini /etc/php/8.2/cli/conf.d/99-sail.ini diff --git a/docker/8.2/nostr.json b/docker/8.2/nostr.json new file mode 100644 index 00000000..b1ca6407 --- /dev/null +++ b/docker/8.2/nostr.json @@ -0,0 +1,54 @@ +{ + "relays": { + "wss://nostr.einundzwanzig.space": { + "read": true, + "write": true + }, + "wss://nostr.mom": { + "read": true, + "write": true + }, + "wss://nostr.fmt.wiz.biz": { + "read": true, + "write": true + }, + "wss://relay.damus.io": { + "read": true, + "write": true + }, + "wss://nostr-pub.wellorder.net": { + "read": true, + "write": true + }, + "wss://relay.nostr.info": { + "read": true, + "write": true + }, + "wss://offchain.pub": { + "read": true, + "write": true + }, + "wss://nos.lol": { + "read": true, + "write": true + }, + "wss://brb.io": { + "read": true, + "write": true + }, + "wss://relay.snort.social": { + "read": true, + "write": true + }, + "wss://relay.current.fyi": { + "read": true, + "write": true + }, + "wss://nostr.relayer.se": { + "read": true, + "write": true + } + }, + "following": null, + "privatekey": "NOSTR_PRIVATE_KEY" +} diff --git a/resources/views/livewire/news/article-overview.blade.php b/resources/views/livewire/news/article-overview.blade.php index 080bac6e..dff48e37 100644 --- a/resources/views/livewire/news/article-overview.blade.php +++ b/resources/views/livewire/news/article-overview.blade.php @@ -1,6 +1,6 @@