diff --git a/.prettierrc b/.prettierrc index 9e26dfe..c4be887 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1 +1,3 @@ -{} \ No newline at end of file +{ + "trailingComma": "es5" +} \ No newline at end of file diff --git a/package.json b/package.json index a2c2cd7..bad8c0d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "esbuild": "0.17.3", "eslint": "^8.56.0", "obsidian": "latest", + "prettier": "^3.2.5", "tslib": "2.4.0", "typescript": "4.7.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d97608..18e27d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,6 +43,9 @@ devDependencies: obsidian: specifier: latest version: 1.4.11(@codemirror/state@6.4.0)(@codemirror/view@6.24.0) + prettier: + specifier: ^3.2.5 + version: 3.2.5 tslib: specifier: 2.4.0 version: 2.4.0 @@ -2362,6 +2365,12 @@ packages: engines: {node: '>= 0.8.0'} dev: true + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true + dev: true + /punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} diff --git a/src/PostHandle.ts b/src/PostHandle.ts index 80bdb4e..a37ac0c 100644 --- a/src/PostHandle.ts +++ b/src/PostHandle.ts @@ -109,8 +109,8 @@ export default class PostHandler { const linkTitle = matches[3] ? matches[3] : matches[2] - ? linkFrontmatter.title + "#" + matches[2] - : linkFrontmatter.title; + ? linkFrontmatter.title + "#" + matches[2] + : linkFrontmatter.title; return `[${linkTitle}](/${this.settings.post_prefix}${slug})`; } }) @@ -138,14 +138,15 @@ export default class PostHandler { } }); return ( - `---\n` + YAML.stringify(post.frontmatter) + `---\n\n` + article.trim() + `\n` + `---\n` + + YAML.stringify(post.frontmatter) + + `---\n\n` + + article.trim() + + `\n` ); } - private modifyImageLinks( - file: TFile, - replaced_article: string - ): void{ + private modifyImageLinks(file: TFile, replaced_article: string): void { this.vault.modify(file, replaced_article); } @@ -166,9 +167,7 @@ export default class PostHandler { return frontmatter; } - private findNote( - link: string - ): Post | TFile | null | undefined { + private findNote(link: string): Post | TFile | null | undefined { for (const post of this.postsOb) { if (post.tFile.basename === link) return post; } diff --git a/src/Settings.ts b/src/Settings.ts index e6baeb5..6e591d4 100644 --- a/src/Settings.ts +++ b/src/Settings.ts @@ -306,22 +306,24 @@ export class Ob2StaticSettingTab extends PluginSettingTab { toggle.setValue(settings.build.enable).onChange(async (value) => { settings.build.enable = value; await this.plugin.saveSettings(); - if (settings.build.enable){ - this.plugin.addRibbonIcon( - "play-square", - "Trigger GitHub Action deploy", - (evt: MouseEvent) => { - // Called when the user clicks the icon. - triggerGitHubDispatchEvent( - this.settings.build.webhook_token, - this.settings.build.user, - this.settings.build.repo, - this.settings.build.event_type - ); - new Notice("Sent GitHub Action deploy Webhook"); - } - ).setAttribute("id","rb-sse-deploy-icon"); - } else{ + if (settings.build.enable) { + this.plugin + .addRibbonIcon( + "play-square", + "Trigger GitHub Action deploy", + (evt: MouseEvent) => { + // Called when the user clicks the icon. + triggerGitHubDispatchEvent( + this.settings.build.webhook_token, + this.settings.build.user, + this.settings.build.repo, + this.settings.build.event_type + ); + new Notice("Sent GitHub Action deploy Webhook"); + } + ) + .setAttribute("id", "rb-sse-deploy-icon"); + } else { document.getElementById("rb-sse-deploy-icon")?.remove(); } this.display(); diff --git a/src/Upload.ts b/src/Upload.ts index 6afdf50..973f326 100644 --- a/src/Upload.ts +++ b/src/Upload.ts @@ -104,7 +104,7 @@ export default class Uploader { // HTTP status code is not in the 2xx range, indicating an error console.error( "HTTP status code is not in the 2xx range, but " + - data.$metadata.httpStatusCode, + data.$metadata.httpStatusCode ); new Notice("Error while uploading post"); throw new Error("Error while uploading post"); diff --git a/src/main.ts b/src/main.ts index 8cb9702..49c7633 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,9 +50,9 @@ export default class Ob2StaticPlugin extends Plugin { ); new Notice("Sent GitHub Action deploy Webhook"); } - ).setAttribute("id","rb-sse-deploy-icon"); + ).setAttribute("id", "rb-sse-deploy-icon"); - if (!this.settings.build.enable){ + if (!this.settings.build.enable) { document.getElementById("rb-sse-deploy-icon")?.remove(); } @@ -66,7 +66,7 @@ export default class Ob2StaticPlugin extends Plugin { * Processes the notes and uploads them to the specified S3 bucket. */ async process(tFiles: TFile[]): Promise { - const uploader = new Uploader(this.app,this.settings); + const uploader = new Uploader(this.app, this.settings); const validRe = await Promise.all( tFiles.map((post) => this.ValidatePost(post)) diff --git a/src/utils/Form2buffer.ts b/src/utils/Form2buffer.ts index 1757d01..aeb7084 100644 --- a/src/utils/Form2buffer.ts +++ b/src/utils/Form2buffer.ts @@ -1,11 +1,12 @@ +export default async function form2buffer( + requestData: FormData +): Promise<{ contentType: string; body: ArrayBuffer }> { + const boundary = `----formdata-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, "0")}`; -export default async function form2buffer(requestData: FormData): Promise<{ contentType: string; body: ArrayBuffer }>{ - const boundary = `----formdata-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}` - - return { - contentType: `multipart/form-data; boundary=${boundary}`, - body: await buildMultipartBody(requestData, boundary).arrayBuffer(), - } + return { + contentType: `multipart/form-data; boundary=${boundary}`, + body: await buildMultipartBody(requestData, boundary).arrayBuffer(), + }; } function buildMultipartBody(formData: FormData, boundary: string): Blob { @@ -13,7 +14,7 @@ function buildMultipartBody(formData: FormData, boundary: string): Blob { return composeMultipartBodyFrom(multipartPieces, boundary); } -function multipartPiecesFrom(formData: FormData): Array{ +function multipartPiecesFrom(formData: FormData): Array { const pieces: Array = []; formData.forEach((content, name) => { if (typeof content === "string") { @@ -43,13 +44,16 @@ function fileToFormDataSection(formName: string, file: File): Blob { function composeMultipartBodyFrom( multipartPieces: (string | Blob)[], boundaryLine: string -):Blob { +): Blob { const allPieces = addMultipartBoundaries(multipartPieces, boundaryLine); const singleBlob = new Blob(addLineBreaks(allPieces)); return singleBlob; } -function addMultipartBoundaries(multipartPieces: BlobPart[], boundary: string): BlobPart[]{ +function addMultipartBoundaries( + multipartPieces: BlobPart[], + boundary: string +): BlobPart[] { const boundaryLine = `--${boundary}`; const allPieces = multipartPieces.flatMap((p) => [boundaryLine, p]); const finalBoundaryLine = `--${boundary}--`;