Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Apr 21, 2024
1 parent d3d2ece commit f09f1a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useSound from "use-sound";
import JSZip from "jszip";

import { MediaFile } from "./services/MediaConverter";
import { isZipFile, convertFiles, isValidFile } from "./services/utilities";
import { isZipFile, convertFiles, isValidFile, isFontFile, isImageFile } from "./services/utilities";

const downloadBlob = (blob: Blob) => {
const link = document.createElement("a");
Expand Down Expand Up @@ -87,13 +87,17 @@ function App() {
const handleUpload = async (files: File[]) => {
try {
for (const file of files) {
if (file.size == 0) throw Error("Invalid file.");
if (file.size === 0) throw Error("Invalid file.");

if (!isValidFile(file)) throw Error("Invalid file type.");

if (isZipFile(file)) handleZipUpload(file);
}
handleConversions(files);

if (files.length > 0 && files.every((file) => isFontFile(file) ||isImageFile(file))) {
handleConversions(files);
}

} catch (exception) {
toast.error(handleUploadError((exception as Error).message));
}
Expand Down
6 changes: 4 additions & 2 deletions src/services/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export default class Bundler {
result = main.concat(data);

if (packaged) {
const log = data.findIndex((file) => file.name.endsWith(".log"));
const log = data.findIndex((file) => {
file.name.endsWith(".log");
});
result.splice(log, 1);
}
} else {
Expand Down Expand Up @@ -124,7 +126,6 @@ export default class Bundler {
const bundle = new JSZip();

for (const [key, value] of data) {
console.log("bundling loose file", key);
bundle.file(`${key}-assets.zip`, value.assets);
}

Expand Down Expand Up @@ -152,6 +153,7 @@ export default class Bundler {
[binary, assets],
`${name}.${this.extensions[key as keyof typeof this.extensions]}`
);

bundle.file(file.name, file);
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/MediaConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class MediaConverter {

for (const file of files) {
if (!(await validate(file))) {
throw Error("Invalid file.");
throw Error(`Invalid file: ${file.filepath}`);
}
body.append(file.filepath, file.data);
}
Expand Down Expand Up @@ -96,6 +96,7 @@ export default class MediaConverter {
} else {
const content = new Blob([response[key]], { type: "text/plain" });
file = { filepath: "convert.log", data: content };
this.log = new File([content], "convert.log");
}

mediaFiles.push(file);
Expand Down

0 comments on commit f09f1a5

Please sign in to comment.