Skip to content

Commit

Permalink
style: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
yy4382 committed Feb 19, 2024
1 parent 9002984 commit 4002070
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 41 deletions.
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"trailingComma": "es5"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions src/PostHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`;
}
})
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down
34 changes: 18 additions & 16 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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<void> {
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))
Expand Down
24 changes: 14 additions & 10 deletions src/utils/Form2buffer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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 {
const multipartPieces: Array<string | Blob> = multipartPiecesFrom(formData);
return composeMultipartBodyFrom(multipartPieces, boundary);
}

function multipartPiecesFrom(formData: FormData): Array<string | Blob>{
function multipartPiecesFrom(formData: FormData): Array<string | Blob> {
const pieces: Array<string | Blob> = [];
formData.forEach((content, name) => {
if (typeof content === "string") {
Expand Down Expand Up @@ -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}--`;
Expand Down

0 comments on commit 4002070

Please sign in to comment.