Skip to content

Commit

Permalink
feature: core 文件操作 groupFileRename.js to #31
Browse files Browse the repository at this point in the history
  • Loading branch information
Drincann committed Apr 12, 2021
1 parent be823c7 commit 995d48b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/core/groupFileRename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { errCodeMap } = require('../util/errCode');
const axios = require('axios');
let URL;
if (!process.browser) {
({ URL } = require('url'));
} else {
URL = window.URL;
}
const errorHandler = require('../util/errorHandler');

/**
* @description 重命名群文件
* @param {string} baseUrl mirai-api-http server 的地址
* @param {string} sessionKey 会话标识
* @param {number} target 群号
* @param {number} id 文件 id
* @param {string} rename 重命名
* @returns {Object} 结构 { message, code }
*/
module.exports = async ({ baseUrl, sessionKey, target, id, rename }) => {
try {
// 拼接 url
const url = new URL('/groupFileRename', baseUrl).toString();

// 请求
const responseData = await axios.post(url, {
sessionKey, target, id, rename
});

try {
var {
data: { msg: message, code }
} = responseData;
} catch (error) {
throw new Error('core.groupFileRename 请求返回格式出错,请检查 mirai-console');
}
// 抛出 mirai 的异常,到 catch 中处理后再抛出
if (code in errCodeMap) {
throw new Error(message);
}
return { message, code };
} catch (error) {
errorHandler(error);
}
};

0 comments on commit 995d48b

Please sign in to comment.