@oebot/core
Version:
能跑就行的 QQ 机器人框架,基于 oicq v2,改自KiviBot(R.I.P.)
38 lines (37 loc) • 1.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadFileToDir = void 0;
const node_os_1 = __importDefault(require("node:os"));
const utils_1 = require("./utils");
const core_1 = require("../core");
async function uploadFileToDir(group, filepath, uploadFilename, dirname) {
try {
const isWin = node_os_1.default.platform() === 'win32';
const dir = dirname || String(this.uin);
const gfs = this.pickGroup(group).fs;
const filename = uploadFilename || filepath.split(isWin ? '\\' : '/').at(-1);
let isDirExist = false;
let pid = '/';
const ls = await gfs.ls();
ls.forEach((l) => {
if (l.name === dir && l.is_dir) {
isDirExist = true;
pid = l.fid;
}
});
if (!isDirExist) {
const state = await gfs.mkdir(dir);
pid = state.fid;
}
await gfs.upload(filepath, pid, filename);
return true;
}
catch (e) {
core_1.OELogger.error((0, utils_1.stringifyError)(e));
return true;
}
}
exports.uploadFileToDir = uploadFileToDir;