From 7bf706b121f8b41f6b52c7b9d8ca345f4d063be9 Mon Sep 17 00:00:00 2001 From: novov Date: Tue, 24 Oct 2023 11:47:53 +1300 Subject: [PATCH] Address PR feedback --- package.json | 1 + src/formats/apple-notes.ts | 7 ++--- .../apple-notes/sqlite/static-params.js | 31 ------------------- src/formats/apple-notes/sqlite/utils.js | 2 +- 4 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 src/formats/apple-notes/sqlite/static-params.js diff --git a/package.json b/package.json index 87275037..485fe4e1 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "joplin-turndown-plugin-gfm": "1.0.12", "plain-tag": "0.1.3", "protobufjs": "7.2.5", + "static-params": "0.4.0", "xml-flow": "1.0.4" } } diff --git a/src/formats/apple-notes.ts b/src/formats/apple-notes.ts index b7b024f5..2c76f6bc 100644 --- a/src/formats/apple-notes.ts +++ b/src/formats/apple-notes.ts @@ -350,10 +350,9 @@ export class AppleNotesImporter extends FormatImporter { try { const binary = await this.getAttachmentSource(this.resolvedAccounts[this.owners[row.ZNOTE]], sourcePath); + const attachmentFolder = await this.getAttachmentFolder(this.resolvedFiles[row.ZNOTE]); //@ts-ignore - const outPath = this.app.vault.getAvailablePath( - `${await this.getAttachmentPath(this.resolvedFiles[row.ZNOTE])}/${outName}`, outExt - ); + const outPath = this.app.vault.getAvailablePath(`${attachmentFolder}/${outName}`, outExt); file = await this.vault.createBinary( outPath, binary, @@ -390,7 +389,7 @@ export class AppleNotesImporter extends FormatImporter { } } - async getAttachmentPath(note: TFile): Promise { + async getAttachmentFolder(note: TFile): Promise { if (this.cachedAttachmentPath) return this.cachedAttachmentPath; let attachmentSetting = this.app.vault.getConfig('attachmentFolderPath'); diff --git a/src/formats/apple-notes/sqlite/static-params.js b/src/formats/apple-notes/sqlite/static-params.js deleted file mode 100644 index 85168d05..00000000 --- a/src/formats/apple-notes/sqlite/static-params.js +++ /dev/null @@ -1,31 +0,0 @@ -class Static extends String {} - -export const asParams = (template, ...values) => { - const t = [template[0]]; - const v = [t]; - - for (let i = 0; i < values.length; i++) { - if (values[i] instanceof Static) { - t[t.length - 1] += values[i] + template[i + 1]; - } - else { - if (Array.isArray(values[i])) { - t.push(...values[i].slice(1).map(_ => ',')); - - v.push(...values[i]); - if (values[i].length == 0) v.push(''); - } - else v.push(values[i]); - - t.push(template[i + 1]); - } - } - - return v; -}; - -export const asStatic = _ => new Static(_); - -export const asTag = fn => function() { - return fn.apply(this, asParams.apply(null, arguments)); -}; diff --git a/src/formats/apple-notes/sqlite/utils.js b/src/formats/apple-notes/sqlite/utils.js index 34af53fe..47c3ba63 100644 --- a/src/formats/apple-notes/sqlite/utils.js +++ b/src/formats/apple-notes/sqlite/utils.js @@ -1,5 +1,5 @@ import plain from 'plain-tag'; -import { asStatic, asParams } from './static-params'; +import { asStatic, asParams } from './static-params/sql'; export const error = (rej, reason) => { const code = 'SQLITE_ERROR';