Fix uploading
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { scanFiles } from '$lib/upload';
|
import { scanFiles } from '$lib/upload';
|
||||||
import { formatBytes } from '$lib/util/upload';
|
import { formatBytes } from '$lib/util/upload';
|
||||||
import { catalog } from '$lib/catalog';
|
|
||||||
|
|
||||||
export let open = false;
|
export let open = false;
|
||||||
|
|
||||||
|
|||||||
@@ -30,17 +30,31 @@ export async function unzipManga(file: File) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDetails(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 {
|
return {
|
||||||
filename,
|
filename,
|
||||||
ext
|
ext,
|
||||||
|
path
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFile(fileEntry: FileSystemFileEntry) {
|
async function getFile(fileEntry: FileSystemFileEntry) {
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
@@ -69,8 +83,7 @@ export async function processFiles(files: File[]) {
|
|||||||
const mangas: string[] = [];
|
const mangas: string[] = [];
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const { ext, filename } = getDetails(file);
|
const { ext, filename, path } = getDetails(file);
|
||||||
const { type, webkitRelativePath } = file;
|
|
||||||
|
|
||||||
if (ext === 'mokuro') {
|
if (ext === 'mokuro') {
|
||||||
const mokuroData: Volume['mokuroData'] = JSON.parse(await file.text());
|
const mokuroData: Volume['mokuroData'] = JSON.parse(await file.text());
|
||||||
@@ -79,20 +92,33 @@ export async function processFiles(files: File[]) {
|
|||||||
mangas.push(mokuroData.title_uuid);
|
mangas.push(mokuroData.title_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
volumes[filename] = {
|
|
||||||
...volumes[filename],
|
volumes[path] = {
|
||||||
|
...volumes[path],
|
||||||
mokuroData,
|
mokuroData,
|
||||||
volumeName: filename
|
volumeName: filename
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const { ext, path } = getDetails(file);
|
||||||
|
const { type, webkitRelativePath } = file;
|
||||||
|
|
||||||
const mimeType = type || getMimeType(file.name);
|
const mimeType = type || getMimeType(file.name);
|
||||||
|
|
||||||
if (imageTypes.includes(mimeType)) {
|
if (imageTypes.includes(mimeType)) {
|
||||||
if (webkitRelativePath) {
|
if (webkitRelativePath) {
|
||||||
const imageName = webkitRelativePath.split('/').at(-1);
|
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) {
|
if (vol && imageName) {
|
||||||
volumes[vol] = {
|
volumes[vol] = {
|
||||||
@@ -110,8 +136,8 @@ export async function processFiles(files: File[]) {
|
|||||||
if (zipTypes.includes(ext)) {
|
if (zipTypes.includes(ext)) {
|
||||||
const unzippedFiles = await unzipManga(file);
|
const unzippedFiles = await unzipManga(file);
|
||||||
|
|
||||||
volumes[filename] = {
|
volumes[path] = {
|
||||||
...volumes[filename],
|
...volumes[path],
|
||||||
files: unzippedFiles
|
files: unzippedFiles
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,6 +150,7 @@ export async function processFiles(files: File[]) {
|
|||||||
if (vols.length > 0) {
|
if (vols.length > 0) {
|
||||||
const valid = vols.map((vol) => {
|
const valid = vols.map((vol) => {
|
||||||
const { files, mokuroData, volumeName } = vol;
|
const { files, mokuroData, volumeName } = vol;
|
||||||
|
|
||||||
if (!mokuroData || !volumeName) {
|
if (!mokuroData || !volumeName) {
|
||||||
showSnackbar('Missing .mokuro file');
|
showSnackbar('Missing .mokuro file');
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user