Skip to content

Commit

Permalink
feature: core 文件操作 getGroupFileInfo.js to #31
Browse files Browse the repository at this point in the history
  • Loading branch information
Drincann committed Apr 11, 2021
1 parent 0d725e0 commit 4ae00c4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
20 changes: 12 additions & 8 deletions dist/node/core/getGroupFileInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@ if (!process.browser) {

const errorHandler = require('../util/errorHandler');
/**
* @description 获取群列表
* @description 获取群文件详细信息
* @param {string} baseUrl mirai-api-http server 的地址
* @param {string} sessionKey 会话标识
* @param {string} group 群号
* @param {string} dir 可选,查询目录,默认为根目录
* @returns {Object[]} 结构 array[...{ id, name, path, isFile }]
* @param {number} target 群号
* @param {string} id 文件 id
* @returns {Object}
* 结构 {
* id, name, path, length, downloadTimes, uploaderId,
* uploadTime, lastModifyTime, downloadUrl, sha1, md5
* }
*/


module.exports = async ({
baseUrl,
sessionKey,
target,
dir
id
}) => {
try {
// 拼接 url
const url = new URL('/groupFileList', baseUrl).toString(); // 请求
const url = new URL('/groupFileInfo', baseUrl).toString(); // 请求

const responseData = await axios.get(url, {
params: {
sessionKey,
target,
dir
id
}
});

Expand All @@ -54,7 +58,7 @@ module.exports = async ({
}
} = responseData;
} catch (error) {
throw new Error('core.getGroupFileList 请求返回格式出错,请检查 mirai-console');
throw new Error('core.getGroupFileInfo 请求返回格式出错,请检查 mirai-console');
} // 抛出 mirai 的异常,到 catch 中处理后再抛出


Expand Down
44 changes: 44 additions & 0 deletions src/core/getGroupFileInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { errCodeMap } = require('../util/errCode');
const axios = require('axios').default;
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 {string} id 文件 id
* @returns {Object}
* 结构 {
* id, name, path, length, downloadTimes, uploaderId,
* uploadTime, lastModifyTime, downloadUrl, sha1, md5
* }
*/
module.exports = async ({ baseUrl, sessionKey, target, id }) => {
try {
// 拼接 url
const url = new URL('/groupFileInfo', baseUrl).toString();

// 请求
const responseData = await axios.get(url, { params: { sessionKey, target, id } });
try {
var { data, data: { msg: message, code } } = responseData;
} catch (error) {
throw new Error('core.getGroupFileInfo 请求返回格式出错,请检查 mirai-console');
}

// 抛出 mirai 的异常,到 catch 中处理后再抛出
if (code in errCodeMap) {
throw new Error(message);
}
return data;
} catch (error) {
errorHandler(error);
}
};

1 comment on commit 4ae00c4

@vercel
Copy link

@vercel vercel bot commented on 4ae00c4 Apr 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.