Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Lark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DocumentAIModel,
DocumentModel,
DriveFileModel,
DriveFileType,
TableFormView,
UserIdType,
WikiNode,
Expand Down Expand Up @@ -291,6 +292,25 @@ export class LarkApp implements LarkAppOption {
return this.documentStore.getOneContent(doc_token, 'markdown');
}

/**
* @see {@link DriveFileModel#updatePermission}
* @see {@link DriveFileModel#enablePassword}
*/
async publishFile(URI: string, enablePassword = false, editable = false) {
await this.getAccessToken();

let [[type, token]] = DriveFileModel.parseURI(URI);

if (type === 'wiki') ({ obj_type: type, obj_token: token } = await this.wiki2drive(token));
else type = getLarkDocumentType(type as LarkDocumentPathType);

await this.driveFileStore.updatePermission(token, type as DriveFileType, {
external_access_entity: 'open',
link_share_entity: editable ? 'tenant_editable' : 'tenant_readable'
});
if (enablePassword) await this.driveFileStore.enablePassword(token, type as DriveFileType);
}

async getBiTableSchema(appId: string): Promise<BiTableSchema> {
const { client } = this;

Expand Down
33 changes: 32 additions & 1 deletion src/module/Drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ 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,
PasswordResponse,
PublicPermission,
TransferOwner,
TransferOption
} from './type';

export * from './type';

Expand Down Expand Up @@ -121,4 +129,27 @@ export abstract class DriveFileModel extends BaseListModel<DriveFile> {
newOwner
);
}

/**
* @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-public/patch-2}
*/
@toggle('uploading')
async updatePermission(token: string, type: DriveFileType, permission: PublicPermission) {
const { body } = await this.client.patch<LarkData>(
`drive/v2/permissions/${token}/public?${buildURLData({ type })}`,
permission
);
return body!.data;
}

/**
* @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-public/permission-public-password/create}
*/
@toggle('uploading')
async enablePassword(token: string, type: DriveFileType) {
const { body } = await this.client.post<LarkData<PasswordResponse>>(
`drive/v1/permissions/${token}/public/password?${buildURLData({ type })}`
);
return body!.data!.password;
}
}
28 changes: 28 additions & 0 deletions src/module/Drive/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,31 @@ export interface TransferOption {
stay_put?: boolean;
old_owner_perm?: 'view' | 'edit' | 'full_access';
}

export type ExternalAccessEntity = 'open' | 'closed' | 'allow_share_partner_tenant';

export type SecurityEntity = 'anyone_can_view' | 'anyone_can_edit' | 'only_full_access';

export type CommentEntity = 'anyone_can_view' | 'anyone_can_edit';

export type ShareEntity = 'anyone' | 'same_tenant';

export type ManageCollaboratorEntity =
| 'collaborator_can_view'
| 'collaborator_can_edit'
| 'collaborator_full_access';

export type LinkShareEntity = 'tenant_readable' | 'tenant_editable' | 'partner_tenant_readable';

export interface PublicPermission {
external_access_entity?: ExternalAccessEntity;
security_entity?: SecurityEntity;
comment_entity?: CommentEntity;
share_entity?: ShareEntity;
manage_collaborator_entity?: ManageCollaboratorEntity;
link_share_entity?: LinkShareEntity;
}

export interface PasswordResponse {
password: string;
}