zhaoyingbo 490c6ea3e5
All checks were successful
Egg CI/CD / build-image (push) Successful in 29s
Egg CI/CD / deploy (push) Successful in 21s
feat: 优化app数据的存储方式
2024-07-10 11:26:56 +00:00

56 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;