-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: core 文件操作 groupFileDelete.js to #31
- Loading branch information
Showing
5 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use strict"; | ||
|
||
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 | ||
* @returns {Object} 结构 { message, code } | ||
*/ | ||
|
||
|
||
module.exports = async ({ | ||
baseUrl, | ||
sessionKey, | ||
target, | ||
id | ||
}) => { | ||
try { | ||
// 拼接 url | ||
const url = new URL('/groupFileDelete', baseUrl).toString(); // 请求 | ||
|
||
const responseData = await axios.post(url, { | ||
sessionKey, | ||
target, | ||
id | ||
}); | ||
|
||
try { | ||
var { | ||
data: { | ||
msg: message, | ||
code | ||
} | ||
} = responseData; | ||
} catch (error) { | ||
throw new Error('core.groupFileDelete 请求返回格式出错,请检查 mirai-console'); | ||
} // 抛出 mirai 的异常,到 catch 中处理后再抛出 | ||
|
||
|
||
if (code in errCodeMap) { | ||
throw new Error(message); | ||
} | ||
|
||
return { | ||
message, | ||
code | ||
}; | ||
} catch (error) { | ||
errorHandler(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use strict"; | ||
|
||
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} movePath 目标 path | ||
* @returns {Object} 结构 { message, code } | ||
*/ | ||
|
||
|
||
module.exports = async ({ | ||
baseUrl, | ||
sessionKey, | ||
target, | ||
id, | ||
movePath | ||
}) => { | ||
try { | ||
// 拼接 url | ||
const url = new URL('/groupFileMove', baseUrl).toString(); // 请求 | ||
|
||
const responseData = await axios.post(url, { | ||
sessionKey, | ||
target, | ||
id, | ||
movePath | ||
}); | ||
|
||
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use strict"; | ||
|
||
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 {string} target 消息 id | ||
* @returns {Object} 结构 { message, code } | ||
*/ | ||
|
||
|
||
module.exports = async ({ | ||
baseUrl, | ||
sessionKey, | ||
target | ||
}) => { | ||
try { | ||
// 拼接 url | ||
const url = new URL('/groupConfig', baseUrl).toString(); // 请求 | ||
|
||
const responseData = await axios.post(url, { | ||
sessionKey, | ||
target | ||
}); | ||
|
||
try { | ||
var { | ||
data: { | ||
msg: message, | ||
code | ||
} | ||
} = responseData; | ||
} catch (error) { | ||
throw new Error('core.setEssence 请求返回格式出错,请检查 mirai-console'); | ||
} // 抛出 mirai 的异常,到 catch 中处理后再抛出 | ||
|
||
|
||
if (code in errCodeMap) { | ||
throw new Error(message); | ||
} | ||
|
||
return { | ||
message, | ||
code | ||
}; | ||
} catch (error) { | ||
errorHandler(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
* @returns {Object} 结构 { message, code } | ||
*/ | ||
module.exports = async ({ baseUrl, sessionKey, target, id }) => { | ||
try { | ||
// 拼接 url | ||
const url = new URL('/groupFileDelete', baseUrl).toString(); | ||
|
||
// 请求 | ||
const responseData = await axios.post(url, { | ||
sessionKey, target, id | ||
}); | ||
|
||
try { | ||
var { | ||
data: { msg: message, code } | ||
} = responseData; | ||
} catch (error) { | ||
throw new Error('core.groupFileDelete 请求返回格式出错,请检查 mirai-console'); | ||
} | ||
// 抛出 mirai 的异常,到 catch 中处理后再抛出 | ||
if (code in errCodeMap) { | ||
throw new Error(message); | ||
} | ||
return { message, code }; | ||
} catch (error) { | ||
errorHandler(error); | ||
} | ||
|
||
}; |