Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	composer.json
#	composer.lock
This commit is contained in:
Michael 2025-02-11 16:18:43 +01:00
commit 73b02ebd23
7 changed files with 197 additions and 137 deletions

View file

@ -3,14 +3,29 @@
namespace App\Http\Controllers;
use App\Helpers\LengthFormatter;
use App\Jobs\FileJob;
use App\Lib\RabbitMQSender;
use App\Models\File;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Storage;
class FileController extends Controller
{
protected static $propertyDefinitions = array(
'content_type' => 'shortstr',
'content_encoding' => 'shortstr',
'application_headers' => 'table_object',
'delivery_mode' => 'octet',
'priority' => 'octet',
'correlation_id' => 'shortstr',
'reply_to' => 'shortstr',
'expiration' => 'shortstr',
'message_id' => 'shortstr',
'timestamp' => 'timestamp',
'type' => 'shortstr',
'user_id' => 'shortstr',
'app_id' => 'shortstr',
'cluster_id' => 'shortstr',
);
public function index() {
//ToDo
}
@ -47,22 +62,19 @@ class FileController extends Controller
'hidden' => true,
'is_scheduled' => false,
'is_playlist' => false,
'filesize' => 0
'filesize' => 0,
'track_type_id' => $request->track_type_id ? $request->track_type_id : null,
]);
$tmpFile = $file->move(Storage::disk('libretime-tmp')->path(''), $dbFile->id.'-'.$originalName);
//Create array to dispatch to Analyzer
$payload = [
'id' => $dbFile->id,
'tmp_file_path' => $tmpFile->getPathname(),
'import_directory' => Storage::disk('libretime-upload')->path('').'/'.'1', //$user->id,
'original_filename' => $originalName,
'options' => new \stdClass()
];
//Queue::connection('rabbitmq')->pushRaw(json_encode($payload), 'airtime-upload');
//Queue::dispatch(new FileJob($payload));
RabbitMQSender::SendMessageToAnalyzer(
$tmpFile->getPathname(),
Storage::disk('libretime-upload')->path('').'/'.'1', //$user->id,
$originalName,
$dbFile->id,
$dbFile->track_type_id
);
}
public function show($id) {

View file

@ -1,39 +0,0 @@
<?php
namespace App\Jobs;
use App\Models\File;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
class FileJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct()
{
//$this->file = $fileInfo;
$this->file = [
'id' => 1,
'tmp_file_path' => '\/srv\/libretime\/organize\/14-Zela Margossian Quintet - On Ya.mp3',
'import_directory' => '\/srv\/libretime\/\/imported\/1', //$user->id,
'original_filename' => 'Zela Margossian Quintet - On Ya.mp3',
'options' => new \stdClass()
];
}
/**
* Execute the job.
*/
public function handle(): void
{
dd($this->file);
}
}

160
app/Lib/RabbitMQSender.php Normal file
View file

@ -0,0 +1,160 @@
<?php
namespace App\Lib;
use App\Models\TrackType;
use Exception;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use stdClass;
class RabbitMQSender
{
public static $doPush = false;
/**
* Sets a flag to push the schedule at the end of the request.
*/
public static function PushSchedule()
{
self::$doPush = true;
}
private static function sendMessage($exchange, $exchangeType, $autoDeleteExchange, $data, $queue = '')
{
$conn = new AMQPStreamConnection(
config('rabbitmq.host'),
config('rabbitmq.port'),
config('rabbitmq.user'),
config('rabbitmq.password'),
config('rabbitmq.vhost')
);
if (!isset($conn)) {
throw new Exception('Cannot connect to RabbitMQ server');
}
$channel = $conn->channel();
$channel->access_request(
config('rabbitmq.vhost'),
false,
false,
true,
true
);
// I'm pretty sure we DON'T want to autodelete ANY exchanges but I'm keeping the code
// the way it is just so I don't accidentally break anything when I add the Analyzer code in. -- Albert, March 13, 2014
$channel->exchange_declare($exchange, $exchangeType, false, true, $autoDeleteExchange);
$msg = new AMQPMessage($data, ['content_type' => 'text/plain']);
$channel->basic_publish($msg, $exchange);
$channel->close();
$conn->close();
}
public static function SendMessageToPypo($event_type, $md)
{
$md['event_type'] = $event_type;
$exchange = 'airtime-pypo';
$data = json_encode($md, JSON_FORCE_OBJECT);
self::sendMessage($exchange, 'direct', true, $data);
}
public static function SendMessageToMediaMonitor($event_type, $md)
{
$md['event_type'] = $event_type;
$exchange = 'airtime-analyzer';
$data = json_encode($md);
self::sendMessage($exchange, 'direct', true, $data);
}
public static function SendMessageToShowRecorder($event_type)
{
// $exchange = 'airtime-pypo';
//
// $now = new DateTime('@' . time()); // in UTC timezone
// $end_timestamp = new DateTime('@' . (time() + 3600 * 2)); // in UTC timezone
//
// $temp = [];
// $temp['event_type'] = $event_type;
// $temp['server_timezone'] = Preferences::getTimezone();
// if ($event_type == 'update_recorder_schedule') {
// $temp['shows'] = Application_Model_Show::getShows(
// $now,
// $end_timestamp,
// $onlyRecord = true
// );
// }
// $data = json_encode($temp);
//
// self::sendMessage($exchange, 'direct', true, $data);
}
public static function SendMessageToAnalyzer(
$tmpFilePath,
$importedStorageDirectory,
$originalFilename,
$fileId,
$fileTrackTypeId
) {
//$config = Config::getConfig();
$conn = new AMQPStreamConnection(
config('rabbitmq.host'),
config('rabbitmq.port'),
config('rabbitmq.user'),
config('rabbitmq.password'),
config('rabbitmq.vhost')
);
$exchange = 'airtime-uploads';
$exchangeType = 'topic';
$queue = 'airtime-uploads';
$autoDeleteExchange = false;
$data['file_id'] = $fileId;
$data['tmp_file_path'] = $tmpFilePath;
$data['import_directory'] = $importedStorageDirectory;
$data['original_filename'] = $originalFilename;
$options = new stdClass();
if ($fileTrackTypeId) {
$fileTrackType = TrackType::whereId($fileTrackTypeId);
$options->analyze_cue_points = $fileTrackType->analyze_cue_points;
}
$data['options'] = $options;
$jsonData = json_encode($data);
// self::sendMessage($exchange, 'topic', false, $jsonData, 'airtime-uploads');
if (!isset($conn)) {
throw new Exception('Cannot connect to RabbitMQ server');
}
$channel = $conn->channel();
$channel->access_request(
config('rabbitmq.vhost'),
false,
false,
true,
true
);
// I'm pretty sure we DON'T want to autodelete ANY exchanges but I'm keeping the code
// the way it is just so I don't accidentally break anything when I add the Analyzer code in. -- Albert, March 13, 2014
$channel->exchange_declare($exchange, $exchangeType, false, true, $autoDeleteExchange);
$msg = new AMQPMessage($jsonData, ['content_type' => 'text/plain']);
$channel->basic_publish($msg, $exchange);
$channel->close();
$conn->close();
}
}

View file

@ -16,8 +16,8 @@
"livewire/livewire": "^3.4",
"livewire/volt": "^1.0",
"mxl/laravel-job": "^1.6",
"php-amqplib/php-amqplib": "^3.7",
"spatie/laravel-permission": "^6.13",
"vladimir-yuldashev/laravel-queue-rabbitmq": "^14.1",
"xenos/musicbrainz": "^1.0"
},
"require-dev": {

66
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f49892f6eb7bb8fb733e5b8d018d1792",
"content-hash": "9757bb812dad4bb4fe33068d0b32f5f1",
"packages": [
{
"name": "bacon/bacon-qr-code",
@ -6307,70 +6307,6 @@
},
"time": "2024-12-21T16:25:41+00:00"
},
{
"name": "vladimir-yuldashev/laravel-queue-rabbitmq",
"version": "v14.1.0",
"source": {
"type": "git",
"url": "https://github.com/vyuldashev/laravel-queue-rabbitmq.git",
"reference": "3d58891479582ebe988df7c3303efa4784dabccd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vyuldashev/laravel-queue-rabbitmq/zipball/3d58891479582ebe988df7c3303efa4784dabccd",
"reference": "3d58891479582ebe988df7c3303efa4784dabccd",
"shasum": ""
},
"require": {
"ext-json": "*",
"illuminate/queue": "^10.0|^11.0",
"php": "^8.0",
"php-amqplib/php-amqplib": "^v3.6"
},
"require-dev": {
"laravel/framework": "^9.0|^10.0|^11.0",
"laravel/horizon": "^5.0",
"laravel/pint": "^1.2",
"mockery/mockery": "^1.0",
"orchestra/testbench": "^7.0|^8.0|^9.0",
"phpunit/phpunit": "^10.0|^11.0"
},
"suggest": {
"ext-pcntl": "Required to use all features of the queue consumer."
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"VladimirYuldashev\\LaravelQueueRabbitMQ\\LaravelQueueRabbitMQServiceProvider"
]
},
"branch-alias": {
"dev-master": "13.0-dev"
}
},
"autoload": {
"psr-4": {
"VladimirYuldashev\\LaravelQueueRabbitMQ\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Vladimir Yuldashev",
"email": "misterio92@gmail.com"
}
],
"description": "RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.",
"support": {
"issues": "https://github.com/vyuldashev/laravel-queue-rabbitmq/issues",
"source": "https://github.com/vyuldashev/laravel-queue-rabbitmq/tree/v14.1.0"
},
"time": "2024-04-26T22:36:00+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.6.1",

View file

@ -71,24 +71,6 @@ return [
'after_commit' => false,
],
'rabbitmq' => [
'driver' => 'rabbitmq',
'hosts' => [
'host' => env('RABBITMQ_HOST', 'rabbitmq'),
'port' => env('RABBITMQ_PORT', 5672),
'user' => env('RABBITMQ_USER', 'libretime'),
'password' => env('RABBITMQ_PASSWORD', 'libretime'),
'vhost' => env('RABBITMQ_VHOST', '/libretime'),
],
'options' => [
'airtime-upload' => [
'exchange' => 'airtime-upload',
'exchange_type' => 'topic',
'exchange_routing_key' => '',
]
]
]
],
/*

9
config/rabbitmq.php Normal file
View file

@ -0,0 +1,9 @@
<?php
return [
'host' => env('RABBITMQ_HOST', 'localhost'),
'port' => env('RABBITMQ_PORT', 5672),
'user' => env('RABBITMQ_USER', 'libretime'),
'password' => env('RABBITMQ_PASSWORD', 'libretime'),
'vhost' => env('RABBITMQ_VHOST', '/libretime'),
];