Skip to content

A self-hosted media server and file management system

api support for folders and videos

aminnausin1df46f609503
diff --git a/app/Http/Controllers/Api/V1/FolderController.php b/app/Http/Controllers/Api/V1/FolderController.php
index 981bbae6..54d22ee3 100644
--- a/app/Http/Controllers/Api/V1/FolderController.php
+++ b/app/Http/Controllers/Api/V1/FolderController.php
@@ -22,14 +22,23 @@ class FolderController extends Controller
try {
return $this->success(
- Folder::where('category_id', $request->category_id)->first()
- //FolderResource::collection(
- // Folder::withCount(['videos'])->having('category_id', '=', $request->category_id)->get()
- //Folder::where('category_id', $request->category_id)->withCount(['videos'])->get()
- //)
+ FolderResource::collection(
+ Folder::where('category_id', $request->category_id)->withCount(['videos'])->get()
+ )
);
} catch (\Throwable $th) {
return $this->error(null, 'Unable to get folders. Error: ' . $th->getMessage(), 500);
}
}
+
+ /**
+ * Display the specified resource.
+ *
+ * @param int $video_id
+ * @return \Illuminate\Http\Response
+ */
+ public function show(Folder $folder)
+ {
+ return new FolderResource(Folder::withCount(['videos'])->find($folder->id));
+ }
}
diff --git a/app/Http/Controllers/Api/V1/VideoController.php b/app/Http/Controllers/Api/V1/VideoController.php
index 76d3259a..09e48633 100644
--- a/app/Http/Controllers/Api/V1/VideoController.php
+++ b/app/Http/Controllers/Api/V1/VideoController.php
@@ -18,29 +18,27 @@ class VideoController extends Controller
/**
* Display a listing of the resource.
*/
- public function update(FolderCollectionRequest $request)
+ public function getFrom(VideoCollectionRequest $request)
{
try {
- return $this->success(
- VideoResource::collection(
- Video::where('folder_id', $request->folder_id)->get()
- ),$request->folder_id
- );
+
+ $result = VideoResource::collection( Video::where('folder_id', $request->folder_id)->get() );
+
+ return $this->success($result);
+
} catch (\Throwable $th) {
return $this->error(null, 'Unable to get videos. Error: ' . $th->getMessage(), 500);
}
}
- // /**
- // * Display the specified resource.
- // *
- // * @param int $video_id
- // * @return \Illuminate\Http\Response
- // */
- // public function getOne(Video $video)
- // {
- // return RecordResource::collection(
- // Record::where('user_id', Auth::user()->id)->where('video_id', $video->id)->get()
- // );
- // }
+ /**
+ * Display the specified resource.
+ *
+ * @param int $video_id
+ * @return \Illuminate\Http\Response
+ */
+ public function show(Video $video)
+ {
+ return new VideoResource($video);
+ }
}
diff --git a/public/js/main.js b/public/js/main.js
index 236af66b..d872671d 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -177,11 +177,11 @@ function parseHistory(data, count = 10, destination = '#list-content-history') {
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">
<section class="flex justify-between items-baseline w-full">
- <h2 class="text-xl text-left">${videoName}</h2>
+ <h2 class="text-xl text-left truncate">${videoName}</h2>
</section>
<aside class="flex justify-between items-center w-full pt-1">
- <h3 class="text-lg text-left text-neutral-500">${folderName}</h2>
- <h3 class="text-lg text-right text-neutral-500 text-nowrap line-clamp-1">${timeSpan}</h3>
+ <h3 class="text-lg text-left text-neutral-500 truncate">${folderName}</h2>
+ <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">
@@ -241,7 +241,7 @@ async function parseFolders(data){
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">${folderName}</h2>
+ <h2 class="text-xl truncate">${folderName}</h2>
</section>
<aside class="flex justify-between items-center w-full pt-1">
<h3 class="text-lg text-left text-neutral-500">${folderCount} Episodes</h2>
@@ -309,8 +309,8 @@ async function loadVideosAndParse(data){
let filePrefix = '../';
return `
<tr class="vid-row" data-id="${id}" data-path="${filePrefix}${fileName}">
- <td class="vid-row-title">${title}</td>
- <td class="vid-row-date">${date}</td>
+ <td class="vid-row-title truncate">${title}</td>
+ <td class="vid-row-date truncate">${date}</td>
</tr>
`
}
diff --git a/routes/api.php b/routes/api.php
index 4aeb926c..a537cdae 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -14,10 +14,13 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
// public
-Route::post('/login', [AuthController::class, 'login']);
-Route::post('/register', [AuthController::class, 'register']);
+Route::resource('/videos', VideoController::class);
+Route::resource('/folders', FolderController::class);
+
Route::post('/videos', [VideoController::class, 'getFrom']);
Route::post('/folders', [FolderController::class, 'getFrom']);
+Route::post('/login', [AuthController::class, 'login']);
+Route::post('/register', [AuthController::class, 'register']);
// protected