Skip to content

A self-hosted media server and file management system

UI Updates and Directory request fixes

aminnausin388dc0cd9eb4
diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.php
index 30450362..5eafe467 100644
--- a/app/Http/Controllers/DirectoryController.php
+++ b/app/Http/Controllers/DirectoryController.php
@@ -13,6 +13,7 @@ use Illuminate\Http\Request;
class DirectoryController extends Controller
{
public function showDirectory(Request $request) {
+ // aim -> return directory and folder id where exists so folder controller is usable
$privateCategories = array("legacy"=>1);
if(isset($privateCategories[strtolower($request->dir)]) && !$request->user('sanctum')){
@@ -20,9 +21,16 @@ class DirectoryController extends Controller
return view('error', $data);
}
- $data['dir'] = $request->dir;
- $data['folder_name'] = $request->folder_name;
+ $data['dir'] = array('id'=>Category::select('id')->firstWhere('name', 'ilike', '%' . $request->dir . '%')->id, 'name'=>$request->dir);
+ if(isset($request->folder_name)){
+ $data['folder'] = array('id'=>null, 'name'=>$request->folder_name);
+ }
+ else{
+ $folderRaw = Folder::select('id','name')->firstWhere('category_id', $data['dir']['id']);
+ $data['folder'] = array('id'=>$folderRaw->id, 'name'=>$folderRaw->name);
+ }
+ // dump($data);
return view('home', $data);
}
diff --git a/public/js/main.js b/public/js/main.js
index ed928aa8..d0412a7a 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -23,7 +23,7 @@ var folderData = [];
document.addEventListener("DOMContentLoaded", function(event) {
try {
- if(stateFolderName === null | stateFolderName === undefined) { loadVideos(); }
+ if(stateFolder === null | stateFolder === undefined) { loadVideos(); }
else { loadCategoryFolders(); }
if(document.getElementById('dark-mode-toggle')){
@@ -64,9 +64,9 @@ document.addEventListener("DOMContentLoaded", function(event) {
//#endregion
});
-function reload(newFolder){
- stateFolderName = newFolder;
- window.history.pushState({dir: stateVideoDirectory, folder: stateFolderName},`${stateVideoDirectory} - ${stateFolderName}`, `/${stateVideoDirectory}/${stateFolderName}`);
+function reload(newFolderID, newFolderName){
+ stateFolder = {id: newFolderID, name: newFolderName};
+ window.history.pushState({dir: stateDirectory.name, folder: stateFolder.name},`${stateDirectory.name} - ${stateFolder.name}`, `/${stateDirectory.name}/${stateFolder.name}`);
loadVideosAndParse(folderData);
}
@@ -122,6 +122,7 @@ function cycleSideBar(state){
document.querySelector("#list-card").classList.add("invisible");
document.querySelector("#list-content-history").classList.add("hidden");
document.querySelector("#list-content-folders").classList.add("hidden");
+ document.getElementById('root').scrollIntoView({behavior: "smooth"});
}
}
@@ -140,7 +141,7 @@ async function loadHistory(limit = 10){
}).then((response) =>
response.json()
).then((json) => {
- console.log(json);
+ // console.log(json);
if(json.success == true){
parseHistory(json.data);
console.log('loading history');
@@ -167,7 +168,7 @@ async function addToHistory(id){
}).then((response) =>
response.json()
).then((json) => {
- console.log(json);
+ // console.log(json);
if(json.success == true) {
// toastr['success']('Added to history!');
// loadHistory();
@@ -227,9 +228,7 @@ function parseHistory(data, count = 10, empty = true) {
async function loadCategoryFolders(){
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
- const dir = stateVideoDirectory ?? 'anime';
-
- fetch(`/ajax/getFolders`, {
+ fetch(`/api/folders`, {
method: 'post',
headers: {
'Accept': 'application/json',
@@ -237,18 +236,18 @@ async function loadCategoryFolders(){
'X-CSRF-TOKEN': csrfToken
},
body: JSON.stringify({
- dir:dir
+ category_id:stateDirectory.id
})
}).then((response) =>
response.json()
).then((json) => {
- console.log(json);
+ // console.log(json);
if(json.success == false){
- toastr["error"](`The directory '${dir}' does not exist.`, "Invalid Category");
+ toastr["error"](`The directory '${stateDirectory.name}' does not exist.`, "Invalid Category");
return;
}
- folderData = json.result;
+ folderData = json.data;
parseFolders(folderData);
loadVideosAndParse(folderData);
}).catch((error) => {
@@ -258,49 +257,50 @@ async function loadCategoryFolders(){
async function parseFolders(data){
- var folderTemplate = function(folderName, fileCount) {
+ var folderTemplate = function(folder_id, folder_name, file_count) {
return `
<div class="p-2 flex flex-wrap rounded-xl dark:bg-neutral-800 bg-slate-100 dark:text-white shadow w-full divide-y divide-gray-300 group">
<section class="flex justify-between items-baseline w-full">
- <h2 class="text-xl truncate">${folderName}</h2>
+ <h2 class="text-xl truncate">${folder_name}</h2>
</section>
<aside class="flex justify-between items-center w-full pt-1">
- <h3 class="text-lg text-left text-neutral-500">${fileCount} Episodes</h2>
- <span class="hidden group-hover:flex space-x-1">
- <button class="flex hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2 space-x-1" onClick="reload('${folderName}');">
+ <h3 class="text-lg text-left text-neutral-500">${file_count} Episode${file_count > 1 ? 's' : ''}</h2>
+ <button class="hidden group-hover:flex space-x-1 folder-link" data-id="${folder_id}" data-name="${folder_name}">
+ <span class="flex hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2 space-x-1">
Watch
- </button>
+ </span>
<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>
+ </button>
</aside>
</div>
`
}
- for (let folderCount = 0; folderCount < data.length; folderCount++) {
- const thisFolderName = data[folderCount]['name'];
- const fileCount = data[folderCount]['file_count']
- console.log(data[folderCount]);
- let folderElement = folderTemplate(thisFolderName, fileCount);
+ data.forEach(folder => {
+ const folder_id = folder.id;
+ const folder_name = folder.attributes.name;
+ const file_count = folder.attributes.file_count;
- $('#list-content-folders').append(folderElement);
- }
+ let folder_element = folderTemplate(folder_id, folder_name, file_count);
+
+ $('#list-content-folders').append(folder_element);
+ });
+
+ $('.folder-link').on('mousedown', (e) => {
+ let name = e.currentTarget.dataset.name;
+ let id = e.currentTarget.dataset.id;
+
+ if(e.which != 2) reload(id, name);
+ else window.open(`/${stateDirectory.name}/${name}`, '_blank');
+ });
}
async function loadVideosAndParse(data){
const darkModeSettings = getDarkModeSettings();
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
-
var folderTemplate = function(folderName, folderCount, fileElements) {
-
- old = `
- <button class="col-sm-4 col-lg-2 btn ${darkModeSettings.btnClass} folder-toggle" id="dataTable-${folderCount}-collapse-toggle" type="button" data-bs-toggle="collapse" data-bs-target="#dataTable-${folderCount}-collapse">
- <i class="bi bi-list"></i>
- Show Folder
- </button>
- `
return `
<div class="col-sm-12">
<div class="folder-header row mb-4">
@@ -325,38 +325,31 @@ async function loadVideosAndParse(data){
`
}
var videoTemplate = function(fileArray){
- let fileName = fileArray['path'];
- let title = fileArray['name'];
- let date = fileArray['date'];
- let id = fileArray['id'];
- let filePrefix = '../';
+ const filePath = fileArray.attributes.path;
+ const title = fileArray.attributes.name;
+ const date = fileArray.attributes.date;
+ const id = fileArray.id;
+ const filePrefix = '../';
return `
- <tr class="vid-row" data-id="${id}" data-path="${filePrefix}${fileName}">
- <td class="vid-row-title truncate">${title}</td>
- <td class="vid-row-date truncate">${date}</td>
+ <tr class="vid-row" data-id="${id}" data-path="${filePrefix}${filePath}">
+ <td class="vid-row-title line-clamp-1 truncate">${title}</td>
+ <td class="vid-row-date line-clamp-1 truncate">${date}</td>
</tr>
`
}
-
- let selectedFolderName = stateFolderName;
- let folder_id = -1;
-
- if(selectedFolderName === null | selectedFolderName === undefined) {
- toastr["error"](`An invalid folder name [${selectedFolderName}] was provided in the URL.`, "Invalid Folder");
- return;
- }
-
- // parse the user provided folder name into an actual folder in the directory and get id
- for (let i = 0; i < data.length; i++) {
- const folder = data[i];
- if(folder["name"].toLowerCase().localeCompare(selectedFolderName.toLowerCase()) == 0){
- folder_id = folder["id"];
- selectedFolderName = folder["name"];
- break;
+
+ // parse the user provided folder name into an actual folder in the directory and get id if id not present
+ if(isNaN(parseInt(stateFolder.id))){
+ if(stateFolder.name === null | stateFolder.name === undefined) {
+ toastr["error"](`An invalid folder name [${stateFolder.name}] was provided in the URL.`, "Invalid Folder");
+ return;
}
- }
- fetch(`/ajax/getVideos`, {
+ let res = data.find(folder => folder.attributes["name"].toLowerCase().localeCompare(stateFolder.name.toLowerCase()) == 0);
+ stateFolder = {id: res["id"], name: res.attributes["name"]};
+ }
+
+ fetch(`/api/videos`, {
method: 'post',
headers: {
'Accept': 'application/json',
@@ -364,19 +357,20 @@ async function loadVideosAndParse(data){
'X-CSRF-TOKEN': csrfToken
},
body: JSON.stringify({
- folder_id:folder_id
+ folder_id: stateFolder.id
})
}).then((response) =>
response.json()
).then((json) => {
if(json.success == false){
- toastr["error"](`The folder '${selectedFolderName}' does not exist.`, "Invalid folder");
+ toastr["error"](`The folder '${stateFolder.name}' does not exist.`, "Invalid folder");
return;
}
- const files = json.result;
+ const files = json.data;
+ // console.log(files);
let fileElements = files.map(videoTemplate);
- let folderElement = folderTemplate(selectedFolderName, 0, fileElements.toString().replaceAll(',',''));
+ let folderElement = folderTemplate(stateFolder.name, 0, fileElements.toString().replaceAll(',',''));
$('#dataContainer').empty();
$('#dataContainer').append(folderElement);
@@ -424,6 +418,7 @@ function initVideos(){
$('#mp4-title').text($(this).find(".vid-row-title").text());
$('#mp4-title-folder').text($(folder).data('folder'));
+ $('#folder-thumbnail').attr('src', `${stateThumbnailDir}${stateFolder.id}.jpg`);
addToHistory(id);
})
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php
index 08f1ff2a..ce42bf47 100644
--- a/resources/views/home.blade.php
+++ b/resources/views/home.blade.php
@@ -1,32 +1,17 @@
<x-app-layout>
<script src="{{ URL::asset('js/main.js') }}"></script>
<script>
- var stateVideoDirectory = <?php echo json_encode($dir ?? 'anime') ?>;
- var stateFolderName = <?php echo json_encode($folder_name ?? 'ODDTAXI') ?>;
+ var stateDirectory = <?php echo json_encode($dir ?? array('id'=>7,'name'=>'anime')) ?>;
+ var stateFolder = <?php echo json_encode($folder ?? array('id'=>7,'name'=>'ODDTAXI')) ?>;
+ var stateThumbnailDir = "{{ URL::asset('storage/thumbnails/folders') }}/"
</script>
@auth
<script>var user = true;</script>
@else
<script>var user = false;</script>
@endauth
- <div class=" hidden p-6 max-w-sm mx-auto bg-white rounded-xl shadow-lg flex items-center space-x-4">
- <div class="shrink-0">
- <img class="h-12 w-12" src="storage/avatars/12345.jpg" alt="ChitChat Logo">
- </div>
- <div>
- <div class="text-xl font-medium text-black">ChitChat</div>
- <p class="text-slate-500">You have a new message!</p>
- </div>
- </div>
- <button type="button" class="hidden flex justify-center items-center select-none bg-red-500 border-2 text-white text-xl font-bold p-2 m-2 rounded-full shadow h-20 w-20 focus:outline-none focus:shadow-outline">
- <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x">
- <line x1="18" y1="6" x2="6" y2="18"></line>
- <line x1="6" y1="6" x2="18" y2="18"></line>
- </svg>
- </button>
-
- <main class="p-6 flex gap-6 flex-row-reverse flex-wrap-reverse lg:flex-nowrap">
- <section id="list-card" class="invisible dark:bg-neutral-900 shadow-xl p-3 pb-6 rounded-2xl light-mode w-full lg:w-72 shrink-0 space-y-2">
+ <main class="p-6 flex gap-6 flex-row-reverse flex-wrap-reverse lg:flex-nowrap snap-y">
+ <section id="list-card" class="invisible dark:bg-neutral-900 shadow-xl p-3 pb-6 rounded-2xl light-mode w-full lg:w-72 shrink-0 space-y-2 scroll-mt-6">
<div class="flex p-1 text-ri">
<h1 id="sidebar-title" class="text-2xl w-full">Folders</h1>
</div>
@@ -69,49 +54,50 @@
</section>
<section id="content-card" class=" dark:bg-neutral-900 shadow-xl p-6 pt-3 rounded-2xl light-mode w-full">
<nav id="navbar">
- <div class="flex flex-row-reverse p-1 ">
- <span class="flex max-w-sm mx-auto items-center space-x-2 shrink-0">
- <section id="user_options" class="dropdown group inline-block relative" aria-expanded="true" aria-haspopup="true" data-dropdown-toggle="user_dropdown">
- <div class="hidden absolute top-12 origin-top-right left-7 w-56 z-10 divide-y divide-gray-200 rounded-md shadow-lg ring-1 bg-white ring-black ring-opacity-5 focus:outline-none" id="user_dropdown" aria-orientation="vertical" aria-labelledby="user_options">
+ <div class="flex p-1 gap-y-3 flex-wrap justify-between">
+ <h1 id="mp4-title-folder" class="text-2xl"></h1>
+ <span class="flex flex-wrap sm:flex-nowrap sm:max-w-sm items-center gap-2 sm:shrink-0">
+ <section id="user_options" class="group inline-block relative" data-dropdown-toggle="user_dropdown" aria-haspopup="true">
+ <button id="user_header" class="flex space-x-2 text-2xl text-slate-900 dark:text-white hover:text-orange-600 dark:hover:text-orange-600 items-center justify-center" >
@auth
+ <span id="user_name">{{ Auth::user()->name }}</span>
+ <img src="{{ URL::asset('storage/avatars/12345.jpg')}}" class="h-7 w-7 rounded-full sm:mx-0 sm:shrink-0 ring-2 ring-orange-600/60 shadow-lg object-cover">
- <div class="divide-y divide-gray-300" role="menu" id="user-menu-auth">
- <section class="px-4 py-3">
- <p class="text-sm leading-5 text-orange-500">Logged in as</p>
- <p class="text-sm font-medium leading-5 text-gray-900 truncate">{{ Auth::user()->email }}</p>
- </section>
- <section class="py-1">
- <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Account settings</button>
- <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Collections</button>
- <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Dashboard</button>
- <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Full History</button>
- <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem"><a href="/jobs/indexFiles" class="w-full h-full">Index Files</a></button>
- <span role="menuitem" tabindex="-1" class="flex justify-between w-full px-4 py-2 text-sm leading-5 text-left text-gray-700 cursor-not-allowed opacity-50" aria-disabled="true">New feature (soon)</span>
- </section>
- <section class="py-1">
- <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="logout();" role="menuitem">Log out</button>
- </section>
- </div>
@else
- <div role="menu" id="user-menu-unauth" class="text-gray-700">
- <section class="">
- <button class="rounded-t-md hover:bg-neutral-100 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="showLogin();" role="menuitem">Log in</button>
- <button class="rounded-b-md hover:bg-neutral-100 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="showSignup();" role="menuitem">Sign up</button>
- </section>
- </div>
+ <span id="user_name_unauth" class="w-[10vw] text-right">Guest</span>
+ <img src="{{ URL::asset('storage/avatars/12345.jpg')}}" class="h-7 w-7 rounded-full sm:mx-0 sm:shrink-0 ring-2 ring-orange-600/60 shadow-lg object-cover">
@endauth
- </div>
- <button id="user_header" class="flex space-x-2 text-2xl text-slate-900 dark:text-white hover:text-orange-600 dark:hover:text-orange-600 items-center justify-center">
+ </button>
+ <div role="menu" id="user_dropdown" aria-orientation="vertical" aria-labelledby="user_options" class="hidden absolute left-0 z-30 mt-4 w-56 origin-top-right divide-y divide-gray-300 rounded-md shadow-lg ring-1 bg-white ring-black ring-opacity-5 focus:outline-none text-gray-700">
+
@auth
- <span id="user_name">{{ Auth::user()->name }}</span>
- <img src="storage/avatars/12345.jpg" class="h-7 w-7 rounded-full sm:mx-0 sm:shrink-0 ring-2 ring-orange-600/60 shadow-lg">
-
+ <!-- <div class="divide-y divide-gray-300" role="menu" id="user-menu-auth"> -->
+ <section class="flex flex-wrap gap-1 px-4 py-3">
+ <p class="text-sm leading-5 text-orange-500">Logged in as: </p>
+ <p class="text-sm font-medium leading-5 text-gray-900 truncate">{{ Auth::user()->email }}</p>
+ </section>
+ <section class="py-1">
+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Account settings</button>
+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Collections</button>
+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Dashboard</button>
+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Full History</button>
+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem"><a href="/jobs/indexFiles" class="w-full h-full">Index Files</a></button>
+ <span role="menuitem" tabindex="-1" class="flex justify-between w-full px-4 py-2 text-sm leading-5 text-left text-gray-700 cursor-not-allowed opacity-50" aria-disabled="true">New feature (soon)</span>
+ </section>
+ <section class="py-1">
+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="logout();" role="menuitem">Log out</button>
+ </section>
+ <!-- </div> -->
@else
- <span id="user_name_unauth" class="w-[10vw] text-right">Guest</span>
- <img src="storage/avatars/12345.jpg" class="h-7 w-7 rounded-full sm:mx-0 sm:shrink-0 ring-2 ring-orange-600/60 shadow-lg">
+ <!-- <div role="menu" id="user-menu-unauth" class="text-gray-700"> -->
+ <section class="">
+ <button class="rounded-t-md hover:bg-neutral-100 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="showLogin();" role="menuitem">Log in</button>
+ <button class="rounded-b-md hover:bg-neutral-100 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="showSignup();" role="menuitem">Sign up</button>
+ </section>
+ <!-- </div> -->
@endauth
-
- </button>
+ </div>
+
</section>
@@ -143,28 +129,27 @@
</label>
</div>
</span>
- <h1 id="mp4-title-folder" class="text-2xl w-full"></h1>
</div>
<hr class="mt-2 mb-3">
</nav>
<section id="content-video">
<div id="video-container">
- <video id="vid-source" width="100%" src="" type="video/mp4" controls class="focus:outline-none">
+ <video id="vid-source" width="100%" src="" type="video/mp4" controls class="focus:outline-none aspect-video">
</video>
<hr class="mt-4 mb-3">
- <div class="p-6 my-4 w-full mx-auto dark:bg-neutral-800 bg-white rounded-xl shadow-lg flex justify-between space-x-4">
+ <div class="p-6 my-4 w-full mx-auto dark:bg-neutral-800 bg-white rounded-xl shadow-lg flex justify-center sm:justify-between gap-4 flex-wrap sm:flex-nowrap">
<div class="flex items-center space-x-4">
<div class="shrink-0">
- <img class="h-12 w-12" src="storage/avatars/12345.jpg" alt="ChitChat Logo">
+ <img id="folder-thumbnail" class="h-16 lg:h-24 object-contain rounded-md" src="{{ URL::asset('storage/thumbnails/folders/5.jpg')}}" onerror="this.onerror=null;this.src=`{{ URL::asset('storage/thumbnails/folders/5.jpg')}}`;" alt="Folder Cover Art">
</div>
- <div>
- <div id="mp4-title" class="text-xl font-medium">ChitChat</div>
+ <div class="h-full">
+ <div id="mp4-title" class="text-xl font-medium"></div>
<p class="dark:text-slate-400 text-slate-500 line-clamp-2">This episode is about a walrus going for a juice box run at 3am</p>
</div>
</div>
- <div id="mp4-controls" class="my-auto container flex w-auto" role="group">
+ <!-- <div id="mp4-controls" class="my-auto container flex w-auto" role="group">
<button type="button" class="bg-gray-800 text-white rounded-l-md border-r border-gray-100 py-2 hover:bg-red-700 hover:text-white px-3 shadow-xl">
<div class="flex flex-row align-middle">
<svg class="w-5 mr-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
@@ -181,7 +166,7 @@
</svg>
</div>
</button>
- </div>
+ </div> -->
</div>
</div>