refac
This commit is contained in:
@@ -199,7 +199,7 @@ export const moveEntry = async (
|
|||||||
apiKey: string,
|
apiKey: string,
|
||||||
source: string,
|
source: string,
|
||||||
destination: string
|
destination: string
|
||||||
): Promise<{ source: string; destination: string } | null> => {
|
): Promise<{ source: string; destination: string } | { error: string }> => {
|
||||||
const url = `${baseUrl.replace(/\/$/, '')}/files/move`;
|
const url = `${baseUrl.replace(/\/$/, '')}/files/move`;
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -215,7 +215,7 @@ export const moveEntry = async (
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('open-terminal moveEntry error:', err);
|
console.error('open-terminal moveEntry error:', err);
|
||||||
return null;
|
return { error: err?.detail ?? 'Move failed' };
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -339,9 +339,11 @@
|
|||||||
if (destFolder.startsWith(sourceDir)) return;
|
if (destFolder.startsWith(sourceDir)) return;
|
||||||
|
|
||||||
const result = await moveEntry(terminal.url, terminal.key, source, destination);
|
const result = await moveEntry(terminal.url, terminal.key, source, destination);
|
||||||
toast[result ? 'success' : 'error'](
|
if ('error' in result) {
|
||||||
$i18n.t(result ? 'Moved {{name}}' : 'Failed to move {{name}}', { name: fileName })
|
toast.error(result.error);
|
||||||
);
|
} else {
|
||||||
|
toast.success($i18n.t('Moved {{name}}', { name: fileName }));
|
||||||
|
}
|
||||||
await loadDir(currentPath);
|
await loadDir(currentPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user