162 lines
6.1 KiB
TypeScript
162 lines
6.1 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
declare module 'vue-router' {
|
|
interface RouteMeta {
|
|
public? : boolean
|
|
adminOnly? : boolean
|
|
}
|
|
}
|
|
import { useAuthStore } from '@/stores/auth'
|
|
import AppLayout from '@/layouts/AppLayout.vue'
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes: [
|
|
// ─── Pages publiques hors layout ─────────────────────────
|
|
{
|
|
path: '/auth',
|
|
component: () => import('@/views/AuthView.vue'),
|
|
meta: { public: true },
|
|
},
|
|
{
|
|
path: '/invite/:code',
|
|
component: () => import('@/views/InviteView.vue'),
|
|
meta: { public: true },
|
|
},
|
|
{
|
|
path: '/setup',
|
|
name: 'setup',
|
|
component: () => import('@/views/SetupView.vue'),
|
|
meta: { adminOnly: true },
|
|
},
|
|
|
|
// ─── App principale avec layout sidebar ──────────────────
|
|
{
|
|
path: '/',
|
|
component: AppLayout,
|
|
children: [
|
|
{ path: '', redirect: '/dashboard' },
|
|
{ path: 'downloads', redirect: '/activity' },
|
|
|
|
// Accueil
|
|
{
|
|
path: 'dashboard',
|
|
name: 'dashboard',
|
|
component: () => import('@/views/DashboardView.vue'),
|
|
},
|
|
|
|
// Médiathèque
|
|
{
|
|
path: 'series',
|
|
name: 'series',
|
|
component: () => import('@/views/SeriesView.vue'),
|
|
},
|
|
{
|
|
path: 'series/:id',
|
|
name: 'serie-detail',
|
|
component: () => import('@/views/SerieView.vue'),
|
|
},
|
|
|
|
// Activité
|
|
{
|
|
path: 'activity',
|
|
name: 'activity',
|
|
component: () => import('@/views/DownloadsView.vue'),
|
|
},
|
|
|
|
// Paramètres
|
|
{
|
|
path: 'settings',
|
|
component: () => import('@/views/settings/SettingsLayout.vue'),
|
|
children: [
|
|
{ path: '', redirect: '/settings/profile' },
|
|
{
|
|
path: 'profile',
|
|
name: 'settings-profile',
|
|
component: () => import('@/views/settings/ProfileView.vue'),
|
|
},
|
|
{
|
|
path: 'download-client',
|
|
name: 'settings-download',
|
|
component: () => import('@/views/settings/DownloadClientView.vue'),
|
|
},
|
|
{
|
|
path: 'media-management',
|
|
name: 'settings-media',
|
|
component: () => import('@/views/settings/MediaManagementView.vue'),
|
|
},
|
|
{
|
|
path: 'import-management',
|
|
name: 'setting-import',
|
|
component: () => import('@/views/settings/ImportManagementView.vue'),
|
|
},
|
|
{
|
|
path: 'catalogue',
|
|
name: 'settings-catalogue',
|
|
component: () => import('@/views/settings/CatalogueView.vue'),
|
|
},
|
|
{
|
|
path: 'logs',
|
|
name: 'settings-logs',
|
|
component: () => import('@/views/settings/LogsView.vue'), // ← nouveau chemin
|
|
},
|
|
{
|
|
path: 'advanced',
|
|
name: 'settings-advanced',
|
|
component: () => import('@/views/settings/AdvancedView.vue'),
|
|
},
|
|
{
|
|
path: 'users',
|
|
name: 'settings-users',
|
|
component: () => import('@/views/settings/UsersView.vue'),
|
|
meta: { adminOnly: true },
|
|
},
|
|
{
|
|
path: 'jellyfin',
|
|
name: 'settings-jellyfin',
|
|
component: () => import('@/views/settings/JellyfinView.vue'),
|
|
meta: { adminOnly: true },
|
|
},
|
|
],
|
|
},
|
|
|
|
// Demandes
|
|
{
|
|
path: 'requests',
|
|
name: 'requests',
|
|
component: () => import('@/views/RequestsView.vue'),
|
|
},
|
|
],
|
|
},
|
|
],
|
|
|
|
scrollBehavior(to, from, savedPosition) {
|
|
if (savedPosition) return savedPosition
|
|
if (to.name === 'setup') return { top: 0 }
|
|
// Retour depuis le détail vers la liste — ne pas scroller en haut
|
|
if (to.name === 'series' && from.name === 'serie-detail') return false
|
|
return { el: '#main-scroll', top: 0 }
|
|
},
|
|
})
|
|
|
|
// ─── Guard auth ───────────────────────────────────────────────
|
|
router.beforeEach(async (to) => {
|
|
const auth = useAuthStore()
|
|
|
|
if (auth.loading) await auth.checkStatus()
|
|
|
|
// Redirige vers /auth si non connecté
|
|
if (!to.meta.public && !auth.loggedIn) return '/auth'
|
|
|
|
// Redirige vers l'accueil si déjà connecté et tente d'accéder à /auth
|
|
if (to.path === '/auth' && auth.loggedIn) return '/dashboard'
|
|
|
|
// Redirige les non-admins hors des pages admin
|
|
if (to.meta.adminOnly && !auth.isAdmin) return '/dashboard'
|
|
|
|
// Premier lancement : l'assistant de configuration est obligatoire
|
|
if (auth.loggedIn && auth.isAdmin && !auth.onboardingDone
|
|
&& !to.meta.public && to.name !== 'setup') return '/setup'
|
|
})
|
|
|
|
export default router |