Skip to content

Commit

Permalink
主要 新的压缩方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xushengfeng committed Dec 8, 2022
1 parent b43d3d4 commit 7c25ecb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"homepage": "https://github.com/xushengfeng/xlinkote/",
"license": "GPL-3.0",
"dependencies": {
"@zip.js/zip.js": "^2.6.60",
"color": "^4.2.3",
"crypto-js": "^4.1.1",
"deep-diff": "^1.0.2",
Expand All @@ -27,7 +28,6 @@
"markdown-it-task-lists": "^2.1.1",
"mathjax": "^3.2.2",
"mermaid": "^9.1.7",
"pako": "^2.0.4",
"pdfjs-dist": "^3.1.81",
"three": "^0.146.0",
"turndown": "^7.1.1",
Expand All @@ -38,10 +38,10 @@
"@types/deep-diff": "^1.0.1",
"@types/three": "^0.144.0",
"autoprefixer": "^10.4.12",
"download": "^8.0.0",
"postcss": "^8.4.17",
"tailwindcss": "^3.1.8",
"typescript": "^4.8.4",
"vite": "^3.1.5",
"download": "^8.0.0"
"vite": "^3.1.5"
}
}
13 changes: 7 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 30 additions & 33 deletions src/js/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2696,14 +2696,14 @@ async function get_xln_value(path: string) {
o = JSON.parse(<string>str);
} catch (e) {
if (store.webdav.加密密钥) {
let bytes = CryptoJS.AES.decrypt(str, store.webdav.加密密钥);
str = bytes.toString(CryptoJS.enc.Utf8);
if (!str) {
let password = prompt("密钥错误,请输入其他密钥");
let bytes = CryptoJS.AES.decrypt(str, password);
str = bytes.toString(CryptoJS.enc.Utf8);
}
str = 解压(str);
let b = (await client.getFileContents(path)) as ArrayBuffer;
let blob = new Blob([b]);
const zipFileReader = new zip.BlobReader(blob);
const zipWriter = new zip.TextWriter();
const zipReader = new zip.ZipReader(zipFileReader);
const firstEntry = (await zipReader.getEntries())[0];
str = await firstEntry.getData(zipWriter, { password: store.webdav.加密密钥 });
await zipReader.close();
o = JSON.parse(<string>str);
}
}
Expand All @@ -2727,10 +2727,20 @@ async function put_xln_value() {
}
let t = JSON.stringify(get_data());
if (store.webdav.加密密钥) {
t = 压缩(t);
t = CryptoJS.AES.encrypt(t, store.webdav.加密密钥).toString();
let b = await 压缩(t);
let reader = new FileReader();
reader.onload = async function () {
console.log(this.result);
let v = await client.putFileContents(path, this.result);
show_upload_pro(v);
};
reader.readAsArrayBuffer(b);
} else {
let v = await client.putFileContents(path, t);
show_upload_pro(v);
}
let v = await client.putFileContents(path, t);
}
function show_upload_pro(v: boolean) {
if (v) {
put_toast("✅文件上传成功");
} else {
Expand All @@ -2752,29 +2762,16 @@ function auto_put_xln() {
}
}

import pako from "pako";

function 压缩(t: string): string {
let c = pako.deflate(t);
let res = "";
let chunk = 8 * 1024;
let i: number;
for (i = 0; i < c.length / chunk; i++) {
res += String.fromCharCode.apply(null, c.slice(i * chunk, (i + 1) * chunk));
}
res += String.fromCharCode.apply(null, c.slice(i * chunk));
return res;
}

function 解压(t: string): string {
let arr = [];
for (var i = 0, j = t.length; i < j; ++i) {
arr.push(t.charCodeAt(i));
}
import * as zip from "@zip.js/zip.js";

let tmpUint8Array = new Uint8Array(arr);
let r = pako.inflate(tmpUint8Array, { to: "string" });
return r;
async function 压缩(t: string) {
const zipFileWriter = new zip.BlobWriter("application/zip");
const textReader = new zip.TextReader(t);
const zipWriter = new zip.ZipWriter(zipFileWriter, { password: store.webdav.加密密钥 });
await zipWriter.add(get_file_name() + ".xln", textReader);
await zipWriter.close();
const zipFileBlob = await zipFileWriter.getData();
return zipFileBlob;
}

// 设置
Expand Down

0 comments on commit 7c25ecb

Please sign in to comment.