Skip to content

Commit 33c238c

Browse files
committed
[fix] some URI bugs
1 parent 6fd996b commit 33c238c

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ on:
33
push:
44
tags:
55
- v*
6+
env:
7+
PUBLISH_TAG: ${{ contains(github.ref_name, '-') && 'next' || 'latest' }}
8+
69
jobs:
710
Test-Build-Publish-Deploy:
811
runs-on: ubuntu-latest
@@ -28,11 +31,12 @@ jobs:
2831
cat > .env <<EOF
2932
${{ secrets.ENV_FILE }}
3033
EOF
31-
npm publish --access public --provenance
34+
npm publish --access public --provenance --tag ${{ env.PUBLISH_TAG }}
3235
env:
3336
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3437

3538
- name: Deploy document
39+
if: ${{ env.PUBLISH_TAG == 'latest' }}
3640
uses: peaceiris/actions-gh-pages@v4
3741
with:
3842
publish_dir: ./docs

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-rc.1",
3+
"version": "2.6.0-rc.2",
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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,21 @@ export class LarkApp implements LarkAppOption {
198198
* @see {@link WikiNodeModel#moveDocument}
199199
*/
200200
copyFile(
201-
URI: `${string}/wiki/${string}`,
201+
URI: `${string}wiki/${string}`,
202202
name?: string,
203203
parent_node_token?: string,
204204
user_id_type?: UserIdType
205205
): Promise<WikiNode>;
206206
copyFile(
207-
URI: `${string}/${LarkDocumentType}/${string}`,
207+
URI: `${string}${LarkDocumentType}/${string}`,
208208
name?: string,
209209
folder_token?: string,
210210
user_id_type?: UserIdType
211211
): Promise<CopiedFile>;
212212
async copyFile(URI: string, name?: string, folder_token?: string, user_id_type?: UserIdType) {
213213
await this.getAccessToken();
214214

215-
let [type, token] = new URL(URI, 'http://localhost').pathname.split('/'),
215+
let [[type, token]] = DriveFileModel.parseURI(URI),
216216
space_id: string | undefined,
217217
parent_node_token = folder_token;
218218

@@ -265,15 +265,13 @@ export class LarkApp implements LarkAppOption {
265265
return obj_type === 'docx' ? obj_token : '';
266266
}
267267

268-
static documentPathPattern = /(wiki|docx)\/(\w+)/;
269-
270268
/**
271269
* @see {@link DocumentModel#getOneContent}
272270
*/
273271
async downloadMarkdown(URI: string) {
274272
await this.getAccessToken();
275273

276-
const [, type, id] = URI.match(LarkApp.documentPathPattern) || [];
274+
const [[type, id]] = DriveFileModel.parseURI(URI);
277275

278276
const doc_token = type === 'wiki' ? (await this.wiki2drive(id)).obj_token : id;
279277

src/module/Drive/index.ts

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

55
import { LarkData, LarkDocumentType, UploadTargetType } from '../../type';
66
import { UserIdType } from '../User/type';
@@ -12,14 +12,20 @@ export abstract class DriveFileModel extends BaseListModel<DriveFile> {
1212
baseURI = 'drive/v1';
1313
abstract client: RESTClient;
1414

15+
static parseURI(path: string) {
16+
const list = new URL(path, 'http://localhost').pathname.split('/').slice(1);
17+
18+
return splitArray(list, 2);
19+
}
20+
1521
/**
1622
* @see {@link https://open.feishu.cn/document/server-docs/docs/drive-v1/file/batch_query}
1723
*
1824
* @param URI such as `docx/xxxyyyzzz`
1925
*/
2026
@toggle('downloading')
2127
async getOne(URI: string, user_id_type?: UserIdType) {
22-
let [doc_type, doc_token] = new URL(URI, 'http://localhost').pathname.split('/');
28+
let [[doc_type, doc_token]] = DriveFileModel.parseURI(URI);
2329

2430
const { body } = await this.client.post<LarkData<{ metas: DriveFile[] }>>(
2531
`${this.baseURI}/metas/batch_query?${buildURLData({ user_id_type })}`,

0 commit comments

Comments
 (0)