mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
check gif
This commit is contained in:
@@ -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) => {
|
||||
|
@@ -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'
|
||||
}
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user