A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
Add history deletion
aminnausin78d4ff9e5d21
diff --git a/app/Http/Controllers/RecordController.php b/app/Http/Controllers/RecordController.phpindex 56dbaa2c..919503d5 100644--- a/app/Http/Controllers/RecordController.php+++ b/app/Http/Controllers/RecordController.php@@ -89,7 +89,7 @@ class RecordController extends Controller*/public function destroy(Record $record){- return $this->isNotAuthorised($record) ?? $record->delete();+ return $this->isNotAuthorised($record) ?? $record->delete() ? $this->success('', 'Success', 200) : $this->error('','Not found', 404);}private function isNotAuthorised(Record $record)diff --git a/public/js/history.js b/public/js/history.jsindex 11bede9c..99b49561 100644--- a/public/js/history.js+++ b/public/js/history.js@@ -124,30 +124,40 @@ async function addToHistory(id){function parseHistory(data, empty = true) {let destination = '#content-history';- let recordTemplate = function(videoName, folderName, timeSpan, date) {+ let recordTemplate = function(videoName, folderName, timeSpan, date, recordID) {return `- <div class="flex flex-wrap rounded-xl dark:bg-neutral-800 dark:hover:bg-neutral-700 hover:bg-slate-200 bg-slate-100 dark:text-white shadow p-3 w-full divide-y divide-gray-300 group flex-grow cursor-pointer">- <section class="flex justify-between items-baseline w-full">- <h2 class="text-xl text-left truncate">${videoName}</h2>- <h2 class="text-xl text-right truncate">${date}</h2>- </section>- <aside class="flex justify-between items-center w-full pt-1">- <h3 class="text-lg text-left text-neutral-500 truncate">${folderName}</h3>- <h3 class="text-lg text-right text-neutral-500 text-nowrap line-clamp-1 truncate">${timeSpan}</h3>- <span class="hidden flex space-x-1">- <button class="hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2">Watch</button>- <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">- <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5 12 21m0 0-7.5-7.5M12 21V3" />- </svg>- </span>- </aside>+ <div class="flex gap-12 group cursor-default">+ <div class="flex rounded-xl items-center justify-center dark:bg-neutral-800 dark:hover:bg-neutral-700 hover:bg-slate-200 bg-slate-100 dark:text-white shadow p-3 w-full group flex-grow cursor-pointer">+ <div class="w-full flex-wrap divide-y divide-gray-300">+ <section class="flex justify-between items-baseline w-full">+ <h2 class="text-xl text-left truncate">${videoName}</h2>+ <h2 class="text-xl text-right truncate">${date}</h2>+ </section>+ <aside class="flex justify-between items-center w-full pt-1">+ <h3 class="text-lg text-left text-neutral-500 truncate">${folderName}</h3>+ <h3 class="text-lg text-right text-neutral-500 text-nowrap line-clamp-1 truncate">${timeSpan}</h3>+ <span class="hidden flex space-x-1">+ <button class="hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2">Watch</button>+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">+ <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5 12 21m0 0-7.5-7.5M12 21V3" />+ </svg>+ </span>+ </aside>+ </div>+ </div>+ <div class="aspect-square rounded-full items-center justify-center group-hover:visible invisible flex">+ <button class="record-delete w-full p-3 items-center justify-center rounded-xl bg-red-700 hover:bg-red-600" data-id='${recordID}'>+ Delete+ </button>+ </div></div>`}- if(empty) $(destination).empty();+ //if(empty) $(destination).empty();for (let recordCount = 0; recordCount < data.length; recordCount++) {+ const recordID = data[recordCount].id;const videoName = data[recordCount].relationships.video_name;const folderName = data[recordCount].relationships.folder_name;const categoryName = data[recordCount].relationships.category_name;@@ -162,17 +172,46 @@ function parseHistory(data, empty = true) {const timeSpan = weeks > 0 ? `${weeks} week${weeks > 1 ? 's' : ''} ago` : days > 0 ? `${days} day${days > 1 ? 's' : ''} ago` : hours > 0 ? `${hours} hour${hours > 1 ? 's' : ''} ago` : minutes > 0 ? `${minutes}m ago` : `${seconds}s ago`- let recordElement = recordTemplate(videoName, folderName, timeSpan, `${rawDate.toLocaleDateString([], {year: "numeric", month: '2-digit', day: '2-digit', hour: '2-digit', hour12:false, minute:'2-digit'})}`);+ let recordElement = recordTemplate(videoName, folderName, timeSpan, `${rawDate.toLocaleDateString([], {year: "numeric", month: '2-digit', day: '2-digit', hour: '2-digit', hour12:false, minute:'2-digit'})}`, recordID);if(empty) $(destination).append(recordElement)else {$(destination).children().last().remove();$(destination).prepend(recordElement);}- $(destination).children().last().on('click', () => {+ $(destination).children().last().children().first().on('click', () => {window.location.href = `/${categoryName}/${folderName}`})}++ $(".record-delete").off('click').on('click.delete', function(){+ const id = parseInt($(this).data('id'));+ const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');++ if(isNaN(id)){+ toastr.error(`Invalid Record ID... ${$(this).data('id')}`);+ return;+ }++ fetch(`/api/records/${id}`, {+ method: 'delete',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': csrfToken+ }+ }).then((response) =>+ response.json()+ ).then((json) => {+ if(json.success == true) {+ toastr.success('Record deleted!');+ $(this).parent().parent().remove();+ };+ }).catch((error) => {+ console.log(error);+ toastr.error('Unable to delete record.');+ });+ })}function toggleDarkMode(){diff --git a/resources/views/profile/history.blade.php b/resources/views/profile/history.blade.phpindex 94c51385..e9eb4610 100644--- a/resources/views/profile/history.blade.php+++ b/resources/views/profile/history.blade.php@@ -90,7 +90,31 @@<hr class="mt-2 mb-3"></nav><section id="content-history" class=" space-y-2 cursor-pointer min-h-[80vh] pt-8">-+ <div class="flex gap-12 group cursor-default hidden">+ <div class="flex rounded-xl items-center justify-center dark:bg-neutral-800 dark:hover:bg-neutral-700 hover:bg-slate-200 bg-slate-100 dark:text-white shadow p-3 w-full group flex-grow cursor-pointer">+ <div class="w-full flex-wrap divide-y divide-gray-300">+ <section class="flex justify-between items-baseline w-full">+ <h2 class="text-xl text-left truncate">${videoName}</h2>+ <h2 class="text-xl text-right truncate">${date}</h2>+ </section>+ <aside class="flex justify-between items-center w-full pt-1">+ <h3 class="text-lg text-left text-neutral-500 truncate">${folderName}</h3>+ <h3 class="text-lg text-right text-neutral-500 text-nowrap line-clamp-1 truncate">${timeSpan}</h3>+ <span class="hidden flex space-x-1">+ <button class="hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2">Watch</button>+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">+ <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5 12 21m0 0-7.5-7.5M12 21V3" />+ </svg>+ </span>+ </aside>+ </div>+ </div>+ <div class="aspect-square rounded-full items-center justify-center group-hover:visible invisible flex">+ <button class="record-delete w-full p-3 items-center justify-center rounded-xl bg-red-700 hover:bg-red-600" data-id='${recordID}'>+ Delete+ </button>+ </div>+ </div></section></section><section id="left-card" class="w-full lg:w-72 shrink-0 hidden lg:block"></section>diff --git a/routes/web.php b/routes/web.phpindex 8a495557..ad813204 100644--- a/routes/web.php+++ b/routes/web.php@@ -19,7 +19,6 @@ Route::get('/', function () { return redirect('/anime/ODDTAXI'); })->name('home'Route::get('login', [AuthController::class, 'create'])->name('login');Route::post('login', [AuthController::class, 'login'])->name('login');-Route::get('register', [AuthController::class, 'generate'])->name('register');Route::post('register', [AuthController::class, 'register'])->name('register');@@ -32,25 +31,18 @@ Route::middleware('auth')->group(function () {Route::post('/logout', [AuthController::class, 'destroy'])->name('logout');Route::get('/jobs/indexFiles', [DirectoryController::class, 'indexFiles']);Route::get('/jobs/syncFiles', [DirectoryController::class, 'syncFiles']);- Route::get('/welcome', function () { return view('welcome'); });Route::get('/history', function () { return view('profile/history'); });- // Route::get('/legacy', [DirectoryController::class, 'showDirectory'])->defaults('dir', 'legacy')->defaults('folder_name', 'Unsorted');- // Route::get('/legacy/{folder_name}', [DirectoryController::class, 'showDirectory'])->defaults('dir', 'legacy')->defaults('folder_name', 'Unsorted');});// public-// Route::get('/', function () { return view('home', ['dir' => 'anime', 'folder_name' => null]); })->name('home');-// Route::get('/testing', function () { return redirect()->route('home'); })->name('testing');-// Route::get('/welcome', function () { return view('welcome'); });--+Route::get('/welcome', function () { return view('welcome'); });Route::get('/{dir}', [DirectoryController::class, 'showDirectory']);Route::get('/{dir}/{folder_name}', [DirectoryController::class, 'showDirectory']);// old-Route::post('/ajax/generateDir', [DirectoryController::class, 'generateDirectory']);-Route::post('/ajax/getFolders', [DirectoryController::class, 'getDirectoryContents']);-Route::post('/ajax/getVideos', [DirectoryController::class, 'getFolderContents']);\ No newline at end of file+// Route::post('/ajax/generateDir', [DirectoryController::class, 'generateDirectory']);+// Route::post('/ajax/getFolders', [DirectoryController::class, 'getDirectoryContents']);+// Route::post('/ajax/getVideos', [DirectoryController::class, 'getFolderContents']);\ No newline at end of file