check gif

This commit is contained in:
linyuchen
2024-01-20 08:38:14 +08:00
parent 600addbf82
commit 6d33fb8b14
3 changed files with 14 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ import {
} from "../common/IPCChannel";
import {ConfigUtil} from "./config";
import {startExpress} from "./HttpServer";
import {log} from "./utils";
import {isGIF, log} from "./utils";
import {friends, groups, selfInfo} from "./data";
const fs = require('fs');
@@ -55,7 +55,10 @@ function onLoad(plugin: any) {
let buffer = await blob.arrayBuffer();
fs.writeFileSync(arg.localFilePath, Buffer.from(buffer));
}
// todo: 需要识别gif格式
if (isGIF(arg.localFilePath)) {
fs.renameSync(arg.localFilePath, arg.localFilePath + ".gif");
arg.localFilePath += ".gif";
}
return arg.localFilePath;
})
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {

View File

@@ -5,4 +5,12 @@ export function log(msg: any) {
fs.appendFile("./llonebot.log", currentDateTime + ":" + msg + "\n", (err: any) => {
})
}
export function isGIF(path: string) {
const buffer = Buffer.alloc(4);
const fd = fs.openSync(path, 'r');
fs.readSync(fd, buffer, 0, 4, 0);
fs.closeSync(fd);
return buffer.toString() === 'GIF8'
}

View File

@@ -233,7 +233,6 @@ async function listenSendMessage(postData: PostDataSendMsg) {
let uri = new URL(url);
let ext: string;
if (message.type == "image") {
// todo: 需要识别gif格式
ext = ".png"
}
if (message.type == "voice") {
@@ -243,7 +242,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
if (uri.protocol == "file:") {
localFilePath = url.split("file://")[1]
} else {
await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
localFilePath = await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
}
message.file = localFilePath
sendFiles.push(localFilePath);