Fix linter/transpiler errors, formatting
This commit is contained in:
parent
fc711c2194
commit
0096f3cae3
@ -13,5 +13,10 @@
|
||||
"@std/testing": "jsr:@std/testing@^1.0.3",
|
||||
"@std/yaml": "jsr:@std/yaml@^1.0.5",
|
||||
"ldapts": "npm:ldapts@^7.2.1"
|
||||
},
|
||||
"fmt": {
|
||||
"exclude": [
|
||||
"magick.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ const userEventHandler = async function (ctx: Context) {
|
||||
} else {
|
||||
notFoundHandler(ctx);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
notFoundHandler(ctx);
|
||||
}
|
||||
};
|
||||
|
2
html.ts
2
html.ts
@ -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}" />`;
|
||||
}
|
||||
|
||||
|
16
magick.ts
16
magick.ts
@ -5,8 +5,9 @@ import { log } from "./log.ts";
|
||||
const tmpImgDir = "/tmp/substr/img";
|
||||
|
||||
function createRoundedImage(profile: Profile) {
|
||||
const command = [
|
||||
'magick',
|
||||
if (!profile.picture) return false;
|
||||
|
||||
const args = [
|
||||
profile.picture,
|
||||
'-resize', '256x256',
|
||||
'(', '+clone', '-alpha', 'extract',
|
||||
@ -20,15 +21,14 @@ function createRoundedImage(profile: Profile) {
|
||||
`${tmpImgDir}/p-${profile.event.id}-rounded.png`
|
||||
];
|
||||
|
||||
return runCommand(command);
|
||||
return runCommand("magick", args);
|
||||
}
|
||||
|
||||
async function createOgImage(profile: Profile, ogImagePath: string, backgroundColor: string) {
|
||||
const status = await createRoundedImage(profile);
|
||||
|
||||
if (status.success) {
|
||||
const command = [
|
||||
'magick',
|
||||
if (status && status.success) {
|
||||
const args = [
|
||||
`${tmpImgDir}/p-${profile.event.id}-rounded.png`,
|
||||
'-resize', '256x256',
|
||||
'-background', backgroundColor,
|
||||
@ -39,7 +39,7 @@ async function createOgImage(profile: Profile, ogImagePath: string, backgroundCo
|
||||
ogImagePath
|
||||
];
|
||||
|
||||
return runCommand(command);
|
||||
return runCommand("magick", args);
|
||||
}
|
||||
};
|
||||
|
||||
@ -52,7 +52,7 @@ export async function generateOgProfileImage(profile: Profile) {
|
||||
|
||||
if (!fileExists) {
|
||||
const status = await createOgImage(profile, ogImagePath, backgroundColor);
|
||||
if (status.success) {
|
||||
if (status && status.success) {
|
||||
log(`Created OG image for ${profile.username}: ${ogImagePath}`, "blue")
|
||||
} else {
|
||||
log(`Could not create OG image for ${profile.username}`, "yellow")
|
||||
|
@ -28,7 +28,7 @@ export default class Article {
|
||||
return tag ? tag[1] : "Untitled";
|
||||
}
|
||||
|
||||
get image(): string {
|
||||
get image(): string | undefined {
|
||||
const tag = this.event.tags.find((t) => t[0] === "image");
|
||||
return tag ? tag[1] : undefined;
|
||||
}
|
||||
|
23
utils.ts
23
utils.ts
@ -1,4 +1,4 @@
|
||||
export async function checkIfFileExists(filePath: string): boolean {
|
||||
export async function checkIfFileExists(filePath: string): Promise<boolean> {
|
||||
try {
|
||||
await Deno.lstat(filePath);
|
||||
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 = [
|
||||
"/tmp/substr/img/"
|
||||
]
|
||||
"/tmp/substr/img/",
|
||||
];
|
||||
|
||||
for (const path of dirs) {
|
||||
await Deno.mkdir(path, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
export async function runCommand(command) {
|
||||
const process = Deno.run({ cmd: command });
|
||||
const status = await process.status();
|
||||
process.close();
|
||||
return status;
|
||||
export async function runCommand(cmd: string, args: string[]) {
|
||||
const command = new Deno.Command(cmd, { args });
|
||||
const { code, stdout, stderr } = await command.output();
|
||||
|
||||
if (code === 1) {
|
||||
console.log(new TextDecoder().decode(stdout));
|
||||
console.log(new TextDecoder().decode(stderr));
|
||||
}
|
||||
|
||||
return { success: code === 0, stdout, stderr };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user