Make Zotero script comment dynamic and assert valid JS
The generated script's setup comment hardcoded school.second-brain.ru even though baseUrl is already interpolated elsewhere in the template, so the comment would lie on any other host. Also add a regression test that the generated script parses as valid JavaScript, to catch escaping mistakes in the template literal.
This commit is contained in:
@@ -9,4 +9,9 @@ describe("buildZoteroScript", () => {
|
|||||||
expect(s).toContain("/api/pdf?url=");
|
expect(s).toContain("/api/pdf?url=");
|
||||||
expect(s).not.toContain("YOUR_KEY");
|
expect(s).not.toContain("YOUR_KEY");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("генерирует синтаксически валидный JS", () => {
|
||||||
|
const s = buildZoteroScript({ apiKey: "sbpdf_test123", baseUrl: "https://school.second-brain.ru" });
|
||||||
|
expect(() => new Function(s)).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Адаптация скрипта Clean PDF (pdf.brainysnipe.ru/zotero-script.js) под школу.
|
// Адаптация скрипта Clean PDF (pdf.brainysnipe.ru/zotero-script.js) под школу.
|
||||||
export function buildZoteroScript({ apiKey, baseUrl }: { apiKey: string; baseUrl: string }): string {
|
export function buildZoteroScript({ apiKey, baseUrl }: { apiKey: string; baseUrl: string }): string {
|
||||||
return `// ── Настройки ──────────────────────────────────────────────────────────────
|
return `// ── Настройки ──────────────────────────────────────────────────────────────
|
||||||
const API_KEY = '${apiKey}'; // персональный ключ из school.second-brain.ru/tools/clean-pdf
|
const API_KEY = '${apiKey}'; // персональный ключ из ${baseUrl}/tools/clean-pdf
|
||||||
const SERVICE_URL = '${baseUrl}';
|
const SERVICE_URL = '${baseUrl}';
|
||||||
const FORMAT = 'A4'; // 'A4' или 'Letter'
|
const FORMAT = 'A4'; // 'A4' или 'Letter'
|
||||||
const THEME = 'light'; // 'light' или 'dark'
|
const THEME = 'light'; // 'light' или 'dark'
|
||||||
|
|||||||
Reference in New Issue
Block a user