mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 18:38:11 +02:00
Add chunked upload for large files
This commit is contained in:
1 parent
da4e02472f
commit
24a6d83ea0
5 files changed
+212
-19
No files matched your search
@@ -6,9 +6,11 @@ import {
|
||||
FetchLock,
|
||||
FetchTree,
|
||||
GetDownloadUrl,
|
||||
IsLargeUpload,
|
||||
MoveEntry,
|
||||
RenameEntry,
|
||||
SetLock as SetLockApi,
|
||||
UploadFileChunked,
|
||||
UploadFiles,
|
||||
} from "../Api.js";
|
||||
import { GetFileIcon, GetFolderIcon } from "../IconStyle.js";
|
||||
@@ -161,16 +163,36 @@ export default function DirectoryPane({
|
||||
async function HandleUpload(Files) {
|
||||
if (!Files || Files.length === 0) return;
|
||||
|
||||
try {
|
||||
const Result = await UploadFiles(RootName, DirectoryPath, Files);
|
||||
if (Result.Errors && Result.Errors.length > 0) {
|
||||
SetErrorMessage(Result.Errors.join("; "));
|
||||
const FileArray = Array.from(Files);
|
||||
const SmallFiles = FileArray.filter((File) => !IsLargeUpload(File));
|
||||
const LargeFiles = FileArray.filter((File) => IsLargeUpload(File));
|
||||
const Errors = [];
|
||||
|
||||
if (SmallFiles.length > 0) {
|
||||
try {
|
||||
const Result = await UploadFiles(RootName, DirectoryPath, SmallFiles);
|
||||
if (Result.Errors && Result.Errors.length > 0) {
|
||||
Errors.push(...Result.Errors);
|
||||
}
|
||||
} catch (Error) {
|
||||
Errors.push(Error.message);
|
||||
}
|
||||
await Reload();
|
||||
OnEntryCreated();
|
||||
} catch (Error) {
|
||||
SetErrorMessage(Error.message);
|
||||
}
|
||||
|
||||
for (const File of LargeFiles) {
|
||||
try {
|
||||
await UploadFileChunked(RootName, DirectoryPath, File);
|
||||
} catch (Error) {
|
||||
Errors.push(`${File.name}: ${Error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (Errors.length > 0) {
|
||||
SetErrorMessage(Errors.join("; "));
|
||||
}
|
||||
|
||||
await Reload();
|
||||
OnEntryCreated();
|
||||
}
|
||||
|
||||
function HandleUploadButtonClick() {
|
||||
|
||||
@@ -7,9 +7,11 @@ import {
|
||||
FetchTree,
|
||||
GetAvatarUrl,
|
||||
GetDownloadUrl,
|
||||
IsLargeUpload,
|
||||
MoveEntry,
|
||||
RenameEntry,
|
||||
SetLock as SetLockApi,
|
||||
UploadFileChunked,
|
||||
UploadFiles,
|
||||
} from "../Api.js";
|
||||
import { GetFileIcon, GetFolderIcon } from "../IconStyle.js";
|
||||
@@ -362,15 +364,35 @@ export default function Sidebar({
|
||||
async function HandleUpload(Files) {
|
||||
if (!Files || Files.length === 0) return;
|
||||
|
||||
try {
|
||||
const Result = await UploadFiles(RootName, CurrentDirectoryPath, Files);
|
||||
if (Result.Errors && Result.Errors.length > 0) {
|
||||
SetErrorMessage(Result.Errors.join("; "));
|
||||
const FileArray = Array.from(Files);
|
||||
const SmallFiles = FileArray.filter((File) => !IsLargeUpload(File));
|
||||
const LargeFiles = FileArray.filter((File) => IsLargeUpload(File));
|
||||
const Errors = [];
|
||||
|
||||
if (SmallFiles.length > 0) {
|
||||
try {
|
||||
const Result = await UploadFiles(RootName, CurrentDirectoryPath, SmallFiles);
|
||||
if (Result.Errors && Result.Errors.length > 0) {
|
||||
Errors.push(...Result.Errors);
|
||||
}
|
||||
} catch (Error) {
|
||||
Errors.push(Error.message);
|
||||
}
|
||||
OnEntryCreated();
|
||||
} catch (Error) {
|
||||
SetErrorMessage(Error.message);
|
||||
}
|
||||
|
||||
for (const File of LargeFiles) {
|
||||
try {
|
||||
await UploadFileChunked(RootName, CurrentDirectoryPath, File);
|
||||
} catch (Error) {
|
||||
Errors.push(`${File.name}: ${Error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (Errors.length > 0) {
|
||||
SetErrorMessage(Errors.join("; "));
|
||||
}
|
||||
|
||||
OnEntryCreated();
|
||||
}
|
||||
|
||||
function HandleUploadButtonClick() {
|
||||
|
||||
Reference in new issue
Block a user