From 8864f3c841a69670b9c0f223a691f0be0316c324 Mon Sep 17 00:00:00 2001 From: schrumpel Date: Sat, 24 Feb 2024 22:19:34 +0100 Subject: [PATCH] upload notifications for matrix --- app/Http/Controllers/VideoController.php | 42 ++++++++++++++---------- config/matrix.php | 6 ++-- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/VideoController.php b/app/Http/Controllers/VideoController.php index b3c320a..a48b7f8 100644 --- a/app/Http/Controllers/VideoController.php +++ b/app/Http/Controllers/VideoController.php @@ -164,28 +164,36 @@ class VideoController extends Controller // exec("curl -H \"Content-Type: application/json; charset=UTF-8\" -X POST -d '$payload' '$url' > /dev/null &"); // } - if (config('matrix.enabled') && config('matrix.token') && config('matrix.homeserver') && config('matrix.room')) { - $nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute()); - $nsfw = $nsfw ? ' NSFW' : ''; - $message = config('matrix.message'); - $message = str_replace( - ['', '', ''], - [$user->username, $video->id, $nsfw], - $message - ); - - $token = config('matrix.token'); - $homeserver = config('matrix.homeserver'); - $room = config('matrix.room'); + + $mauauth = config('matrix.mauauth'); + $mauurl = config('matrix.mauurl'); $payload = json_encode([ - "msgtype" => "m.text", - "body" => $message + "user" => $user->username, + "video_id" => $video->id ]); - exec("curl -v -XPOST -d '$payload' '$homeserver$room/send/m.room.message?access_token=$token' > /dev/null &"); - } + exec("curl -X POST -H 'Content-Type: application/json' -u '$mauauth' '$mauurl' -d '$payload' "); + } + + // if (config('matrix.enabled') && config('matrix.token') && config('matrix.homeserver') && config('matrix.room')) { + // $nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute()); + // $nsfw = $nsfw ? ' NSFW' : ''; + // $message = config('matrix.message'); + // $message = str_replace( + // ['', '', ''], + // [$user->username, $video->id, $nsfw], + // $message + // ); + + // $token = config('matrix.token'); + // $homeserver = config('matrix.homeserver'); + // $room = config('matrix.room'); + + + // exec("curl -v -XPOST -d '$payload' '$homeserver$room/send/m.room.message?access_token=$token' > /dev/null &"); + // } return new JsonResponse([ diff --git a/config/matrix.php b/config/matrix.php index ec40068..14c8e9b 100644 --- a/config/matrix.php +++ b/config/matrix.php @@ -1,8 +1,6 @@ true, - 'homeserver' => env('MATRIX_HOMESERVER'), - 'room' => env('MATRIX_ROOMID'), - 'token' => env('MATRIX_TOKEN'), - 'message' => ' uploaded a new webm: https://w0bm.com/', + 'mauauth' => env('MATRIX_MAUAUTH'), + 'mauurl' => env('MATRIX_MAUURL') ];