Files
FastGPT/packages/service/common/file/utils.ts
Archer 6b7b03c245 4.7 doc update (#1068)
* 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>
2024-03-27 12:50:07 +08:00

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);
}
});
};