forked from Open-Source-Bazaar/Open-Source-Bazaar.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[...slug].ts
More file actions
35 lines (27 loc) · 1.13 KB
/
[...slug].ts
File metadata and controls
35 lines (27 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Context } from 'koa';
import { LarkDocumentPathType } from 'mobx-lark';
import { createKoaRouter, withKoaRouter } from 'next-ssr-middleware';
import { safeAPI, verifyJWT } from '../../../core';
import { lark } from '../../core';
export const config = { api: { bodyParser: false } };
const router = createKoaRouter(import.meta.url);
router.post('/:type/:id', safeAPI, verifyJWT, async (context: Context) => {
const { type, id } = context.params,
{ name, parentToken, ownerType, ownerId } = Reflect.get(context.request, 'body');
const copiedFile =
type === 'wiki'
? await lark.copyFile(`${type as 'wiki'}/${id}`, name, parentToken)
: await lark.copyFile(`${type as LarkDocumentPathType}/${id}`, name, parentToken);
const newId = 'token' in copiedFile ? copiedFile.token : copiedFile.node_token;
if (ownerType && ownerId)
try {
await lark.driveFileStore.transferOwner(type, newId, {
member_type: ownerType,
member_id: ownerId,
});
} catch (error) {
console.error(JSON.stringify(error, null, 2));
}
context.body = copiedFile;
});
export default withKoaRouter(router);