diff --git a/composables/useContent.ts b/composables/useContent.ts deleted file mode 100644 index b9732ce..0000000 --- a/composables/useContent.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Content } from '~/shared/content.util'; -import type { ExploreContent, ContentComposable, TreeItem } from '~/types/content'; - -const useContentState = () => useState('content', () => []); - -export function useContent(): ContentComposable { - const contentState = useContentState(); - - return { - content: contentState, - tree: computed(() => { - const arr: TreeItem[] = []; - for(const element of contentState.value) - { - addChild(arr, element); - } - return arr; - }), - fetch, - get, - } -} - -async function fetch(force: boolean = false) { - const content = useContentState(); - if(content.value.length === 0 || force) - content.value = await useRequestFetch()('/api/file/overview'); -} - -async function get(path: string, force: boolean = false): Promise { - const content = useContentState() - const value = content.value; - const item = value.find(e => e.path === path); - - if(item && !item.content) - { - item.content = await useRequestFetch()(`/api/file/content/${encodeURIComponent(path)}`); - } - - content.value = value; - - return item; -} - -function addChild(arr: TreeItem[], e: ExploreContent): void { - const parent = arr.find(f => e.path.startsWith(f.path)); - - if(parent) - { - if(!parent.children) - parent.children = []; - - addChild(parent.children, e); - } - else - { - arr.push({ ...e }); - arr.sort((a, b) => { - if(a.order !== b.order) - return a.order - b.order; - return a.title.localeCompare(b.title); - }); - } -} \ No newline at end of file diff --git a/db.sqlite b/db.sqlite index 4071325..a82d537 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/db.sqlite-shm b/db.sqlite-shm index 74c3d56..fe9ac28 100644 Binary files a/db.sqlite-shm and b/db.sqlite-shm differ diff --git a/db.sqlite-wal b/db.sqlite-wal index 268e880..e69de29 100644 Binary files a/db.sqlite-wal and b/db.sqlite-wal differ diff --git a/layouts/default.vue b/layouts/default.vue index aaba3e7..044a92f 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -60,7 +60,6 @@ import { link } from '#shared/components.util'; const open = ref(false); const { loggedIn, user } = useUserSession(); -const { fetch } = useContent(); await fetch(false); @@ -82,7 +81,6 @@ const tree = new TreeDOM((item, depth) => { ], { class: ['flex flex-1 items-center hover:border-accent-blue hover:text-accent-purple max-w-full'], attributes: { 'data-private': item.private }, active: 'text-accent-blue' }, item.path ? { name: 'explore-path', params: { path: item.path } } : undefined )]); }, (item) => item.navigable); (path.value?.split('/').map((e, i, a) => a.slice(0, i).join('/')) ?? []).forEach(e => tree.toggle(tree.tree.search('path', e)[0], true)); -const treeParent = useTemplateRef('treeParent'); const unmount = useRouter().afterEach((to, from, failure) => { if(failure) @@ -95,6 +93,7 @@ watch(route, () => { open.value = false; }); +const treeParent = useTemplateRef('treeParent'); onMounted(() => { if(treeParent.value) treeParent.value.appendChild(tree.container); diff --git a/middleware/auth.global.ts b/middleware/auth.global.ts index 63390b5..023c5fb 100644 --- a/middleware/auth.global.ts +++ b/middleware/auth.global.ts @@ -2,13 +2,9 @@ import { hasPermissions } from "#shared/auth.util"; export default defineNuxtRouteMiddleware(async (to, from) => { const { loggedIn, fetch, user } = useUserSession(); - const { fetch: fetchContent } = useContent(); const meta = to.meta; - if(await fetch()) - { - fetchContent(true); - } + await fetch() if(!!meta.guestsGoesTo && !loggedIn.value) { @@ -34,7 +30,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => { } else if(!hasPermissions(user.value.permissions, meta.rights)) { - return abortNavigation({ statusCode: 401, message: 'Unauthorized', }); + return abortNavigation({ statusCode: 401, message: 'Unauthorized', }); } } diff --git a/pages/character/[id]/edit.client.vue b/pages/character/[id]/edit.client.vue index 3198651..a7073c5 100644 --- a/pages/character/[id]/edit.client.vue +++ b/pages/character/[id]/edit.client.vue @@ -1,6 +1,6 @@