mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2025-12-12 17:25:56 +00:00
### Improved
- Some JWT notes have been added to the setting dialogue (#742). ### Fixed - No longer wrong values encoded into the QR code. - We can acknowledge why the QR codes have not been generated. ### Refactored - Some dependencies have been updated. - Internal functions have been modularised into `octagonal-wheels` packages and are well tested. - Fixed importing from the parent project in library codes. (#729).
This commit is contained in:
28
package-lock.json
generated
28
package-lock.json
generated
@@ -19,8 +19,8 @@
|
|||||||
"fflate": "^0.8.2",
|
"fflate": "^0.8.2",
|
||||||
"idb": "^8.0.3",
|
"idb": "^8.0.3",
|
||||||
"minimatch": "^10.0.2",
|
"minimatch": "^10.0.2",
|
||||||
"octagonal-wheels": "^0.1.42",
|
"octagonal-wheels": "^0.1.44",
|
||||||
"qrcode-generator": "^1.4.4",
|
"qrcode-generator": "^2.0.4",
|
||||||
"trystero": "^0.22.0",
|
"trystero": "^0.22.0",
|
||||||
"xxhash-wasm-102": "npm:xxhash-wasm@^1.0.2"
|
"xxhash-wasm-102": "npm:xxhash-wasm@^1.0.2"
|
||||||
},
|
},
|
||||||
@@ -9159,9 +9159,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/octagonal-wheels": {
|
"node_modules/octagonal-wheels": {
|
||||||
"version": "0.1.42",
|
"version": "0.1.44",
|
||||||
"resolved": "https://registry.npmjs.org/octagonal-wheels/-/octagonal-wheels-0.1.42.tgz",
|
"resolved": "https://registry.npmjs.org/octagonal-wheels/-/octagonal-wheels-0.1.44.tgz",
|
||||||
"integrity": "sha512-Hc2GWCtmG4+OzY9flY5vHjozUPuwsQoY7osG+I2QzACs8iTWrlAcw1re8FgU4vDC/to9rFogWfYWI8bNbr5j2w==",
|
"integrity": "sha512-sUn/dkYQ2AbMB0R8CubVd75BjkcsteW9B14ArO99F6wM5JRwOo/yPIBBoxCUFE7JjBFOfuWG21C9E3NTga6XrA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"idb": "^8.0.3"
|
"idb": "^8.0.3"
|
||||||
@@ -10019,9 +10019,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/qrcode-generator": {
|
"node_modules/qrcode-generator": {
|
||||||
"version": "1.4.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-1.4.4.tgz",
|
"resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-2.0.4.tgz",
|
||||||
"integrity": "sha512-HM7yY8O2ilqhmULxGMpcHSF1EhJJ9yBj8gvDEuZ6M+KGJ0YY2hKpnXvRD+hZPLrDVck3ExIGhmPtSdcjC+guuw==",
|
"integrity": "sha512-mZSiP6RnbHl4xL2Ap5HfkjLnmxfKcPWpWe/c+5XxCuetEenqmNFf1FH/ftXPCtFG5/TDobjsjz6sSNL0Sr8Z9g==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/querystringify": {
|
"node_modules/querystringify": {
|
||||||
@@ -18353,9 +18353,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"octagonal-wheels": {
|
"octagonal-wheels": {
|
||||||
"version": "0.1.42",
|
"version": "0.1.44",
|
||||||
"resolved": "https://registry.npmjs.org/octagonal-wheels/-/octagonal-wheels-0.1.42.tgz",
|
"resolved": "https://registry.npmjs.org/octagonal-wheels/-/octagonal-wheels-0.1.44.tgz",
|
||||||
"integrity": "sha512-Hc2GWCtmG4+OzY9flY5vHjozUPuwsQoY7osG+I2QzACs8iTWrlAcw1re8FgU4vDC/to9rFogWfYWI8bNbr5j2w==",
|
"integrity": "sha512-sUn/dkYQ2AbMB0R8CubVd75BjkcsteW9B14ArO99F6wM5JRwOo/yPIBBoxCUFE7JjBFOfuWG21C9E3NTga6XrA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"idb": "^8.0.3"
|
"idb": "^8.0.3"
|
||||||
}
|
}
|
||||||
@@ -18967,9 +18967,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"qrcode-generator": {
|
"qrcode-generator": {
|
||||||
"version": "1.4.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-1.4.4.tgz",
|
"resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-2.0.4.tgz",
|
||||||
"integrity": "sha512-HM7yY8O2ilqhmULxGMpcHSF1EhJJ9yBj8gvDEuZ6M+KGJ0YY2hKpnXvRD+hZPLrDVck3ExIGhmPtSdcjC+guuw=="
|
"integrity": "sha512-mZSiP6RnbHl4xL2Ap5HfkjLnmxfKcPWpWe/c+5XxCuetEenqmNFf1FH/ftXPCtFG5/TDobjsjz6sSNL0Sr8Z9g=="
|
||||||
},
|
},
|
||||||
"querystringify": {
|
"querystringify": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
|
|||||||
@@ -94,8 +94,8 @@
|
|||||||
"fflate": "^0.8.2",
|
"fflate": "^0.8.2",
|
||||||
"idb": "^8.0.3",
|
"idb": "^8.0.3",
|
||||||
"minimatch": "^10.0.2",
|
"minimatch": "^10.0.2",
|
||||||
"octagonal-wheels": "^0.1.42",
|
"octagonal-wheels": "^0.1.44",
|
||||||
"qrcode-generator": "^1.4.4",
|
"qrcode-generator": "^2.0.4",
|
||||||
"trystero": "^0.22.0",
|
"trystero": "^0.22.0",
|
||||||
"xxhash-wasm-102": "npm:xxhash-wasm@^1.0.2"
|
"xxhash-wasm-102": "npm:xxhash-wasm@^1.0.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,5 +65,5 @@ export const ICHeaderLength = ICHeader.length;
|
|||||||
export const ICXHeader = "ix:";
|
export const ICXHeader = "ix:";
|
||||||
|
|
||||||
export const FileWatchEventQueueMax = 10;
|
export const FileWatchEventQueueMax = 10;
|
||||||
export const configURIBase = "obsidian://setuplivesync?settings=";
|
|
||||||
export const configURIBaseQR = "obsidian://setuplivesync?settingsQR=";
|
export { configURIBase, configURIBaseQR } from "../lib/src/common/types.ts";
|
||||||
|
|||||||
@@ -566,119 +566,3 @@ export function updatePreviousExecutionTime(key: string, timeDelta: number = 0)
|
|||||||
}
|
}
|
||||||
waitingTasks[key].leastNext = Math.max(Date.now() + timeDelta, waitingTasks[key].leastNext);
|
waitingTasks[key].leastNext = Math.max(Date.now() + timeDelta, waitingTasks[key].leastNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefixMapObject = {
|
|
||||||
s: {
|
|
||||||
1: "V",
|
|
||||||
2: "W",
|
|
||||||
3: "X",
|
|
||||||
4: "Y",
|
|
||||||
5: "Z",
|
|
||||||
},
|
|
||||||
o: {
|
|
||||||
1: "v",
|
|
||||||
2: "w",
|
|
||||||
3: "x",
|
|
||||||
4: "y",
|
|
||||||
5: "z",
|
|
||||||
},
|
|
||||||
} as Record<string, Record<number, string>>;
|
|
||||||
|
|
||||||
const decodePrefixMapObject = Object.fromEntries(
|
|
||||||
Object.entries(prefixMapObject).flatMap(([prefix, map]) =>
|
|
||||||
Object.entries(map).map(([len, char]) => [char, { prefix, len: parseInt(len) }])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const prefixMapNumber = {
|
|
||||||
n: {
|
|
||||||
1: "a",
|
|
||||||
2: "b",
|
|
||||||
3: "c",
|
|
||||||
4: "d",
|
|
||||||
5: "e",
|
|
||||||
},
|
|
||||||
N: {
|
|
||||||
1: "A",
|
|
||||||
2: "B",
|
|
||||||
3: "C",
|
|
||||||
4: "D",
|
|
||||||
5: "E",
|
|
||||||
},
|
|
||||||
} as Record<string, Record<number, string>>;
|
|
||||||
|
|
||||||
const decodePrefixMapNumber = Object.fromEntries(
|
|
||||||
Object.entries(prefixMapNumber).flatMap(([prefix, map]) =>
|
|
||||||
Object.entries(map).map(([len, char]) => [char, { prefix, len: parseInt(len) }])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
export function encodeAnyArray(obj: any[]): string {
|
|
||||||
const tempArray = obj.map((v) => {
|
|
||||||
if (v === null) return "n";
|
|
||||||
if (v === false) return "f";
|
|
||||||
if (v === true) return "t";
|
|
||||||
if (v === undefined) return "u";
|
|
||||||
if (typeof v == "number") {
|
|
||||||
const b36 = v.toString(36);
|
|
||||||
const strNum = v.toString();
|
|
||||||
const expression = b36.length < strNum.length ? "N" : "n";
|
|
||||||
const encodedStr = expression == "N" ? b36 : strNum;
|
|
||||||
const len = encodedStr.length.toString(36);
|
|
||||||
const lenLen = len.length;
|
|
||||||
|
|
||||||
const prefix2 = prefixMapNumber[expression][lenLen];
|
|
||||||
return prefix2 + len + encodedStr;
|
|
||||||
}
|
|
||||||
const str = typeof v == "string" ? v : JSON.stringify(v);
|
|
||||||
const prefix = typeof v == "string" ? "s" : "o";
|
|
||||||
const length = str.length.toString(36);
|
|
||||||
const lenLen = length.length;
|
|
||||||
|
|
||||||
const prefix2 = prefixMapObject[prefix][lenLen];
|
|
||||||
return prefix2 + length + str;
|
|
||||||
});
|
|
||||||
const w = tempArray.join("");
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
const decodeMapConstant = {
|
|
||||||
u: undefined,
|
|
||||||
n: null,
|
|
||||||
f: false,
|
|
||||||
t: true,
|
|
||||||
} as Record<string, any>;
|
|
||||||
export function decodeAnyArray(str: string): any[] {
|
|
||||||
const result = [];
|
|
||||||
let i = 0;
|
|
||||||
while (i < str.length) {
|
|
||||||
const char = str[i];
|
|
||||||
i++;
|
|
||||||
if (char in decodeMapConstant) {
|
|
||||||
result.push(decodeMapConstant[char]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (char in decodePrefixMapNumber) {
|
|
||||||
const { prefix, len } = decodePrefixMapNumber[char];
|
|
||||||
const lenStr = str.substring(i, i + len);
|
|
||||||
i += len;
|
|
||||||
const radix = prefix == "N" ? 36 : 10;
|
|
||||||
const lenNum = parseInt(lenStr, 36);
|
|
||||||
const value = str.substring(i, i + lenNum);
|
|
||||||
i += lenNum;
|
|
||||||
result.push(parseInt(value, radix));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const { prefix, len } = decodePrefixMapObject[char];
|
|
||||||
const lenStr = str.substring(i, i + len);
|
|
||||||
i += len;
|
|
||||||
const lenNum = parseInt(lenStr, 36);
|
|
||||||
const value = str.substring(i, i + lenNum);
|
|
||||||
i += lenNum;
|
|
||||||
if (prefix == "s") {
|
|
||||||
result.push(value);
|
|
||||||
} else {
|
|
||||||
result.push(JSON.parse(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|||||||
2
src/lib
2
src/lib
Submodule src/lib updated: 6617500bc5...b8fb5e5e63
@@ -77,6 +77,9 @@ export class ModuleSetupObsidian extends AbstractObsidianModule {
|
|||||||
async encodeQR() {
|
async encodeQR() {
|
||||||
const settingString = encodeSettingsToQRCodeData(this.settings);
|
const settingString = encodeSettingsToQRCodeData(this.settings);
|
||||||
const codeSVG = encodeQR(settingString, OutputFormat.SVG);
|
const codeSVG = encodeQR(settingString, OutputFormat.SVG);
|
||||||
|
if (codeSVG == "") {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
const msg = $msg("Setup.QRCode", { qr_image: codeSVG });
|
const msg = $msg("Setup.QRCode", { qr_image: codeSVG });
|
||||||
await this.core.confirm.confirmWithMessage("Settings QR Code", msg, ["OK"], "OK");
|
await this.core.confirm.confirmWithMessage("Settings QR Code", msg, ["OK"], "OK");
|
||||||
return await Promise.resolve(codeSVG);
|
return await Promise.resolve(codeSVG);
|
||||||
|
|||||||
@@ -243,6 +243,10 @@
|
|||||||
disabled={!isUseJWT}
|
disabled={!isUseJWT}
|
||||||
></textarea>
|
></textarea>
|
||||||
</InputRow>
|
</InputRow>
|
||||||
|
<InfoNote>
|
||||||
|
For HS256/HS512 algorithms, provide the shared secret key. For ES256/ES512 algorithms, provide the pkcs8
|
||||||
|
PEM-formatted private key.
|
||||||
|
</InfoNote>
|
||||||
<InputRow label="JWT Key ID (kid)">
|
<InputRow label="JWT Key ID (kid)">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
|||||||
Reference in New Issue
Block a user