> {
}
export async function getWarrenDirectory(
+ warrenId: string,
path: string
): Promise
{
- // eslint-disable-next-line prefer-const
- let [warrenId, rest] = splitOnce(path, '/');
-
- if (rest == null) {
- rest = '/';
- } else {
- rest = '/' + decodeURI(rest);
- }
-
const { data, error } = await useFetch<
ApiResponse<{ files: DirectoryEntry[] }>
>(getApiUrl(`warrens/files`), {
@@ -47,7 +39,7 @@ export async function getWarrenDirectory(
},
body: JSON.stringify({
warrenId,
- path: rest,
+ path,
}),
});
@@ -61,19 +53,15 @@ export async function getWarrenDirectory(
}
export async function createDirectory(
+ warrenId: string,
path: string,
directoryName: string
): Promise<{ success: boolean }> {
- // eslint-disable-next-line prefer-const
- let [warrenId, rest] = splitOnce(path, '/');
-
- if (rest == null) {
- rest = '/';
- } else {
- rest = '/' + decodeURI(rest) + '/';
+ if (!path.endsWith('/')) {
+ path += '/';
}
- rest += directoryName;
+ path += directoryName;
const { status } = await useFetch(getApiUrl(`warrens/files/directory`), {
method: 'POST',
@@ -82,7 +70,7 @@ export async function createDirectory(
},
body: JSON.stringify({
warrenId,
- path: rest,
+ path,
}),
});
@@ -105,20 +93,16 @@ export async function createDirectory(
}
export async function deleteWarrenDirectory(
+ warrenId: string,
path: string,
directoryName: string,
force: boolean
): Promise<{ success: boolean }> {
- // eslint-disable-next-line prefer-const
- let [warrenId, rest] = splitOnce(path, '/');
-
- if (rest == null) {
- rest = '/';
- } else {
- rest = '/' + decodeURI(rest) + '/';
+ if (!path.endsWith('/')) {
+ path += '/';
}
- rest += directoryName;
+ path += directoryName;
const { status } = await useFetch(getApiUrl(`warrens/files/directory`), {
method: 'DELETE',
@@ -127,7 +111,7 @@ export async function deleteWarrenDirectory(
},
body: JSON.stringify({
warrenId,
- path: rest,
+ path,
force,
}),
});
@@ -152,19 +136,15 @@ export async function deleteWarrenDirectory(
}
export async function deleteWarrenFile(
+ warrenId: string,
path: string,
fileName: string
): Promise<{ success: boolean }> {
- // eslint-disable-next-line prefer-const
- let [warrenId, rest] = splitOnce(path, '/');
-
- if (rest == null) {
- rest = '/';
- } else {
- rest = '/' + decodeURI(rest) + '/';
+ if (!path.endsWith('/')) {
+ path += '/';
}
- rest += fileName;
+ path += fileName;
const { status } = await useFetch(getApiUrl(`warrens/files/file`), {
method: 'DELETE',
@@ -173,7 +153,7 @@ export async function deleteWarrenFile(
},
body: JSON.stringify({
warrenId,
- path: rest,
+ path,
}),
});
@@ -197,19 +177,11 @@ export async function deleteWarrenFile(
}
export async function uploadToWarren(
+ warrenId: string,
path: string,
files: FileList,
onProgress: ((loaded: number, total: number) => void) | undefined
): Promise<{ success: boolean }> {
- // eslint-disable-next-line prefer-const
- let [warrenId, rest] = splitOnce(path, '/');
-
- if (rest == null) {
- rest = '/';
- } else {
- rest = '/' + decodeURI(rest);
- }
-
const xhr = new XMLHttpRequest();
xhr.open('POST', getApiUrl(`warrens/files/upload`));
xhr.upload.onprogress = (e) => {
@@ -232,7 +204,7 @@ export async function uploadToWarren(
const body = new FormData();
body.set('warrenId', warrenId);
- body.set('path', rest);
+ body.set('path', path);
for (const file of files) {
body.append('files', file);
}
@@ -260,20 +232,15 @@ export async function uploadToWarren(
}
export async function renameWarrenEntry(
+ warrenId: string,
path: string,
currentName: string,
newName: string
): Promise<{ success: boolean }> {
- // eslint-disable-next-line prefer-const
- let [warrenId, rest] = splitOnce(path, '/');
-
- if (rest == null) {
- rest = '/';
- } else {
- rest = '/' + decodeURI(rest) + '/';
+ if (!path.endsWith('/')) {
+ path += '/';
}
-
- rest += currentName;
+ path += currentName;
const { status } = await useFetch(getApiUrl(`warrens/files/rename`), {
method: 'PATCH',
@@ -282,7 +249,7 @@ export async function renameWarrenEntry(
},
body: JSON.stringify({
warrenId,
- path: rest,
+ path,
newName,
}),
});
diff --git a/frontend/pages/warrens/[...path].vue b/frontend/pages/warrens/files.vue
similarity index 58%
rename from frontend/pages/warrens/[...path].vue
rename to frontend/pages/warrens/files.vue
index 107cf4f..bde6242 100644
--- a/frontend/pages/warrens/[...path].vue
+++ b/frontend/pages/warrens/files.vue
@@ -7,9 +7,24 @@ definePageMeta({
middleware: ['authenticated'],
});
-const entries = useAsyncData('current-directory', () =>
- getWarrenDirectory(useWarrenRoute().value)
-).data;
+const warrenStore = useWarrenStore();
+
+if (warrenStore.current == null) {
+ await navigateTo({
+ path: '/warrens',
+ });
+}
+
+const entries = useAsyncData('current-directory', async () => {
+ if (warrenStore.current == null) {
+ return null;
+ }
+
+ return await getWarrenDirectory(
+ warrenStore.current.warrenId,
+ warrenStore.current.path
+ );
+}).data;
diff --git a/frontend/pages/warrens/index.vue b/frontend/pages/warrens/index.vue
index 23b84d8..8dcb23d 100644
--- a/frontend/pages/warrens/index.vue
+++ b/frontend/pages/warrens/index.vue
@@ -1,26 +1,35 @@
- selectWarren(warren)"
>
-
-
+
+ {{ warren.name }}
+
diff --git a/frontend/stores/index.ts b/frontend/stores/index.ts
index 04318a6..93720eb 100644
--- a/frontend/stores/index.ts
+++ b/frontend/stores/index.ts
@@ -2,20 +2,48 @@ import { defineStore } from 'pinia';
import type { DirectoryEntry } from '~/types';
import type { Warren } from '~/types/warrens';
-export const useWarrenStore = defineStore<
- 'warrens',
- {
- warrens: Record;
- }
->('warrens', {
+export const useWarrenStore = defineStore('warrens', {
state: () => ({
- warrens: {},
- upload: null,
+ warrens: {} as Record,
+ current: null as { warrenId: string; path: string } | null,
}),
-});
+ actions: {
+ async setCurrentWarren(warrenId: string, path: string) {
+ this.current = {
+ warrenId,
+ path,
+ };
+ await refreshNuxtData('current-directory');
+ },
+ async addToCurrentWarrenPath(path: string) {
+ if (this.current == null) {
+ return;
+ }
-export const useWarrenRoute = () =>
- computed(() => useRoute().path.split('/warrens/')[1]);
+ if (!this.current.path.endsWith('/')) {
+ this.current.path += '/';
+ }
+
+ this.current.path += path;
+ await refreshNuxtData('current-directory');
+ },
+ async setCurrentWarrenPath(path: string) {
+ if (this.current == null) {
+ return;
+ }
+
+ if (!path.startsWith('/')) {
+ path = '/' + path;
+ }
+
+ this.current.path = path;
+ await refreshNuxtData('current-directory');
+ },
+ clearCurrentWarren() {
+ this.current = null;
+ },
+ },
+});
export const useCreateDirectoryDialog = defineStore('create_directory_dialog', {
state: () => ({
diff --git a/frontend/stores/upload.ts b/frontend/stores/upload.ts
index c6e716e..e4b39a0 100644
--- a/frontend/stores/upload.ts
+++ b/frontend/stores/upload.ts
@@ -5,7 +5,7 @@ export const useUploadStore = defineStore<
{
startIndex: number;
files: UploadFile[];
- path: string | null;
+ destination: { warrenId: string; path: string } | null;
progress: {
loadedBytes: number;
totalBytes: number;
@@ -15,7 +15,7 @@ export const useUploadStore = defineStore<
state: () => ({
startIndex: 0,
files: [],
- path: null,
+ destination: null,
progress: null,
}),
});
diff --git a/frontend/utils/api.ts b/frontend/utils/api.ts
index d169748..e655efa 100644
--- a/frontend/utils/api.ts
+++ b/frontend/utils/api.ts
@@ -8,14 +8,14 @@ export function getApiUrl(path: string): string {
* @param path - The warren path (e.g. `a3f79579-9155-4492-a579-b0253c8d3bf8/my-directory/`)
* @returns A prettier path `a3f79579-9155-4492-a579-b0253c8d3bf8/my-directory` -> `my-warren/my-directory`
*/
-export function routeWithWarrenName(path: string): string {
- const warrens = useWarrenStore().warrens;
+export function routeWithWarrenName(warrenId: string, path: string): string {
+ const warrenStore = useWarrenStore();
- const id = path.split('/')[0];
-
- if (!(id in warrens)) {
+ if (!(warrenId in warrenStore.warrens)) {
return path;
}
- return path.replace(id, warrens[id].name);
+ const warrenName = warrenStore.warrens[warrenId].name;
+
+ return `${warrenName}${path}`;
}
diff --git a/frontend/utils/index.ts b/frontend/utils/index.ts
index 7fcfb53..70bf3f9 100644
--- a/frontend/utils/index.ts
+++ b/frontend/utils/index.ts
@@ -1,53 +1,9 @@
-import type { BreadcrumbData } from '~/types';
-
-export function getBreadcrumbs(path: string): BreadcrumbData[] {
- const { warrens } = useWarrenStore();
-
- const crumbs = path
- .split('/')
- .filter((v) => v.length > 0)
- .map((v) => ({
- name: v,
- href: '#',
- }));
-
- crumbs.unshift({ name: '/', href: '/' });
-
- for (let i = 1; i < crumbs.length; i++) {
- crumbs[i].name = decodeURI(crumbs[i].name);
- crumbs[i].href =
- '/' +
- path
- .split('/')
- .slice(1, i + 1)
- .join('/');
- }
-
- if (
- crumbs.length >= 3 &&
- crumbs[1].href === '/warrens' &&
- crumbs[2].name in warrens
- ) {
- crumbs[2].name = warrens[crumbs[2].name].name;
- }
-
- return crumbs;
-}
-
export function preventDefault(event: Event) {
event.preventDefault();
return event;
}
-export function joinPaths(base: string, other: string): string {
- if (!base.endsWith('/')) {
- base += '/';
- }
-
- return base + other;
-}
-
export function splitOnce(
str: string,
search: string