change to use jszip
This commit is contained in:
parent
ae00815f76
commit
73b03e28ba
|
|
@ -21,7 +21,9 @@
|
|||
"dependencies": {
|
||||
"brotli-wasm": "^2.0.1",
|
||||
"exit-hook": "^4.0.0",
|
||||
"file-type": "^21.1.1",
|
||||
"firebase-admin": "^12.2.0",
|
||||
"jszip": "^3.10.1",
|
||||
"prisma": "^5.17.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import { startBrCompress } from "./br-load";
|
|||
import { dir } from "./dir";
|
||||
import { g } from "./global";
|
||||
import { gunzipAsync } from "./gzip";
|
||||
import { fileTypeFromBlob, fileTypeFromBuffer } from "file-type";
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
|
|
@ -109,11 +110,31 @@ export const deploy = {
|
|||
await removeAsync(dir("public"));
|
||||
}
|
||||
if (g.deploy.content.public) {
|
||||
console.log(`[DEBUG] Creating public directory and writing ${Object.keys(g.deploy.content.public).length} files`);
|
||||
await dirAsync(dir("public"));
|
||||
for (const [k, v] of Object.entries(g.deploy.content.public)) {
|
||||
await writeAsync(dir(`public/${k}`), v);
|
||||
console.log(`[DEBUG] Extracting public directory from zip file`);
|
||||
const zipPath = dir(`app/web/deploy/${ts}.zip`);
|
||||
const publicDestPath = dir("public");
|
||||
|
||||
await dirAsync(publicDestPath);
|
||||
|
||||
// Read the zip file
|
||||
const JSZip = (await import("jszip")).default;
|
||||
const zipData = await Bun.file(zipPath).arrayBuffer();
|
||||
const zip = await JSZip.loadAsync(zipData);
|
||||
|
||||
// Extract only files in the public folder
|
||||
const publicFiles = Object.keys(zip.files).filter(path => path.startsWith("public/"));
|
||||
|
||||
for (const filePath of publicFiles) {
|
||||
const file = zip.files[filePath];
|
||||
if (!file.dir) {
|
||||
const content = await file.async("uint8array");
|
||||
const destPath = dir(filePath);
|
||||
await dirAsync(destPath.substring(0, destPath.lastIndexOf("/")));
|
||||
await Bun.write(destPath, content);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[DEBUG] Successfully extracted ${publicFiles.length} files from public folder`);
|
||||
}
|
||||
console.log(`[DEBUG] Public files setup completed`);
|
||||
|
||||
|
|
@ -343,8 +364,10 @@ export const deploy = {
|
|||
|
||||
if (isBinary) {
|
||||
g.deploy.content.public[relativePath] = fileContent;
|
||||
console.log(`[DEBUG] ✓ Loaded binary file for public/${relativePath}`);
|
||||
} else {
|
||||
g.deploy.content.public[relativePath] = new TextDecoder().decode(fileContent);
|
||||
console.log(`[DEBUG] ✓ Loaded text file for public/${relativePath}`);
|
||||
}
|
||||
} else if (entry.filename.startsWith('server/')) {
|
||||
const relativePath = entry.filename.slice(7); // Remove 'server/' prefix
|
||||
|
|
|
|||
Loading…
Reference in New Issue