dont use [...path] routing since it breaks building statically
This commit is contained in:
@@ -27,17 +27,9 @@ export async function getWarrens(): Promise<Record<string, Warren>> {
|
||||
}
|
||||
|
||||
export async function getWarrenDirectory(
|
||||
warrenId: string,
|
||||
path: string
|
||||
): Promise<DirectoryEntry[]> {
|
||||
// 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,
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user