mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 21:27:47 +00:00
fix: 上传图片
This commit is contained in:
parent
64275de0e8
commit
436ecd1d5c
1 changed files with 8 additions and 8 deletions
|
|
@ -4,7 +4,7 @@ import { imageResourcesPath } from '../../lib/path.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
export async function uploadCharacterImg() {
|
export async function uploadCharacterImg() {
|
||||||
if (!this.e.isMaster) {
|
if (!this.e.isMaster) {
|
||||||
this.reply('只有主人才能添加...');
|
this.reply('只有主人才能添加');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const reg = /(上传|添加)(.+)(角色|面板)图$/;
|
const reg = /(上传|添加)(.+)(角色|面板)图$/;
|
||||||
|
|
@ -14,6 +14,10 @@ export async function uploadCharacterImg() {
|
||||||
}
|
}
|
||||||
const charName = match[2].trim();
|
const charName = match[2].trim();
|
||||||
const name = char.aliasToName(charName);
|
const name = char.aliasToName(charName);
|
||||||
|
if (!name) {
|
||||||
|
this.reply('未找到对应角色');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const images = [];
|
const images = [];
|
||||||
// 下面方法来源于miao-plugin/apps/character/ImgUpload.js
|
// 下面方法来源于miao-plugin/apps/character/ImgUpload.js
|
||||||
for (const val of this.e.message) {
|
for (const val of this.e.message) {
|
||||||
|
|
@ -63,7 +67,6 @@ export async function uploadCharacterImg() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug('images', images);
|
|
||||||
if (images.length <= 0) {
|
if (images.length <= 0) {
|
||||||
this.reply(
|
this.reply(
|
||||||
'消息中未找到图片,请将要发送的图片与消息一同发送或引用要添加的图像。'
|
'消息中未找到图片,请将要发送的图片与消息一同发送或引用要添加的图像。'
|
||||||
|
|
@ -77,12 +80,9 @@ export async function uploadCharacterImg() {
|
||||||
for (const image of images) {
|
for (const image of images) {
|
||||||
let fileName = new Date().getTime().toString();
|
let fileName = new Date().getTime().toString();
|
||||||
let fileType = 'png';
|
let fileType = 'png';
|
||||||
if (val.file) {
|
if (image.file) {
|
||||||
fileName = val.file.substring(0, val.file.lastIndexOf('.'));
|
fileName = image.file.substring(0, image.file.lastIndexOf('.'));
|
||||||
fileType = val.file.substring(val.file.lastIndexOf('.') + 1);
|
fileType = image.file.substring(image.file.lastIndexOf('.') + 1);
|
||||||
}
|
|
||||||
if (response.headers.get('content-type') === 'image/gif') {
|
|
||||||
fileType = 'gif';
|
|
||||||
}
|
}
|
||||||
const filePath = path.join(panelImagesPath, `${fileName}.${fileType}`);
|
const filePath = path.join(panelImagesPath, `${fileName}.${fileType}`);
|
||||||
const result = await downloadFile(image.url, filePath);
|
const result = await downloadFile(image.url, filePath);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue