diff --git a/deno.json b/deno.json
index 44c61f2..c8fb0e1 100644
--- a/deno.json
+++ b/deno.json
@@ -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"
+ ]
}
}
diff --git a/handlers/user-event.ts b/handlers/user-event.ts
index 7337be9..ed0dbc2 100644
--- a/handlers/user-event.ts
+++ b/handlers/user-event.ts
@@ -34,7 +34,7 @@ const userEventHandler = async function (ctx: Context) {
} else {
notFoundHandler(ctx);
}
- } catch (e) {
+ } catch (_e) {
notFoundHandler(ctx);
}
};
diff --git a/html.ts b/html.ts
index b42738e..65ab62f 100644
--- a/html.ts
+++ b/html.ts
@@ -163,7 +163,7 @@ function openWithNostrAppHtml(bech32Id: string): string {
`;
}
-function feedLinksHtml(profile) {
+function feedLinksHtml(profile: Profile) {
return ``;
}
diff --git a/magick.ts b/magick.ts
index 9d58962..1daa1f2 100644
--- a/magick.ts
+++ b/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")
diff --git a/models/article.ts b/models/article.ts
index 9cc925f..1a4bdd3 100644
--- a/models/article.ts
+++ b/models/article.ts
@@ -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;
}
diff --git a/utils.ts b/utils.ts
index 459c08c..a407d29 100644
--- a/utils.ts
+++ b/utils.ts
@@ -1,4 +1,4 @@
-export async function checkIfFileExists(filePath: string): boolean {
+export async function checkIfFileExists(filePath: string): Promise {
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 {
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 };
}