Fixed GIF commands for real (lol)

This commit is contained in:
TheEssem 2020-10-19 20:24:53 -05:00
parent 5e34e45ac4
commit a03d3a5e79
9 changed files with 35 additions and 20 deletions

View File

@ -17,11 +17,12 @@ app.post("/run", express.json(), async (req, res, next) => {
try {
let type;
if (object.path) {
type = await magick.getType(object.path);
type = object.type ? object.type : await magick.getType(object.path);
if (!type) {
return res.sendStatus(400);
}
object.type = type.split("/")[1];
if (object.type !== "gif" && object.onlyGIF) return res.send("nogif");
const delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${object.path}`)).stdout.replace("\n", "");
object.delay = (100 / delay.split("/")[0]) * delay.split("/")[1];
}

View File

@ -4,12 +4,13 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to freeze!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
const { buffer, type } = await magick.run({
cmd: "freeze",
path: image.path,
loop: false
loop: false,
onlyGIF: true
});
if (buffer === "nogif") return `${message.author.mention}, that isn't a GIF!`;
return {
file: buffer,
name: `freeze.${type}`

View File

@ -4,12 +4,13 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to loop!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
const { buffer, type } = await magick.run({
cmd: "freeze",
path: image.path,
loop: true
loop: true,
onlyGIF: true
});
if (buffer === "nogif") return `${message.author.mention}, that isn't a GIF!`;
return {
file: buffer,
name: `loop.${type}`

View File

@ -4,15 +4,16 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to reverse!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
const { buffer, type } = await magick.run({
cmd: "reverse",
path: image.path,
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0,
onlyGIF: true
});
if (buffer === "nogif") return `${message.author.mention}, that isn't a GIF!`;
return {
file: buffer,
name: "reverse.gif"
name: `reverse.${type}`
};
};

View File

@ -1,19 +1,19 @@
const magick = require("../utils/image.js");
const { promisify } = require("util");
exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to slow down!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
const { buffer, type } = await magick.run({
cmd: "speed",
path: image.path,
slow: true
slow: true,
onlyGIF: true
});
if (buffer === "nogif") return `${message.author.mention}, that isn't a GIF!`;
return {
file: buffer,
name: "slow.gif"
name: `slow.${type}`
};
};

View File

@ -4,16 +4,17 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to loop!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
const { buffer, type } = await magick.run({
cmd: "reverse",
path: image.path,
soos: true,
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0
delay: image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0,
onlyGIF: true
});
if (buffer === "nogif") return `${message.author.mention}, that isn't a GIF!`;
return {
file: buffer,
name: "soos.gif"
name: `soos.${type}`
};
};

View File

@ -4,14 +4,15 @@ exports.run = async (message) => {
message.channel.sendTyping();
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide a GIF to speed up!`;
if (image.type !== "gif") return `${message.author.mention}, that isn't a GIF!`;
const { buffer, type } = await magick.run({
cmd: "speed",
path: image.path
path: image.path,
onlyGIF: true
});
if (buffer === "nogif") return `${message.author.mention}, that isn't a GIF!`;
return {
file: buffer,
name: "speed.gif"
name: `speed.${type}`
};
};

View File

@ -17,6 +17,11 @@ exports.run = async (object, fromAPI = false) => {
}
});
const buffer = await req.buffer();
console.log(buffer.toString());
if (buffer.toString() === "nogif") return {
buffer: "nogif",
type: null
};
return {
buffer: buffer,
type: req.headers.get("content-type").split("/")[1]
@ -24,7 +29,11 @@ exports.run = async (object, fromAPI = false) => {
} else {
let type;
if (!fromAPI && object.path) {
type = (await this.getType(object.path)).split("/")[1];
type = (object.type ? object.type : await this.getType(object.path)).split("/")[1];
if (type !== "gif" && object.onlyGIF) return {
buffer: "nogif",
type: null
};
object.type = type;
const delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${object.path}`)).stdout.replace("\n", "");
object.delay = (100 / delay.split("/")[0]) * delay.split("/")[1];

View File

@ -17,7 +17,7 @@ const getImage = async (image, image2, gifv = false) => {
} else if (image2.includes("imgur.com")) {
payload.path = image.replace(".mp4", ".gif");
}
payload.type = "gif";
payload.type = "image/gif";
}
return payload;
} catch (error) {