rename directory entries

This commit is contained in:
2025-07-16 06:23:24 +02:00
parent b121c27b37
commit a2cb58867c
16 changed files with 389 additions and 21 deletions

View File

@@ -256,3 +256,49 @@ export async function uploadToWarren(
return { success: true };
}
export async function renameWarrenEntry(
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 = '/' + rest + '/';
}
rest += currentName;
const { status } = await useFetch(getApiUrl(`warrens/files/rename`), {
method: 'PATCH',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
warrenId,
path: rest,
newName,
}),
});
if (status.value !== 'success') {
toast.error('Rename', {
id: 'RENAME_FILE_TOAST',
description: `Failed to rename ${currentName}`,
});
return { success: false };
}
await refreshNuxtData('current-directory');
toast.success('Rename', {
id: 'RENAME_FILE_TOAST',
description: `Successfully renamed ${currentName} to ${newName}`,
});
return { success: true };
}