Skip to content

A self-hosted media server and file management system

feat: basic user profile

aminnausinbd3b425a06b1
diff --git a/app/Http/Controllers/Api/V1/ProfileController.php b/app/Http/Controllers/Api/V1/ProfileController.php
index e9619a39..4289373b 100644
--- a/app/Http/Controllers/Api/V1/ProfileController.php
+++ b/app/Http/Controllers/Api/V1/ProfileController.php
@@ -3,7 +3,39 @@
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
+use App\Http\Resources\ProfileResource;
+use App\Models\User;
+use App\Traits\HttpResponses;
+use Illuminate\Database\Eloquent\ModelNotFoundException;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
class ProfileController extends Controller {
- //
+ use HttpResponses;
+
+ /**
+ * Display the specified resource.
+ * Get user by id
+ *
+ * @return \Illuminate\Http\Response
+ */
+ public function show(int $user_id) {
+ try {
+ return new ProfileResource(User::findOrFail($user_id ?? Auth::id()));
+ } catch (ModelNotFoundException $th) {
+ return $this->error(null, 'User not found', 404);
+ } catch (\Throwable $th) {
+ return $this->error(null, 'Unable to get user. Error: ' . $th->getMessage(), 500);
+ }
+ }
+
+ public function findUser(Request $request) {
+ try {
+ return new ProfileResource(User::where('name', $request->username ?? Auth::user()->name)->firstOrFail());
+ } catch (ModelNotFoundException $th) {
+ return $this->error(null, 'User not found', 404);
+ } catch (\Throwable $th) {
+ return $this->error(null, 'Unable to get user. Error: ' . $th->getMessage(), 500);
+ }
+ }
}
diff --git a/app/Http/Requests/UserStoreRequest.php b/app/Http/Requests/UserStoreRequest.php
index 492ae336..f6e491c4 100644
--- a/app/Http/Requests/UserStoreRequest.php
+++ b/app/Http/Requests/UserStoreRequest.php
@@ -20,7 +20,7 @@ class UserStoreRequest extends FormRequest {
*/
public function rules(): array {
return [
- 'name' => ['required', 'string', 'max:255', 'unique:users'],
+ 'name' => ['required', 'string', 'max:255', 'unique:users', 'regex:/\D/'],
'email' => ['required', 'string', 'max:255', 'unique:users'],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
];
diff --git a/app/Http/Resources/ProfileResource.php b/app/Http/Resources/ProfileResource.php
new file mode 100644
index 00000000..dc9305d3
--- /dev/null
+++ b/app/Http/Resources/ProfileResource.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Request;
+use Illuminate\Http\Resources\Json\JsonResource;
+
+class ProfileResource extends JsonResource {
+ /**
+ * Transform the resource into an array.
+ *
+ * @return array<string, mixed>
+ */
+ public function toArray(Request $request): array {
+ return [
+ 'id' => $this->id,
+ 'name' => $this->name,
+ 'created_at' => $this->created_at,
+ 'last_active' => $this->last_active,
+ 'avatar' => null,
+ ];
+ }
+}
diff --git a/resources/js/components/pinesUI/DropdownMenu.vue b/resources/js/components/pinesUI/DropdownMenu.vue
index 6f6678f4..625b36c0 100755
--- a/resources/js/components/pinesUI/DropdownMenu.vue
+++ b/resources/js/components/pinesUI/DropdownMenu.vue
@@ -48,7 +48,7 @@ const manualPosition = ref(0);
const dropDownItemsAuth = computed<DropdownMenuItem[][]>(() => {
return [
[
- { ...defaults, name: 'profile', url: '/profile', text: 'Profile', icon: LucideUser, disabled: true },
+ { ...defaults, name: 'account', url: '/account', text: 'Account', icon: LucideUser, disabled: false },
{ ...defaults, name: 'settings', url: '/settings', text: 'Settings', icon: LucideSettings },
{ ...defaults, name: 'home', url: '/', text: 'Home', icon: LucideTvMinimalPlay },
],
@@ -104,8 +104,9 @@ const dropDownItemsAuth = computed<DropdownMenuItem[][]>(() => {
name: 'verify folders',
text: 'Verify Folders',
title: 'Verify folder metadata (titles, video counts, folder size, localised thumbnails)',
- hidden: true,
- icon: LucideFolderCheck,
+ hidden: false,
+ icon: LucideFolderSync,
+ shortcut: '30s',
action: () => {
handleStartTask('verifyFolders');
},
diff --git a/resources/js/components/profile/ProfileHeader.vue b/resources/js/components/profile/ProfileHeader.vue
new file mode 100644
index 00000000..bbcc733b
--- /dev/null
+++ b/resources/js/components/profile/ProfileHeader.vue
@@ -0,0 +1,42 @@
+<script setup lang="ts">
+import type { ProfileResource } from '@/types/resources';
+
+import { getProfileByName } from '@/service/ProfileService';
+import { onMounted, ref } from 'vue';
+import { toTimeSpan } from '@/service/util';
+import { useRoute } from 'vue-router';
+
+const router = useRoute();
+const userProfile = ref<ProfileResource>();
+
+onMounted(async () => {
+ const userIdentifier = router.params.username.toString();
+
+ const { data } = await getProfileByName(userIdentifier);
+
+ userProfile.value = data;
+});
+</script>
+<template>
+ <section
+ id="banner"
+ style="background-image: url('https://s4.anilist.co/file/anilistcdn/user/banner/b6792701-mBLPRvzr3xPL.jpg')"
+ class="bg-cover flex rounded-md h-52 lg:h-64 text-white"
+ >
+ <section id="user-header" class="mt-auto p-3 flex gap-4 bg-gradient-to-b from-transparent to-neutral-950/40 w-full items-end flex-wrap text-center">
+ <img
+ :src="
+ userProfile?.name[0] === 'a'
+ ? '/storage/avatars/default.jpg'
+ : (userProfile?.avatar ?? `https://ui-avatars.com/api/?name=${userProfile?.name[0]}&amp;color=7F9CF5&amp;background=random`)
+ "
+ class="h-32 w-32 min-w-24 rounded-full ring-2 ring-violet-700/70 object-cover aspect-square mx-auto"
+ alt="profile"
+ />
+ <section class="text-centre flex flex-wrap flex-1 justify-center items-end sm:pb-2 xl:pb-4">
+ <h2 class="text-2xl capitalize w-full sm:text-left sm:flex-1">{{ userProfile?.name }}</h2>
+ <h3 class="text-sm">Member since: {{ toTimeSpan(userProfile?.created_at || '', '') }}</h3>
+ </section>
+ </section>
+ </section>
+</template>
diff --git a/resources/js/service/metadataService.ts b/resources/js/service/metadataService.ts
index 8c83c57e..c3ba4b8b 100644
--- a/resources/js/service/metadataService.ts
+++ b/resources/js/service/metadataService.ts
@@ -1,5 +1,3 @@
-// services/lyricsService.ts
-
import { API } from '@/service/api';
export async function fetchSyncedLyrics(metadataId: number, query?: string) {
diff --git a/resources/js/service/profileService.ts b/resources/js/service/profileService.ts
new file mode 100644
index 00000000..1035fea9
--- /dev/null
+++ b/resources/js/service/profileService.ts
@@ -0,0 +1,14 @@
+import { API } from '@/service/api';
+
+export async function getProfileByName(username: string) {
+ const parsedId = parseInt(username);
+ if (!isNaN(parsedId) && parsedId.toString() === username) return getProfileById(parsedId);
+
+ const { data } = await API.get(`/profiles/search/${username}`);
+ return data ?? null;
+}
+
+export async function getProfileById(id: number) {
+ const { data } = await API.get(`/profiles/${id}`);
+ return data ?? null;
+}
diff --git a/resources/js/types/resources.ts b/resources/js/types/resources.ts
index e1b90c47..976aef8e 100644
--- a/resources/js/types/resources.ts
+++ b/resources/js/types/resources.ts
@@ -10,6 +10,14 @@ export interface UserResource {
avatar?: string;
}
+export interface ProfileResource {
+ id: number;
+ name: string;
+ last_active: string;
+ created_at: string;
+ avatar?: string;
+}
+
export interface CategoryResource {
id: number;
name: string;
diff --git a/resources/js/views/ProfileView.vue b/resources/js/views/ProfileView.vue
index c6148ca9..e8bdbd91 100755
--- a/resources/js/views/ProfileView.vue
+++ b/resources/js/views/ProfileView.vue
@@ -1,17 +1,16 @@
-<script setup>
+<script setup lang="ts">
import { useAppStore } from '../stores/AppStore';
import { storeToRefs } from 'pinia';
import { onMounted } from 'vue';
-import { toast } from '@/service/toaster/toastService';
-import LayoutBase from '../layouts/LayoutBase.vue';
-import ButtonText from '../components/inputs/ButtonText.vue';
+import ProfileHeader from '@/components/profile/ProfileHeader.vue';
+import ButtonText from '@/components/inputs/ButtonText.vue';
+import LayoutBase from '@/layouts/LayoutBase.vue';
-const appStore = useAppStore();
-const { pageTitle, selectedSideBar } = storeToRefs(appStore);
+const { pageTitle, selectedSideBar } = storeToRefs(useAppStore());
onMounted(() => {
- pageTitle.value = 'Tests';
+ pageTitle.value = 'User Profile';
selectedSideBar.value = '';
});
</script>
@@ -19,76 +18,19 @@ onMounted(() => {
<template>
<LayoutBase>
<template #content>
- <section class="min-h-[80vh]">
- <div class="relative w-auto h-auto">
- <div class="relative space-y-5">
- <div class="relative">
- <div class="relative flex flex-col px-10 space-y-2 sm:space-x-5 sm:space-y-0 sm:flex-row sm:px-0">
- <ButtonText
- @click="
- toast.add('Default Toast Notification', {
- type: 'danger',
- description: `The taxi driver Odokawa lives a very mundane life. He has no family, doesn't really hang out with others, and he's an oddball who is narrow-minded and doesn't talk much. The only people he can call his friends are his doctor, Gouriki and his classmate from high school, Kakihana.
-
-All of his patrons seem to be slightly odd themselves. The college student who wants the world to notice him online, Kabasawa. A nurse with secrets named Shirakawa. A comedy duo that just can't catch a break named the Homosapiens. A local hoodlum named Dobu. An idol group that's just starting out named Mystery Kiss... All these mundane conversations somehow eventually lead to a girl who's gone missing.
-`,
- life: 3000,
- position: 'top-right',
- })
- "
- >
- <template #text> Test Notification </template>
- </ButtonText>
- <ButtonText
- @click="
- toast.add('Default Toast Notification', {
- type: 'success',
- description: 'This is an example toast notification',
- life: 3000,
- position: 'bottom-left',
- })
- "
- >
- <template #text> Test </template>
- </ButtonText>
- <ButtonText
- @click="
- toast.add('Default Toast Notification', {
- type: 'warning',
- description: 'This is an example toast notification',
- life: 3000,
- })
- "
- >
- <template #text> Test </template>
- </ButtonText>
- <ButtonText
- @click="
- toast.add('Default Toast Notification', {
- type: 'info',
- life: 3000,
- })
- "
- >
- <template #text> Test </template>
- </ButtonText>
- <ButtonText @click="toast('Event has been created')">
- <template #text> Test </template>
- </ButtonText>
- <ButtonText
- @click="
- toast.error(`The taxi driver Odokawa lives a very mundane life. He has no family, doesn't really hang out with others, and he's an oddball who is narrow-minded and doesn't talk much. The only people he can call his friends are his doctor, Gouriki and his classmate from high school, Kakihana.
-
-All of his patrons seem to be slightly odd themselves. The college student who wants the world to notice him online, Kabasawa. A nurse with secrets named Shirakawa. A comedy duo that just can't catch a break named the Homosapiens. A local hoodlum named Dobu. An idol group that's just starting out named Mystery Kiss... All these mundane conversations somehow eventually lead to a girl who's gone missing.
-`)
- "
- >
- <template #text> Test </template>
- </ButtonText>
- </div>
- </div>
+ <section id="content-profile" class="flex flex-col gap-3">
+ <ProfileHeader />
+ <section id="user-info" class="w-full flex justify-between">
+ <div class="flex flex-col gap-1">
+ <!-- <p>Views: 2343</p>
+ <p>Tags: 20</p>
+ <p>Edits: 20</p> -->
+ </div>
+ <div class="h-6 flex gap-2 text-sm">
+ <ButtonText text="Add Friend" />
+ <ButtonText text="Block" />
</div>
- </div>
+ </section>
</section>
</template>
</LayoutBase>
diff --git a/routes/api.php b/routes/api.php
index 45348de5..1e787190 100755
--- a/routes/api.php
+++ b/routes/api.php
@@ -34,9 +34,10 @@ Route::group(['middleware' => ['auth:sanctum']], function () {
Route::get('/active-sessions', [UserController::class, 'sessionCount']);
Route::get('/user-view-count/{metadata}', [RecordController::class, 'userViewCount']);
+ Route::get('/profiles/search/{username?}', [ProfileController::class, 'findUser']);
Route::resource('/records', RecordController::class)->only(['index', 'store', 'destroy']);
- Route::resource('/profile', ProfileController::class)->only(['show', 'store', 'update']);
+ Route::resource('/profiles', ProfileController::class)->only(['show', 'store', 'update']);
Route::resource('/series', SeriesController::class)->only(['index', 'store', 'update']);
Route::resource('/metadata', MetadataController::class)->only(['show', 'store', 'update']);
Route::resource('/tags', TagController::class)->only(['index', 'store']);