mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00

* fix: plugin update * feat: get current time plugin * fix: ts * perf: select app ux * fix: ts * perf: max w * move code * perf: inform tip * fix: inform * doc * fix: tool handle * perf: tmp file store * doc * fix: message file selector * feat: doc * perf: switch trigger * doc * fix: openapi import * rount the number * parse openapi schema * fix empty line after variables (#64) * doc image * image size * doc * doc * catch error --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
45 lines
956 B
TypeScript
45 lines
956 B
TypeScript
import fs from 'fs';
|
|
|
|
export const removeFilesByPaths = (paths: string[]) => {
|
|
paths.forEach((path) => {
|
|
fs.unlink(path, (err) => {
|
|
if (err) {
|
|
// console.error(err);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
export const guessBase64ImageType = (str: string) => {
|
|
const imageTypeMap: Record<string, string> = {
|
|
'/': 'image/jpeg',
|
|
i: 'image/png',
|
|
R: 'image/gif',
|
|
U: 'image/webp',
|
|
Q: 'image/bmp'
|
|
};
|
|
|
|
const defaultType = 'image/jpeg';
|
|
if (typeof str !== 'string' || str.length === 0) {
|
|
return defaultType;
|
|
}
|
|
|
|
const firstChar = str.charAt(0);
|
|
return imageTypeMap[firstChar] || defaultType;
|
|
};
|
|
|
|
export const clearDirFiles = (dirPath: string) => {
|
|
if (!fs.existsSync(dirPath)) {
|
|
return;
|
|
}
|
|
|
|
fs.readdirSync(dirPath).forEach((file) => {
|
|
const curPath = `${dirPath}/${file}`;
|
|
if (fs.lstatSync(curPath).isDirectory()) {
|
|
clearDirFiles(curPath);
|
|
} else {
|
|
fs.unlinkSync(curPath);
|
|
}
|
|
});
|
|
};
|