Fix uploading

This commit is contained in:
ZXY101
2023-09-29 11:52:56 +02:00
parent 133567a7a4
commit 0bb5c8a5ac
2 changed files with 37 additions and 11 deletions

View File

@@ -5,7 +5,6 @@
import { onMount } from 'svelte';
import { scanFiles } from '$lib/upload';
import { formatBytes } from '$lib/util/upload';
import { catalog } from '$lib/catalog';
export let open = false;

View File

@@ -30,17 +30,31 @@ export async function unzipManga(file: File) {
}
function getDetails(file: File) {
const [filename, ext] = file.name.split('.');
const { webkitRelativePath, name } = file
const [filename, ext] = name.split('.');
let path = filename
if (webkitRelativePath) {
path = webkitRelativePath.split('.')[0]
}
return {
filename,
ext
ext,
path
};
}
async function getFile(fileEntry: FileSystemFileEntry) {
try {
return new Promise<File>((resolve, reject) => fileEntry.file(resolve, reject));
return new Promise<File>((resolve, reject) => fileEntry.file((file) => {
if (!file.webkitRelativePath) {
Object.defineProperty(file, 'webkitRelativePath', {
value: fileEntry.fullPath.substring(1)
})
}
resolve(file)
}, reject));
} catch (err) {
console.log(err);
}
@@ -69,8 +83,7 @@ export async function processFiles(files: File[]) {
const mangas: string[] = [];
for (const file of files) {
const { ext, filename } = getDetails(file);
const { type, webkitRelativePath } = file;
const { ext, filename, path } = getDetails(file);
if (ext === 'mokuro') {
const mokuroData: Volume['mokuroData'] = JSON.parse(await file.text());
@@ -79,20 +92,33 @@ export async function processFiles(files: File[]) {
mangas.push(mokuroData.title_uuid);
}
volumes[filename] = {
...volumes[filename],
volumes[path] = {
...volumes[path],
mokuroData,
volumeName: filename
};
continue;
}
}
for (const file of files) {
const { ext, path } = getDetails(file);
const { type, webkitRelativePath } = file;
const mimeType = type || getMimeType(file.name);
if (imageTypes.includes(mimeType)) {
if (webkitRelativePath) {
const imageName = webkitRelativePath.split('/').at(-1);
const vol = webkitRelativePath.split('/').at(-2);
let vol = ''
Object.keys(volumes).forEach((key) => {
if (webkitRelativePath.startsWith(key)) {
vol = key
}
})
if (vol && imageName) {
volumes[vol] = {
@@ -110,8 +136,8 @@ export async function processFiles(files: File[]) {
if (zipTypes.includes(ext)) {
const unzippedFiles = await unzipManga(file);
volumes[filename] = {
...volumes[filename],
volumes[path] = {
...volumes[path],
files: unzippedFiles
};
@@ -124,6 +150,7 @@ export async function processFiles(files: File[]) {
if (vols.length > 0) {
const valid = vols.map((vol) => {
const { files, mokuroData, volumeName } = vol;
if (!mokuroData || !volumeName) {
showSnackbar('Missing .mokuro file');
return false;