refactor file system operations
the most notable improvement is that uploads are now using streams so they no longer require the entire file to be stored in memory
This commit is contained in:
@@ -54,7 +54,7 @@ function onFilesChanged(event: Event) {
|
||||
|
||||
if (uploadStore.destination == null) {
|
||||
uploadStore.destination = warrenStore.current;
|
||||
} else if (currentAndUploadRouteMatch.value) {
|
||||
} else if (!currentAndUploadRouteMatch.value) {
|
||||
toast.warning('Upload', {
|
||||
description:
|
||||
'The unfinished items belong to a different directory. Remove them before attempting to upload to a different directory.',
|
||||
|
||||
@@ -24,7 +24,10 @@ function createObjectUrl(file: File): string {
|
||||
{ 'p-2': !file.data.type.startsWith('image/') },
|
||||
]"
|
||||
>
|
||||
<div v-if="file.status === 'not_uploaded'" class="h-full w-full">
|
||||
<div
|
||||
v-if="file.status === 'not_uploaded'"
|
||||
class="flex h-full w-full items-center justify-center"
|
||||
>
|
||||
<img
|
||||
v-if="file.data.type.startsWith('image/')"
|
||||
:src="createObjectUrl(file.data)"
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function getWarrenDirectory(
|
||||
): Promise<DirectoryEntry[]> {
|
||||
const { data, error } = await useFetch<
|
||||
ApiResponse<{ files: DirectoryEntry[] }>
|
||||
>(getApiUrl(`warrens/files`), {
|
||||
>(getApiUrl(`warrens/files/ls`), {
|
||||
method: 'POST',
|
||||
headers: getApiHeaders(),
|
||||
body: JSON.stringify({
|
||||
@@ -60,7 +60,7 @@ export async function createDirectory(
|
||||
|
||||
path += directoryName;
|
||||
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/directory`), {
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/mkdir`), {
|
||||
method: 'POST',
|
||||
headers: getApiHeaders(),
|
||||
body: JSON.stringify({
|
||||
@@ -99,8 +99,8 @@ export async function deleteWarrenDirectory(
|
||||
|
||||
path += directoryName;
|
||||
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/directory`), {
|
||||
method: 'DELETE',
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/rm`), {
|
||||
method: 'POST',
|
||||
headers: getApiHeaders(),
|
||||
body: JSON.stringify({
|
||||
warrenId,
|
||||
@@ -139,12 +139,13 @@ export async function deleteWarrenFile(
|
||||
|
||||
path += fileName;
|
||||
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/file`), {
|
||||
method: 'DELETE',
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/rm`), {
|
||||
method: 'POST',
|
||||
headers: getApiHeaders(),
|
||||
body: JSON.stringify({
|
||||
warrenId,
|
||||
path,
|
||||
force: false,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -174,7 +175,7 @@ export async function uploadToWarren(
|
||||
onProgress: ((loaded: number, total: number) => void) | undefined
|
||||
): Promise<{ success: boolean }> {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', getApiUrl(`warrens/files/upload`));
|
||||
xhr.open('POST', getApiUrl(`warrens/files/save`));
|
||||
xhr.upload.onprogress = (e) => {
|
||||
onProgress?.(e.loaded, e.total);
|
||||
};
|
||||
@@ -236,15 +237,17 @@ export async function renameWarrenEntry(
|
||||
if (!path.endsWith('/')) {
|
||||
path += '/';
|
||||
}
|
||||
let targetPath = path;
|
||||
targetPath += newName;
|
||||
path += currentName;
|
||||
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/rename`), {
|
||||
method: 'PATCH',
|
||||
const { status } = await useFetch(getApiUrl(`warrens/files/mv`), {
|
||||
method: 'POST',
|
||||
headers: getApiHeaders(),
|
||||
body: JSON.stringify({
|
||||
warrenId,
|
||||
path,
|
||||
newName,
|
||||
targetPath,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -277,7 +280,7 @@ export async function fetchFile(
|
||||
path += fileName;
|
||||
|
||||
const { data, error } = await useFetch<Blob>(
|
||||
getApiUrl(`warrens/files/fetch?warrenId=${warrenId}&path=${path}`),
|
||||
getApiUrl(`warrens/files/cat?warrenId=${warrenId}&path=${path}`),
|
||||
{
|
||||
method: 'GET',
|
||||
headers: getApiHeaders(),
|
||||
|
||||
Reference in New Issue
Block a user