mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-26 02:39:45 +02:00
fix bug on zip archive
This commit is contained in:
@ -2,6 +2,15 @@ String.prototype.getlink = function(root)
|
||||
{
|
||||
return API.REST + "/VFS/get/" + this.abspath(root);
|
||||
}
|
||||
String.prototype.asBase64 = function () {
|
||||
const tmp = encodeURIComponent(this);
|
||||
return btoa(
|
||||
tmp.replace(/%([0-9A-F]{2})/g, (match, p1) =>
|
||||
String.fromCharCode(parseInt(p1, 16))
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
String.prototype.abspath = function(root)
|
||||
{
|
||||
const list = this.split("://");
|
||||
@ -206,10 +215,10 @@ class AntOSDKBaseJob {
|
||||
if (t === "object" || typeof data === "string") {
|
||||
let b64;
|
||||
if (t === "object") {
|
||||
b64 = btoa(JSON.stringify(data, undefined, 4));
|
||||
b64 = JSON.stringify(data, undefined, 4).asBase64();
|
||||
}
|
||||
else {
|
||||
b64 = btoa(data);
|
||||
b64 = data.asBase64();
|
||||
}
|
||||
b64 = `data:${m};base64,${b64}`;
|
||||
return resolve(b64);
|
||||
|
@ -49,11 +49,14 @@ class ZipJob extends AntOSDKBaseJob {
|
||||
}
|
||||
else {
|
||||
const ret = await this.read_files([file], "arraybuffer");
|
||||
const u_data = ret[0];
|
||||
const blob = new Blob( [ret[0]], {
|
||||
type: "octet/stream",
|
||||
});
|
||||
const b64 = await this.b64("binary", blob);
|
||||
const z_path = `${base}${basename}`.replace(
|
||||
/^\/+|\/+$/g,
|
||||
"");
|
||||
zip.file(z_path, u_data, { binary: true });
|
||||
zip.file(z_path, b64.replace("data:octet/stream;base64,",""), { base64: true, compression : "DEFLATE" });
|
||||
this.log_info(`${file} added to zip`);
|
||||
resolve(undefined);
|
||||
}
|
||||
@ -83,8 +86,10 @@ class ZipJob extends AntOSDKBaseJob {
|
||||
const ret = await this.scandir(src);
|
||||
await this.aradd(ret.map(v => v.path), zip, "/");
|
||||
}
|
||||
const z_data = await zip.generateAsync({ type: "base64" });
|
||||
await this.save_file(dest, "data:application/zip;base64," + z_data, "base64");
|
||||
const z_data = await zip.generateAsync({ type: "arraybuffer" });
|
||||
const blob = new Blob([z_data], {
|
||||
type: "application/octet-stream"});
|
||||
await this.save_file(dest, blob,"binary");
|
||||
this.log_info(`Zip archive saved in ${dest}`);
|
||||
resolve(dest);
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user