56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { LarkServer } from "../../types"
|
||
import larkNetTool from "./larkNetTool"
|
||
|
||
const batchGetMeta =
|
||
(appName?: string) =>
|
||
async (docTokens: string[], doc_type = "doc", user_id_type = "user_id") => {
|
||
const URL =
|
||
"https://open.f.mioffice.cn/open-apis/drive/v1/metas/batch_query"
|
||
// 如果docTokens长度超出150,需要分批请求
|
||
const docTokensLen = docTokens.length
|
||
const maxLen = 150
|
||
const requestMap = Array.from(
|
||
{ length: Math.ceil(docTokensLen / maxLen) },
|
||
(_, index) => {
|
||
const start = index * maxLen
|
||
const docTokensSlice = docTokens.slice(start, start + maxLen)
|
||
const data = {
|
||
request_docs: docTokensSlice.map((id) => ({
|
||
doc_token: id,
|
||
doc_type,
|
||
})),
|
||
}
|
||
return larkNetTool.post(appName)<LarkServer.BatchDocMetaRes>(
|
||
URL,
|
||
data,
|
||
{
|
||
user_id_type,
|
||
}
|
||
)
|
||
}
|
||
)
|
||
const responses = await Promise.all(requestMap)
|
||
const metas = responses.flatMap((res) => {
|
||
return res.data?.metas || []
|
||
})
|
||
|
||
const failed_list = responses.flatMap((res) => {
|
||
return res.data?.failed_list || []
|
||
})
|
||
|
||
return {
|
||
code: 0,
|
||
data: {
|
||
metas,
|
||
failed_list,
|
||
},
|
||
msg: "success",
|
||
}
|
||
}
|
||
|
||
const drive = {
|
||
batchGetMeta,
|
||
}
|
||
|
||
export default drive
|