From 28b25cda00bc9dbe7582a757d2f8538ff5f0f33d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:45:03 +0000 Subject: [PATCH 1/5] Initial plan From 175ccf27eafcee56d18582043efd2098fdf0d8a7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:48:35 +0000 Subject: [PATCH 2/5] feat: add document publish APIs --- src/Lark.ts | 26 +++++++++++++++++++++++++ src/module/Drive/index.ts | 40 ++++++++++++++++++++++++++++++++++++++- src/module/Drive/type.ts | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/Lark.ts b/src/Lark.ts index 4014fdb..635479a 100644 --- a/src/Lark.ts +++ b/src/Lark.ts @@ -9,6 +9,8 @@ import { DocumentAIModel, DocumentModel, DriveFileModel, + PublishedFile, + PublicFileType, TableFormView, UserIdType, WikiNode, @@ -291,6 +293,30 @@ export class LarkApp implements LarkAppOption { return this.documentStore.getOneContent(doc_token, 'markdown'); } + async publishFile( + URI: string, + enablePassword = false, + editable = false + ): Promise { + await this.getAccessToken(); + + const [[pathType, token]] = DriveFileModel.parseURI(URI), + type: PublicFileType = + pathType === 'wiki' + ? pathType + : getLarkDocumentType(pathType as LarkDocumentPathType); + + const permissionPublic = await this.driveFileStore.updatePublicPermission(type, token, { + external_access_entity: 'open', + link_share_entity: editable ? 'anyone_editable' : 'anyone_readable' + }), + password = enablePassword + ? await this.driveFileStore.createPublicPassword(type, token) + : undefined; + + return { permissionPublic, password }; + } + async getBiTableSchema(appId: string): Promise { const { client } = this; diff --git a/src/module/Drive/index.ts b/src/module/Drive/index.ts index 7e6d2cb..9fd7a4e 100644 --- a/src/module/Drive/index.ts +++ b/src/module/Drive/index.ts @@ -4,7 +4,16 @@ import { buildURLData, splitArray } from 'web-utility'; import { LarkData, LarkDocumentPathTypeMap, LarkDocumentType, UploadTargetType } from '../../type'; import { UserIdType } from '../User/type'; -import { CopiedFile, DriveFile, DriveFileType, TransferOwner, TransferOption } from './type'; +import { + CopiedFile, + DriveFile, + DriveFileType, + PermissionPublic, + PublicFileType, + PublicPermissionPatch, + TransferOption, + TransferOwner +} from './type'; export * from './type'; @@ -106,6 +115,35 @@ export abstract class DriveFileModel extends BaseListModel { return body!.data!.file; } + /** + * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-public/patch-2} + */ + @toggle('uploading') + async updatePublicPermission( + type: PublicFileType, + token: string, + permission: PublicPermissionPatch + ) { + const { body } = await this.client.patch>( + `drive/v2/permissions/${token}/public?${buildURLData({ type })}`, + permission + ); + + return body!.data!.permission_public; + } + + /** + * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-public/permission-public-password/create} + */ + @toggle('uploading') + async createPublicPassword(type: PublicFileType, token: string) { + const { body } = await this.client.post>( + `${this.baseURI}/permissions/${token}/public/password?${buildURLData({ type })}` + ); + + return body!.data!.password; + } + /** * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-member/transfer_owner} */ diff --git a/src/module/Drive/type.ts b/src/module/Drive/type.ts index 5014076..08eab35 100644 --- a/src/module/Drive/type.ts +++ b/src/module/Drive/type.ts @@ -14,6 +14,42 @@ export type DriveFile = Record< export type CopiedFile = Record<'type' | `${'parent_' | ''}token` | 'name' | 'url', string>; export type DriveFileType = LarkDocumentType | 'minutes' | 'folder' | 'wiki'; +export type PublicFileType = Exclude; + +export type PublicPermissionLevel = 'anyone_can_view' | 'anyone_can_edit' | 'only_full_access'; +export type PublicCommentEntity = 'anyone_can_view' | 'anyone_can_edit'; +export type PublicShareEntity = 'anyone' | 'same_tenant'; +export type PublicCollaboratorEntity = + | 'collaborator_can_view' + | 'collaborator_can_edit' + | 'collaborator_full_access'; +export type PublicExternalAccessEntity = 'open' | 'closed' | 'allow_share_partner_tenant'; +export type PublicLinkShareEntity = + | 'tenant_readable' + | 'tenant_editable' + | 'partner_tenant_readable' + | 'partner_tenant_editable' + | 'anyone_readable' + | 'anyone_editable' + | 'closed'; + +export interface PermissionPublic { + external_access_entity: PublicExternalAccessEntity; + security_entity: PublicPermissionLevel; + comment_entity: PublicCommentEntity; + share_entity: PublicShareEntity; + manage_collaborator_entity: PublicCollaboratorEntity; + link_share_entity: PublicLinkShareEntity; + copy_entity: PublicPermissionLevel; + lock_switch: boolean; +} + +export type PublicPermissionPatch = Partial>; + +export interface PublishedFile { + permissionPublic: Partial; + password?: string; +} export interface TransferOwner { member_type: 'email' | 'userid' | 'openid'; From 9b1a085a9bc1d3d094bff425daf8935db2299e24 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:49:59 +0000 Subject: [PATCH 3/5] refactor: normalize publish permission paths --- src/module/Drive/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/module/Drive/index.ts b/src/module/Drive/index.ts index 9fd7a4e..2933581 100644 --- a/src/module/Drive/index.ts +++ b/src/module/Drive/index.ts @@ -124,8 +124,10 @@ export abstract class DriveFileModel extends BaseListModel { token: string, permission: PublicPermissionPatch ) { + const baseURI = this.baseURI.replace('/v1', '/v2'); + const { body } = await this.client.patch>( - `drive/v2/permissions/${token}/public?${buildURLData({ type })}`, + `${baseURI}/permissions/${token}/public?${buildURLData({ type })}`, permission ); From cfa34ac8f43076542f2f702ce726115c9fba99e5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Jun 2026 22:50:57 +0000 Subject: [PATCH 4/5] refactor: stabilize drive permission paths --- src/module/Drive/index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/module/Drive/index.ts b/src/module/Drive/index.ts index 2933581..3d10b08 100644 --- a/src/module/Drive/index.ts +++ b/src/module/Drive/index.ts @@ -17,6 +17,9 @@ import { export * from './type'; +const MemberPermissionBaseURI = 'drive/v1/permissions'; +const PublicPermissionBaseURI = 'drive/v2/permissions'; + export abstract class DriveFileModel extends BaseListModel { baseURI = 'drive/v1'; abstract client: RESTClient; @@ -124,10 +127,8 @@ export abstract class DriveFileModel extends BaseListModel { token: string, permission: PublicPermissionPatch ) { - const baseURI = this.baseURI.replace('/v1', '/v2'); - const { body } = await this.client.patch>( - `${baseURI}/permissions/${token}/public?${buildURLData({ type })}`, + `${PublicPermissionBaseURI}/${token}/public?${buildURLData({ type })}`, permission ); @@ -140,7 +141,7 @@ export abstract class DriveFileModel extends BaseListModel { @toggle('uploading') async createPublicPassword(type: PublicFileType, token: string) { const { body } = await this.client.post>( - `${this.baseURI}/permissions/${token}/public/password?${buildURLData({ type })}` + `${MemberPermissionBaseURI}/${token}/public/password?${buildURLData({ type })}` ); return body!.data!.password; @@ -157,7 +158,7 @@ export abstract class DriveFileModel extends BaseListModel { option = {} as TransferOption ) { await this.client.post( - `${this.baseURI}/permissions/${token}/members/transfer_owner?${buildURLData({ ...option, type })}`, + `${MemberPermissionBaseURI}/${token}/members/transfer_owner?${buildURLData({ ...option, type })}`, newOwner ); } From 333a0f2ce2b7c51efe2f6e748641ba37296c63e3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Jun 2026 23:07:14 +0000 Subject: [PATCH 5/5] refactor: simplify drive permission literal types --- src/module/Drive/type.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/module/Drive/type.ts b/src/module/Drive/type.ts index 08eab35..131e4ff 100644 --- a/src/module/Drive/type.ts +++ b/src/module/Drive/type.ts @@ -16,22 +16,18 @@ export type CopiedFile = Record<'type' | `${'parent_' | ''}token` | 'name' | 'ur export type DriveFileType = LarkDocumentType | 'minutes' | 'folder' | 'wiki'; export type PublicFileType = Exclude; -export type PublicPermissionLevel = 'anyone_can_view' | 'anyone_can_edit' | 'only_full_access'; -export type PublicCommentEntity = 'anyone_can_view' | 'anyone_can_edit'; +type PublicEditableLevel = 'view' | 'edit'; +type PublicLinkAccessLevel = 'readable' | 'editable'; +type PublicLinkShareScope = 'tenant' | 'partner_tenant' | 'anyone'; + +export type PublicPermissionLevel = `anyone_can_${PublicEditableLevel}` | 'only_full_access'; +export type PublicCommentEntity = `anyone_can_${PublicEditableLevel}`; export type PublicShareEntity = 'anyone' | 'same_tenant'; export type PublicCollaboratorEntity = - | 'collaborator_can_view' - | 'collaborator_can_edit' + | `collaborator_can_${PublicEditableLevel}` | 'collaborator_full_access'; export type PublicExternalAccessEntity = 'open' | 'closed' | 'allow_share_partner_tenant'; -export type PublicLinkShareEntity = - | 'tenant_readable' - | 'tenant_editable' - | 'partner_tenant_readable' - | 'partner_tenant_editable' - | 'anyone_readable' - | 'anyone_editable' - | 'closed'; +export type PublicLinkShareEntity = `${PublicLinkShareScope}_${PublicLinkAccessLevel}` | 'closed'; export interface PermissionPublic { external_access_entity: PublicExternalAccessEntity;