commit 8cffa38ebae2a46b7c8e855c7b21a124e35adc89
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Thu Mar 10 23:52:56 2022 +0800
bypass more cors for onedrive
commit 1b59ac1e58032099068aab55d22ef96c6396f203
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 23:58:28 2022 +0800
change wordings for webdav cors
commit 73142eb18b59fff20839680e866f51cfcb0a6226
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 23:38:58 2022 +0800
remove cors hint for webdav
commit 7dbb0b49d50e529b2b72e55ea2c8503ba7fa9268
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 23:31:54 2022 +0800
fix webdav
commit c28c4e19720a56230d483acf306463d42e619fa4
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 23:31:35 2022 +0800
remove more headers
commit 4eeae7043fa68d669a5c23c5549c14c1260ce638
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 23:18:32 2022 +0800
polish cors hints for s3
commit d9e55a91a1c413e9419cd6b30a3a6e3b403d483b
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 22:40:37 2022 +0800
fix format
commit b780a3eb4e37b05b8e8b92d6a2f9283b3459d738
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 22:37:02 2022 +0800
finally correctly inject requestUrl into s3
commit 6a55a1a43d7653d65579ab88aa816e5d54cd276a
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 22:33:18 2022 +0800
to arraybuffer from view
commit 2f2607b4f0a3d9db5943528ced57cb2fdb419607
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Wed Mar 9 13:31:22 2022 +0800
add split ranges
commit ea24da24dea83fdb770e7e391cf8a2e4fea78d0d
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Sun Mar 6 22:57:50 2022 +0800
add settings of bypassing for s3
commit 2f099dc8ca1e66ea137b28dd329be50968734ba6
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Sun Mar 6 22:38:07 2022 +0800
use api ver var
commit 74c7ce2449a88cbe7c7f50cbb687b36ff3732c04
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Sun Mar 6 22:37:25 2022 +0800
correct way to inject s3
commit f29945d73132d21b2c44472ec2cafc06b9d71e8f
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Tue Mar 1 00:09:57 2022 +0800
add new http handler
commit d55104cb08e168cbcc243cf901cbd7f46f2e324b
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Mon Feb 28 22:59:55 2022 +0800
add types for patch
commit 50b79ade7188ee7dfab9c1d03119585db358ba6f
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Mon Feb 28 08:25:19 2022 +0800
remove verbose
commit 83f0e71aa15aa7586f6d4e105cd77c25c2e113ce
Author: fyears <1142836+fyears@users.noreply.github.com>
Date: Mon Feb 28 08:25:04 2022 +0800
patch webdav!
236 lines
6.2 KiB
TypeScript
236 lines
6.2 KiB
TypeScript
import { expect } from "chai";
|
|
import { JSDOM } from "jsdom";
|
|
import * as misc from "../src/misc";
|
|
|
|
describe("Misc: hidden file", () => {
|
|
it("should find hidden file correctly", () => {
|
|
let item = "";
|
|
expect(misc.isHiddenPath(item)).to.be.false;
|
|
|
|
item = ".";
|
|
expect(misc.isHiddenPath(item)).to.be.false;
|
|
|
|
item = "..";
|
|
expect(misc.isHiddenPath(item)).to.be.false;
|
|
|
|
item = "/x/y/z/../././../a/b/c";
|
|
expect(misc.isHiddenPath(item)).to.be.false;
|
|
|
|
item = ".hidden";
|
|
expect(misc.isHiddenPath(item)).to.be.true;
|
|
|
|
item = "_hidden_loose";
|
|
expect(misc.isHiddenPath(item)).to.be.true;
|
|
expect(misc.isHiddenPath(item, false)).to.be.false;
|
|
|
|
item = "/sdd/_hidden_loose";
|
|
expect(misc.isHiddenPath(item)).to.be.true;
|
|
|
|
item = "what/../_hidden_loose/what/what/what";
|
|
expect(misc.isHiddenPath(item)).to.be.true;
|
|
|
|
item = "what/../_hidden_loose/what/what/what";
|
|
expect(misc.isHiddenPath(item, false)).to.be.false;
|
|
|
|
item = "what/../_hidden_loose/../.hidden/what/what/what";
|
|
expect(misc.isHiddenPath(item, false)).to.be.true;
|
|
});
|
|
});
|
|
|
|
describe("Misc: get folder levels", () => {
|
|
it("should ignore empty path", () => {
|
|
const item = "";
|
|
expect(misc.getFolderLevels(item)).to.be.empty;
|
|
});
|
|
|
|
it("should ignore single file", () => {
|
|
const item = "xxx";
|
|
expect(misc.getFolderLevels(item)).to.be.empty;
|
|
});
|
|
|
|
it("should detect path ending with /", () => {
|
|
const item = "xxx/";
|
|
const res = ["xxx"];
|
|
expect(misc.getFolderLevels(item)).to.deep.equal(res);
|
|
});
|
|
|
|
it("should correctly split folders and files", () => {
|
|
const item = "xxx/yyy/zzz.md";
|
|
const res = ["xxx", "xxx/yyy"];
|
|
expect(misc.getFolderLevels(item)).to.deep.equal(res);
|
|
|
|
const item2 = "xxx/yyy/zzz";
|
|
const res2 = ["xxx", "xxx/yyy"];
|
|
expect(misc.getFolderLevels(item2)).to.deep.equal(res2);
|
|
|
|
const item3 = "xxx/yyy/zzz/";
|
|
const res3 = ["xxx", "xxx/yyy", "xxx/yyy/zzz"];
|
|
expect(misc.getFolderLevels(item3)).to.deep.equal(res3);
|
|
});
|
|
|
|
it("should correctly add ending slash if required", () => {
|
|
const item = "xxx/yyy/zzz.md";
|
|
const res = ["xxx/", "xxx/yyy/"];
|
|
expect(misc.getFolderLevels(item, true)).to.deep.equal(res);
|
|
|
|
const item2 = "xxx/yyy/zzz";
|
|
const res2 = ["xxx/", "xxx/yyy/"];
|
|
expect(misc.getFolderLevels(item2, true)).to.deep.equal(res2);
|
|
|
|
const item3 = "xxx/yyy/zzz/";
|
|
const res3 = ["xxx/", "xxx/yyy/", "xxx/yyy/zzz/"];
|
|
expect(misc.getFolderLevels(item3, true)).to.deep.equal(res3);
|
|
});
|
|
|
|
it("should treat path starting with / correctly", () => {
|
|
const item = "/xxx/yyy/zzz.md";
|
|
const res = ["/xxx", "/xxx/yyy"];
|
|
expect(misc.getFolderLevels(item)).to.deep.equal(res);
|
|
|
|
const item2 = "/xxx/yyy/zzz";
|
|
const res2 = ["/xxx", "/xxx/yyy"];
|
|
expect(misc.getFolderLevels(item2)).to.deep.equal(res2);
|
|
|
|
const item3 = "/xxx/yyy/zzz/";
|
|
const res3 = ["/xxx", "/xxx/yyy", "/xxx/yyy/zzz"];
|
|
expect(misc.getFolderLevels(item3)).to.deep.equal(res3);
|
|
|
|
const item4 = "/xxx";
|
|
const res4 = [] as string[];
|
|
expect(misc.getFolderLevels(item4)).to.deep.equal(res4);
|
|
|
|
const item5 = "/";
|
|
const res5 = [] as string[];
|
|
expect(misc.getFolderLevels(item5)).to.deep.equal(res5);
|
|
});
|
|
});
|
|
|
|
describe("Misc: get parent folder", () => {
|
|
it("should treat empty path correctly", () => {
|
|
const item = "";
|
|
expect(misc.getParentFolder(item)).equals("/");
|
|
});
|
|
|
|
it("should treat one level path correctly", () => {
|
|
let item = "abc/";
|
|
expect(misc.getParentFolder(item)).equals("/");
|
|
item = "/efg/";
|
|
expect(misc.getParentFolder(item)).equals("/");
|
|
});
|
|
|
|
it("should treat more levels path correctly", () => {
|
|
let item = "abc/efg";
|
|
expect(misc.getParentFolder(item)).equals("abc/");
|
|
item = "/hij/klm/";
|
|
expect(misc.getParentFolder(item)).equals("/hij/");
|
|
});
|
|
});
|
|
|
|
describe("Misc: vaild file name tests", () => {
|
|
it("should treat no ascii correctly", async () => {
|
|
const x = misc.isVaildText("😄🍎 apple 苹果");
|
|
// console.log(x)
|
|
expect(x).to.be.true;
|
|
});
|
|
|
|
it("should find not-printable chars correctly", async () => {
|
|
const x = misc.isVaildText("😄🍎 apple 苹果\u0000");
|
|
// console.log(x)
|
|
expect(x).to.be.false;
|
|
});
|
|
|
|
it("should allow spaces/slashes/...", async () => {
|
|
const x = misc.isVaildText("😄🍎 apple 苹果/-_=/\\*%^&@#$`");
|
|
expect(x).to.be.true;
|
|
});
|
|
});
|
|
|
|
describe("Misc: get dirname", () => {
|
|
it("should return itself for folder", async () => {
|
|
const x = misc.getPathFolder("ssss/");
|
|
// console.log(x)
|
|
expect(x).to.equal("ssss/");
|
|
});
|
|
|
|
it("should return folder for file", async () => {
|
|
const x = misc.getPathFolder("sss/yyy");
|
|
// console.log(x)
|
|
expect(x).to.equal("sss/");
|
|
});
|
|
|
|
it("should treat / specially", async () => {
|
|
const x = misc.getPathFolder("/");
|
|
expect(x).to.equal("/");
|
|
|
|
const y = misc.getPathFolder("/abc");
|
|
expect(y).to.equal("/");
|
|
});
|
|
});
|
|
|
|
describe("Misc: extract svg", () => {
|
|
beforeEach(function () {
|
|
const fakeBrowser = new JSDOM("");
|
|
global.window = fakeBrowser.window as any;
|
|
});
|
|
|
|
it("should extract rect from svg correctly", () => {
|
|
const x = "<svg><rect/><g/></svg>";
|
|
const y = misc.extractSvgSub(x);
|
|
// console.log(x)
|
|
expect(y).to.equal("<rect/><g/>");
|
|
});
|
|
});
|
|
|
|
describe("Misc: get split ranges", () => {
|
|
it("should deal with big parts", () => {
|
|
const k = misc.getSplitRanges(10, 20);
|
|
const k2: misc.SplitRange[] = [
|
|
{
|
|
partNum: 1,
|
|
start: 0,
|
|
end: 10,
|
|
},
|
|
];
|
|
expect(k).to.deep.equal(k2);
|
|
});
|
|
|
|
it("should deal with 0 remainder", () => {
|
|
const k = misc.getSplitRanges(20, 10);
|
|
const k2: misc.SplitRange[] = [
|
|
{
|
|
partNum: 1,
|
|
start: 0,
|
|
end: 10,
|
|
},
|
|
{
|
|
partNum: 2,
|
|
start: 10,
|
|
end: 20,
|
|
},
|
|
];
|
|
expect(k).to.deep.equal(k2);
|
|
});
|
|
|
|
it("should deal with not-0 remainder", () => {
|
|
const k = misc.getSplitRanges(25, 10);
|
|
const k2: misc.SplitRange[] = [
|
|
{
|
|
partNum: 1,
|
|
start: 0,
|
|
end: 10,
|
|
},
|
|
{
|
|
partNum: 2,
|
|
start: 10,
|
|
end: 20,
|
|
},
|
|
{
|
|
partNum: 3,
|
|
start: 20,
|
|
end: 25,
|
|
},
|
|
];
|
|
expect(k).to.deep.equal(k2);
|
|
});
|
|
});
|