Fix linter/transpiler errors, formatting

This commit is contained in:
Râu Cao 2024-10-24 14:32:04 +02:00
parent fc711c2194
commit 0096f3cae3
Signed by: raucao
GPG Key ID: 37036C356E56CC51
6 changed files with 30 additions and 20 deletions

View File

@ -13,5 +13,10 @@
"@std/testing": "jsr:@std/testing@^1.0.3", "@std/testing": "jsr:@std/testing@^1.0.3",
"@std/yaml": "jsr:@std/yaml@^1.0.5", "@std/yaml": "jsr:@std/yaml@^1.0.5",
"ldapts": "npm:ldapts@^7.2.1" "ldapts": "npm:ldapts@^7.2.1"
},
"fmt": {
"exclude": [
"magick.ts"
]
} }
} }

View File

@ -34,7 +34,7 @@ const userEventHandler = async function (ctx: Context) {
} else { } else {
notFoundHandler(ctx); notFoundHandler(ctx);
} }
} catch (e) { } catch (_e) {
notFoundHandler(ctx); notFoundHandler(ctx);
} }
}; };

View File

@ -163,7 +163,7 @@ function openWithNostrAppHtml(bech32Id: string): string {
`; `;
} }
function feedLinksHtml(profile) { function feedLinksHtml(profile: Profile) {
return `<link rel="alternate" type="application/atom+xml" href="/@${profile.username}/articles.atom" title="Articles by ${profile.name}" />`; return `<link rel="alternate" type="application/atom+xml" href="/@${profile.username}/articles.atom" title="Articles by ${profile.name}" />`;
} }

View File

@ -5,8 +5,9 @@ import { log } from "./log.ts";
const tmpImgDir = "/tmp/substr/img"; const tmpImgDir = "/tmp/substr/img";
function createRoundedImage(profile: Profile) { function createRoundedImage(profile: Profile) {
const command = [ if (!profile.picture) return false;
'magick',
const args = [
profile.picture, profile.picture,
'-resize', '256x256', '-resize', '256x256',
'(', '+clone', '-alpha', 'extract', '(', '+clone', '-alpha', 'extract',
@ -20,15 +21,14 @@ function createRoundedImage(profile: Profile) {
`${tmpImgDir}/p-${profile.event.id}-rounded.png` `${tmpImgDir}/p-${profile.event.id}-rounded.png`
]; ];
return runCommand(command); return runCommand("magick", args);
} }
async function createOgImage(profile: Profile, ogImagePath: string, backgroundColor: string) { async function createOgImage(profile: Profile, ogImagePath: string, backgroundColor: string) {
const status = await createRoundedImage(profile); const status = await createRoundedImage(profile);
if (status.success) { if (status && status.success) {
const command = [ const args = [
'magick',
`${tmpImgDir}/p-${profile.event.id}-rounded.png`, `${tmpImgDir}/p-${profile.event.id}-rounded.png`,
'-resize', '256x256', '-resize', '256x256',
'-background', backgroundColor, '-background', backgroundColor,
@ -39,7 +39,7 @@ async function createOgImage(profile: Profile, ogImagePath: string, backgroundCo
ogImagePath ogImagePath
]; ];
return runCommand(command); return runCommand("magick", args);
} }
}; };
@ -52,7 +52,7 @@ export async function generateOgProfileImage(profile: Profile) {
if (!fileExists) { if (!fileExists) {
const status = await createOgImage(profile, ogImagePath, backgroundColor); const status = await createOgImage(profile, ogImagePath, backgroundColor);
if (status.success) { if (status && status.success) {
log(`Created OG image for ${profile.username}: ${ogImagePath}`, "blue") log(`Created OG image for ${profile.username}: ${ogImagePath}`, "blue")
} else { } else {
log(`Could not create OG image for ${profile.username}`, "yellow") log(`Could not create OG image for ${profile.username}`, "yellow")

View File

@ -28,7 +28,7 @@ export default class Article {
return tag ? tag[1] : "Untitled"; return tag ? tag[1] : "Untitled";
} }
get image(): string { get image(): string | undefined {
const tag = this.event.tags.find((t) => t[0] === "image"); const tag = this.event.tags.find((t) => t[0] === "image");
return tag ? tag[1] : undefined; return tag ? tag[1] : undefined;
} }

View File

@ -1,4 +1,4 @@
export async function checkIfFileExists(filePath: string): boolean { export async function checkIfFileExists(filePath: string): Promise<boolean> {
try { try {
await Deno.lstat(filePath); await Deno.lstat(filePath);
return true; return true;
@ -11,19 +11,24 @@ export async function checkIfFileExists(filePath: string): boolean {
} }
} }
export async function createSubtrTmpDirectories(): void { export async function createSubtrTmpDirectories(): Promise<void> {
const dirs = [ const dirs = [
"/tmp/substr/img/" "/tmp/substr/img/",
] ];
for (const path of dirs) { for (const path of dirs) {
await Deno.mkdir(path, { recursive: true }); await Deno.mkdir(path, { recursive: true });
} }
} }
export async function runCommand(command) { export async function runCommand(cmd: string, args: string[]) {
const process = Deno.run({ cmd: command }); const command = new Deno.Command(cmd, { args });
const status = await process.status(); const { code, stdout, stderr } = await command.output();
process.close();
return status; if (code === 1) {
console.log(new TextDecoder().decode(stdout));
console.log(new TextDecoder().decode(stderr));
}
return { success: code === 0, stdout, stderr };
} }