koel/resources/assets/js/config/routes.ts

146 lines
2.7 KiB
TypeScript
Raw Normal View History

import type { Route } from '@/router'
import Router from '@/router'
import { userStore } from '@/stores'
import { cache, playlistCollaborationService } from '@/services'
2024-01-04 11:35:36 +00:00
import { useUpload } from '@/composables'
import { logger } from '@/utils'
2024-01-18 11:13:05 +00:00
const UUID_REGEX = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
export const routes: Route[] = [
{
path: '/home',
screen: 'Home',
},
{
path: '/404',
screen: '404',
},
{
path: '/queue',
screen: 'Queue',
},
{
path: '/songs',
screen: 'Songs',
},
{
path: '/albums',
screen: 'Albums',
},
{
path: '/artists',
screen: 'Artists',
},
{
path: '/favorites',
screen: 'Favorites',
},
{
path: '/recently-played',
screen: 'RecentlyPlayed',
},
{
path: '/search',
screen: 'Search.Excerpt',
},
{
path: '/search/songs',
screen: 'Search.Songs',
},
{
path: '/upload',
screen: 'Upload',
onResolve: () => useUpload().allowsUpload.value,
},
{
path: '/settings',
screen: 'Settings',
onResolve: () => userStore.current?.is_admin,
},
{
path: '/users',
screen: 'Users',
onResolve: () => userStore.current?.is_admin,
},
{
path: '/youtube',
screen: 'YouTube',
},
{
path: '/profile',
screen: 'Profile',
},
{
path: 'visualizer',
screen: 'Visualizer',
},
{
path: '/album/(?<id>\\d+)',
screen: 'Album',
},
{
path: '/artist/(?<id>\\d+)',
screen: 'Artist',
},
{
2024-01-18 11:13:05 +00:00
path: `/playlist/(?<id>${UUID_REGEX})`,
screen: 'Playlist',
},
2024-01-18 11:13:05 +00:00
{
path: `/playlist/collaborate/(?<id>${UUID_REGEX})`,
screen: 'Blank',
onResolve: async params => {
try {
const playlist = await playlistCollaborationService.acceptInvite(params.id)
Router.go(`/playlist/${playlist.id}`, true)
return true
} catch (error: unknown) {
logger.error(error)
2024-01-18 11:13:05 +00:00
return false
}
},
2024-01-18 11:13:05 +00:00
},
2022-10-21 20:06:43 +00:00
{
path: '/genres',
screen: 'Genres',
2022-10-21 20:06:43 +00:00
},
{
path: '/genres/(?<name>\.+)',
screen: 'Genre',
2022-10-21 20:06:43 +00:00
},
2024-05-19 05:49:42 +00:00
{
path: '/podcasts',
screen: 'Podcasts',
},
{
path: `/podcasts/(?<id>${UUID_REGEX})`,
screen: 'Podcast',
},
{
path: '/episodes/(?<id>\.+)',
screen: 'Episode',
},
2022-11-06 17:09:06 +00:00
{
path: '/visualizer',
screen: 'Visualizer',
2022-11-06 17:09:06 +00:00
},
{
2024-01-18 11:13:05 +00:00
path: `/song/(?<id>${UUID_REGEX})`,
screen: 'Queue',
redirect: () => 'queue',
onResolve: params => {
cache.set('song-to-queue', params.id)
return true
},
2023-08-20 22:35:58 +00:00
},
{
2024-01-18 11:13:05 +00:00
path: `/invitation/accept/(?<token>${UUID_REGEX})`,
screen: 'Invitation.Accept',
2024-02-25 19:32:53 +00:00
},
{
path: `/reset-password/(?<payload>[a-zA-Z0-9\\+/=]+)`,
screen: 'Password.Reset',
},
]