fix: SendGroupNotice Image Unlink

This commit is contained in:
手瓜一十雪 2024-05-12 15:49:53 +08:00
parent 5c3442a71f
commit a6c056a894

View File

@ -2,6 +2,7 @@ import { checkFileReceived, uri2local } from '@/common/utils/file';
import BaseAction from '../BaseAction'; import BaseAction from '../BaseAction';
import { ActionName } from '../types'; import { ActionName } from '../types';
import { NTQQGroupApi, WebApi } from '@/core/apis'; import { NTQQGroupApi, WebApi } from '@/core/apis';
import { unlink } from 'node:fs';
interface Payload { interface Payload {
group_id: string; group_id: string;
content: string; content: string;
@ -16,7 +17,7 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
let UploadImage: { id: string, width: number, height: number } | undefined = undefined; let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
if (payload.image) { if (payload.image) {
//公告图逻辑 //公告图逻辑
let Image_path, Image_IsLocal, Image_errMsg; let Image_path, Image_errMsg, Image_IsLocal = false;
let Uri2LocalRet = (await uri2local(payload.image)); let Uri2LocalRet = (await uri2local(payload.image));
Image_errMsg = Uri2LocalRet.errMsg; Image_errMsg = Uri2LocalRet.errMsg;
Image_path = Uri2LocalRet.path; Image_path = Uri2LocalRet.path;
@ -32,6 +33,9 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
if (ImageUploadResult.errCode != 0) { if (ImageUploadResult.errCode != 0) {
throw `群公告${payload.image}设置失败,图片上传失败`; throw `群公告${payload.image}设置失败,图片上传失败`;
} }
if (!Image_IsLocal) {
unlink(Image_path, () => { });
}
UploadImage = ImageUploadResult.picInfo; UploadImage = ImageUploadResult.picInfo;
} }
let Notice_Pinned = 0; let Notice_Pinned = 0;