drag DirectoryEntry onto directory to move
This commit is contained in:
@@ -300,3 +300,49 @@ export async function fetchFile(
|
||||
data: data.value,
|
||||
};
|
||||
}
|
||||
|
||||
export async function moveFile(
|
||||
warrenId: string,
|
||||
path: string,
|
||||
fileName: string,
|
||||
targetPath: string
|
||||
): Promise<{ success: boolean }> {
|
||||
if (!path.endsWith('/')) {
|
||||
path += '/';
|
||||
}
|
||||
path += fileName;
|
||||
|
||||
if (!targetPath.endsWith('/')) {
|
||||
targetPath += '/';
|
||||
}
|
||||
targetPath += fileName;
|
||||
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/mv`), {
|
||||
method: 'POST',
|
||||
headers: getApiHeaders(),
|
||||
body: JSON.stringify({
|
||||
warrenId,
|
||||
path,
|
||||
targetPath,
|
||||
}),
|
||||
});
|
||||
|
||||
if (status.value !== 'success') {
|
||||
toast.error('Move', {
|
||||
id: 'MOVE_FILE_TOAST',
|
||||
description: `Failed to move ${fileName}`,
|
||||
});
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
await refreshNuxtData('current-directory');
|
||||
|
||||
toast.success('Rename', {
|
||||
id: 'RENAME_FILE_TOAST',
|
||||
description: `Successfully moved ${fileName} to ${targetPath}`,
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user