upload notifications for matrix

This commit is contained in:
2024-02-24 22:19:34 +01:00
parent de12738c63
commit 8864f3c841
2 changed files with 27 additions and 21 deletions

View File

@@ -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 &"); // 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')) { if (config('matrix.enabled') && config('matrix.token') && config('matrix.homeserver') && config('matrix.room')) {
$nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute());
$nsfw = $nsfw ? ' NSFW' : ''; $mauauth = config('matrix.mauauth');
$message = config('matrix.message'); $mauurl = config('matrix.mauurl');
$message = str_replace(
['<USER>', '<ID>', '<NSFW>'],
[$user->username, $video->id, $nsfw],
$message
);
$token = config('matrix.token');
$homeserver = config('matrix.homeserver');
$room = config('matrix.room');
$payload = json_encode([ $payload = json_encode([
"msgtype" => "m.text", "user" => $user->username,
"body" => $message "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>', '<ID>', '<NSFW>'],
// [$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([ return new JsonResponse([

View File

@@ -1,8 +1,6 @@
<?php <?php
return [ return [
'enabled' => true, 'enabled' => true,
'homeserver' => env('MATRIX_HOMESERVER'), 'mauauth' => env('MATRIX_MAUAUTH'),
'room' => env('MATRIX_ROOMID'), 'mauurl' => env('MATRIX_MAUURL')
'token' => env('MATRIX_TOKEN'),
'message' => '<USER> uploaded a new <NSFW> webm: https://w0bm.com/<ID>',
]; ];