From 8570b2a204c79df3357c98c9fdf7130cbea0fb2f Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Sat, 10 May 2025 15:04:57 +0200 Subject: [PATCH 1/2] Use a tdoss directory in the data directory This is better because then I won't have a bunch of directories with random numbers directly in the data/ directory. Which makes it easier to clean up whenever something fails and the cleanup isn't done. --- commands/misc/tdoss.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/commands/misc/tdoss.js b/commands/misc/tdoss.js index 5c80e3a..56f4e55 100644 --- a/commands/misc/tdoss.js +++ b/commands/misc/tdoss.js @@ -10,9 +10,10 @@ module.exports = { description: 'Combine picture with tdoss album cover template', async execute({ message, args }) { - let dataDir = path.resolve(__dirname, '..', '..', 'data'); - const directory = path.resolve(dataDir, Math.floor(new Date).toString()) - fs.mkdirSync(directory) + let tdossDir = path.resolve(process.cwd, 'data', 'tdoss'); + + const directory = path.resolve(tdossDir, Math.floor(new Date).toString()) + fs.mkdirSync(directory, {recursive: true}) let url = ""; if(message.attachments.size > 0){ @@ -58,7 +59,7 @@ module.exports = { } - const command = `magick ${dataDir}/tdoss_template.png \\( ${directory}/input.png -resize 800x800^ -gravity center -extent 1000x1000 \\) -compose dst-over -composite ${directory}/tdoss_result.png`; + const command = `magick ${tdossDir}/tdoss_template.png \\( ${directory}/input.png -resize 800x800^ -gravity center -extent 1000x1000 \\) -compose dst-over -composite ${directory}/tdoss_result.png`; if (this.executeCommand(command).error === true) { message.channel.send("Something went wrong during image manipulation.\nTry again and if it keeps happening, contact the owner of the bot.") fs.rmSync(`${directory}`, {recursive: true}) From 6a0350f13ca9bdabbcf79d5b7d0c395e63851ea9 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Sat, 10 May 2025 15:09:53 +0200 Subject: [PATCH 2/2] Fix problem if content-type isn't provided by server --- commands/misc/tdoss.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/misc/tdoss.js b/commands/misc/tdoss.js index 56f4e55..09b5447 100644 --- a/commands/misc/tdoss.js +++ b/commands/misc/tdoss.js @@ -97,7 +97,8 @@ module.exports = { return {value: 3, errorMessage: error.cause.message}; } if(!res.ok) return {value: 1, errorMessage: res.status.toString()}; - if(!res.headers.get('content-type').startsWith("image")) return {value: 2, errorMessage: ""}; + const contentType = res.headers.get('content-type'); + if(!contentType || !contentType.startsWith("image")) return {value: 2, errorMessage: contentType || "No content-type header"}; const stream = Readable.fromWeb(res.body) await writeFile(path, stream); return {value: 0, errorMessage: ""};