Allow single zip upload + improve manga extraction
This commit is contained in:
@@ -26,10 +26,17 @@ export async function unzipManga(file: File) {
|
||||
|
||||
for (const entry of sortedEntries) {
|
||||
const mime = getMimeType(entry.filename);
|
||||
if (imageTypes.includes(mime)) {
|
||||
const isMokuroFile = entry.filename.split('.').pop() === 'mokuro'
|
||||
|
||||
if (imageTypes.includes(mime) || isMokuroFile) {
|
||||
const blob = await entry.getData?.(new BlobWriter(mime));
|
||||
if (blob) {
|
||||
const file = new File([blob], entry.filename, { type: mime });
|
||||
if (!file.webkitRelativePath) {
|
||||
Object.defineProperty(file, 'webkitRelativePath', {
|
||||
value: file.name
|
||||
})
|
||||
}
|
||||
unzippedFiles[entry.filename] = file;
|
||||
}
|
||||
}
|
||||
@@ -162,6 +169,11 @@ export async function processFiles(_files: File[]) {
|
||||
if (ext && zipTypes.includes(ext)) {
|
||||
const unzippedFiles = await unzipManga(file);
|
||||
|
||||
if (files.length === 1) {
|
||||
processFiles(Object.values(unzippedFiles))
|
||||
return;
|
||||
}
|
||||
|
||||
volumes[path] = {
|
||||
...volumes[path],
|
||||
files: unzippedFiles
|
||||
|
||||
@@ -6,40 +6,17 @@ import {
|
||||
ZipWriter,
|
||||
} from "@zip.js/zip.js";
|
||||
|
||||
async function zipVolumes(manga: Volume[]) {
|
||||
const volumeZips = []
|
||||
|
||||
for (const volume of manga) {
|
||||
const files = Object.values(volume.files);
|
||||
export async function zipManga(manga: Volume[]) {
|
||||
const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
|
||||
|
||||
const promises = files.map((file) => {
|
||||
const promises = manga.map((volume) => {
|
||||
const imagePromises = Object.values(volume.files).map((file) => {
|
||||
return zipWriter.add(file.name, new BlobReader(file))
|
||||
})
|
||||
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
|
||||
volumeZips.push({
|
||||
zipName: decodeURI(volume.volumeName),
|
||||
zipBlob: await zipWriter.close(),
|
||||
mokuroData: JSON.stringify(volume.mokuroData)
|
||||
});
|
||||
}
|
||||
|
||||
return volumeZips;
|
||||
}
|
||||
|
||||
export async function zipManga(manga: Volume[]) {
|
||||
const volumeZips = await zipVolumes(manga)
|
||||
const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
|
||||
|
||||
|
||||
const promises = volumeZips.map((volumeZip) => {
|
||||
return [
|
||||
zipWriter.add(`${volumeZip.zipName}.mokuro`, new TextReader(volumeZip.mokuroData)),
|
||||
zipWriter.add(`${volumeZip.zipName}.zip`, new BlobReader(volumeZip.zipBlob))
|
||||
zipWriter.add(`${volume.volumeName}.mokuro`, new TextReader(JSON.stringify(volume.mokuroData))),
|
||||
...imagePromises,
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user