Skip to content

Commit 167e079

Browse files
committed
[fix] Path & Type converting of Lark documents
1 parent 5faa637 commit 167e079

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx-lark",
3-
"version": "2.6.0",
3+
"version": "2.6.1",
44
"license": "LGPL-3.0",
55
"author": "shiy2008@gmail.com",
66
"description": "Unofficial TypeScript SDK for FeiShu/Lark API, which is based on MobX-RESTful.",

src/Lark.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import {
1010
WikiNodeModel
1111
} from './module';
1212
import {
13+
getLarkDocumentType,
1314
isLarkError,
1415
JSTicket,
1516
LarkData,
17+
LarkDocumentPathType,
1618
LarkDocumentType,
1719
TenantAccessToken,
1820
UploadTargetType,
@@ -204,7 +206,7 @@ export class LarkApp implements LarkAppOption {
204206
user_id_type?: UserIdType
205207
): Promise<WikiNode>;
206208
copyFile(
207-
URI: `${string}${LarkDocumentType}/${string}`,
209+
URI: `${string}${LarkDocumentPathType}/${string}`,
208210
name?: string,
209211
folder_token?: string,
210212
user_id_type?: UserIdType
@@ -223,6 +225,9 @@ export class LarkApp implements LarkAppOption {
223225
space_id,
224226
parent_node_token
225227
} = await this.wiki2drive(token));
228+
else {
229+
type = getLarkDocumentType(type as LarkDocumentPathType);
230+
}
226231

227232
const copidFile = await this.driveFileStore.copyOne(
228233
type as LarkDocumentType,

src/module/Drive/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { makeFormData } from 'koajax';
22
import { BaseListModel, RESTClient, toggle } from 'mobx-restful';
33
import { buildURLData, splitArray } from 'web-utility';
44

5-
import { LarkData, LarkDocumentType, UploadTargetType } from '../../type';
5+
import { LarkData, LarkDocumentPathTypeMap, LarkDocumentType, UploadTargetType } from '../../type';
66
import { UserIdType } from '../User/type';
77
import { CopiedFile, DriveFile } from './type';
88

@@ -94,7 +94,9 @@ export abstract class DriveFileModel extends BaseListModel<DriveFile> {
9494
folder_token?: string,
9595
user_id_type?: UserIdType
9696
) {
97-
name ||= (await this.getOne(`${type}/${file_token}`, user_id_type)).title + ' (copy)';
97+
name ||=
98+
(await this.getOne(`${LarkDocumentPathTypeMap[type]}/${file_token}`, user_id_type))
99+
.title + ' (copy)';
98100
folder_token ||= (await this.getRootFolder()).token;
99101

100102
const { body } = await this.client.post<LarkData<{ file: CopiedFile }>>(

src/type.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ export type LarkDocumentType =
6060
| 'slides'
6161
| 'file';
6262

63+
export type LarkDocumentPathType =
64+
| `doc${'' | 'x'}`
65+
| 'mindnote'
66+
| 'sheets'
67+
| 'base'
68+
| 'slides'
69+
| 'file';
70+
71+
export const LarkDocumentPathTypeMap: Record<LarkDocumentType, LarkDocumentPathType> = {
72+
doc: 'doc',
73+
docx: 'docx',
74+
mindnote: 'mindnote',
75+
sheet: 'sheets',
76+
bitable: 'base',
77+
slides: 'slides',
78+
file: 'file'
79+
};
80+
81+
export const getLarkDocumentType = (path: LarkDocumentPathType) =>
82+
Object.entries(LarkDocumentPathTypeMap).find(([, p]) => p === path)![0] as LarkDocumentType;
83+
6384
export type UploadTargetType =
6485
| 'doc_image'
6586
| 'docx_image'

0 commit comments

Comments
 (0)