rename directory entries
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user