/** * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file src/doc_client.ts * @author guofan */ import BceBaseClient from './bce_base_client'; import type { BceConfig, BceResponse } from './types/common'; /** 文档客户端选项 */ interface DocumentOptions { config?: Partial; title?: string; format?: string; notification?: string; meta?: { md5?: string; [key: string]: any; }; } /** 文档创建响应 */ interface CreateDocumentResponse { documentId: string; bucket: string; object: string; bosEndpoint: string; } /** 文档注册响应 */ interface RegisterResponse { documentId: string; bucket: string; object: string; bosEndpoint: string; } /** 文档状态 */ interface DocumentStatus { documentId: string; status: 'PROCESSING' | 'PUBLISHED' | 'FAILED'; createTime: string; publishTime?: string; title: string; format: string; sizeInBytes: number; pageCount?: number; error?: { code: string; message: string; }; } /** 文档列表选项 */ interface ListDocumentsOptions { status?: 'PROCESSING' | 'PUBLISHED' | 'FAILED'; maxKeys?: number; marker?: string; config?: Partial; } /** * 文档转码任务接口(Job/Transcoding API) * http://bce.baidu.com/doc/DOC/API.html#.1D.1E.B0.1E.6C.74.0C.6D.C1.68.D2.57.6F.70.EA.F1 */ export default class Document extends BceBaseClient { private _documentId; /** * 构造函数 * @param config 文档客户端配置 */ constructor(config: BceConfig); /** * 构建 URL * @param extraPaths 额外路径段 * @returns 完整的 URL 路径 */ private _buildUrl; /** * 获取文档 ID * @returns 文档 ID */ getId(): string | null; /** * 设置文档 ID * @param documentId 文档 ID * @returns this(链式调用) */ setId(documentId: string): this; /** * 创建文档转码任务 * @param data 文档数据(文件路径、Buffer、Blob 或 BOS 路径) * @param options 选项 * @returns Promise 解析为创建结果 */ create(data: string | Buffer | Blob, options?: DocumentOptions): Promise>; /** * 从 BOS 创建文档 * @param bucket 存储桶名称 * @param object 对象键 * @param title 文档标题 * @param format 文档格式 * @param notification 通知配置 * @returns Promise 解析为创建结果 */ createFromBos(bucket: string, object: string, title: string, format: string, notification?: string): Promise>; /** * 执行创建文档 * @param data 文档数据 * @param options 选项 * @returns Promise 解析为创建结果 */ private _doCreate; /** * 注册文档 * @param options 选项 * @returns Promise 解析为注册结果 */ register(options: DocumentOptions): Promise>; /** * 发布文档 * @param options 选项 * @returns Promise 解析为发布结果 */ publish(options?: DocumentOptions): Promise>; /** * 读取文档状态 * @param documentId 文档 ID(可选,默认使用当前设置的 ID) * @param options 选项 * @returns Promise 解析为文档状态 */ read(documentId?: string, options?: DocumentOptions): Promise>; /** * 列出文档 * @param options 选项 * @returns Promise 解析为文档列表 */ list(options?: ListDocumentsOptions): Promise>; /** * 删除文档 * @param documentId 文档 ID(可选,默认使用当前设置的 ID) * @param options 选项 * @returns Promise 解析为删除结果 */ remove(documentId?: string, options?: DocumentOptions): Promise>; } export {}; //# sourceMappingURL=doc_client.d.ts.map