per_page) || is_null($request)) { $pagination = 5; } else { $pagination = $request->per_page; } return File::searchFilter($request) ->where('import_status', '=', 0) ->with('track_type') ->with('owner') ->orderBy('artist_name') ->paginate($pagination) ->toJson(); } /** * Save first data into cc_files row and the file in libretime-tmp storage, * then send a message to Analyzer to move it to libretime-storage (then Analyzer * call the update method) * @param Request $request * @return void * @throws \Exception */ public function store(Request $request) { $user = Auth::user(); //Accept request only from logged-in users if (!$user) { throw new \Exception("You must be logged in"); } //Mime type list: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types $request->validate([ 'file' => 'required|file|mimes:audio/mpeg,mpga,mp3,audio/x-wav,audio/ogg,audio/mp4', ]); $file = $request->file('file'); $originalName = $file->getClientOriginalName(); $time = new LengthFormatter('00:00:00'); $dbFile = File::create([ 'import_status' => 1, 'currentlyaccessing' => 0, 'md5' => md5($request->file('file')->getRealPath()), 'length' => $time->format(), //preparare helper che trasforma tempo in 0 years 0 mons 0 days 0 hours 0 mins 0.0 secs 'file_exists' => true, 'owner_id' => $user->id, //Get the user ID 'cuein' => $time->format(), //preparare helper che trasforma tempo in 0 years 0 mons 0 days 0 hours 0 mins 0.0 secs 'cueout' => $time->format(), //preparare helper che trasforma tempo in 0 years 0 mons 0 days 0 hours 0 mins 0.0 secs 'silan_check' => false, 'hidden' => true, 'is_scheduled' => false, 'is_playlist' => false, '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); RabbitMQSender::SendMessageToAnalyzer( $tmpFile->getPathname(), Storage::disk('libretime-upload')->path('').'/'.$user->id, $originalName, $dbFile->id, $dbFile->track_type_id ); return $dbFile->toJson(); } /** * Retrieve a single file metadata * @param $id * @return mixed */ public function show($id) { return File::whereId($id)->first()->toJson(); } /** * Update a cc_files row, either with metadata from Analyzer or * with manually updated metadata * @param Request $request * @param $id * @return mixed */ public function update(Request $request, $id) { $file = File::whereId($id)->first(); $fields = $request->all(); if (is_null($fields['name'])) { unset($fields['name']); } //Only from Analyzer if (isset($fields['full_path'])) { $fields['filepath'] = $fields['full_path']; } //Check Import status if ($fields['import_status'] == 'PipelineStatus.SUCCEED') { $fields['import_status'] = 0; } //Check if there is a track type id, if not add "MUSIC" id if (is_null($file->track_type_id)) { $fields['track_type_id'] = TrackType::where('code','MUSICA')->first()->id; } //return json_encode(['req' => $fields,'id' => $id]); $file->fill($fields)->save(); return $file->toJson(); } /** * Delete file from storage and DB * @param $id * @return true */ public function destroy($id) { $file = File::whereId($id)->first(); Storage::disk('libretime')->delete($file->filepath); $file->delete(); return true; } public function checkUploadStatus($id) { return File::whereId($id)->first()->only('import_status'); } //Test Method, must be deleted before finishing public function test() { return view('upload'); } }