# 在线文档

在线文档,以下简称文档,是一种特殊的文件,详见 文档、文件、附件有什么区别?。

因此,文档支持所有文件相关的接口,除此之外,还支持以下接口。

# 创建文档

功能:创建文档,暂时只支持文字文档类型。

路径:fs/bs/doc/create。

请求方法:POST。

请求参数:

参数 必须 类型 备注
parentFid 是 string 上级文件夹 ID,如果为顶级则传 "0"。
docType 是 DocType 文档类型
spaceType 是 SpaceType 空间类型
name 是 string 文档名称
appUserId 是 string 业务用户 ID

参数示例:

{
  "parentFid": "0",
  "docType": "note",
  "spaceType": 1,
  "name": "测试文档",
  "appUserId": "007"
}

请求示例:

点击查看
export async function POST(
  parentFid: string,
  docType: DocType,
  spaceType: SpaceType,
  name: string,
  appUserId: string
): Promise<ResponseBody<IflydocsDocument>> {
  const method = 'POST'
  const path = '/fs/bs/doc/create'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = {
    parentFid,
    docType,
    spaceType,
    name,
    appUserId,
  }

  const resp = await axios.post(path, data, {
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "success",
  "data": {
    "status": 1,
    "fid": "10tc9",
    "appId": "6da37dd3",
    "name": "note",
    "parentFid": "0",
    "createTime": 1666859299839,
    "modifyTime": 1666859299839,
    "creator": 1657589576821,
    "creatorName": "我",
    "modifier": 1657589576821,
    "modifierName": "我",
    "owner": 1657589576821,
    "ownerName": "我",
    "docType": "note",
    "type": 2,
    "sourceType": 1,
    "sourceId": "10tc9",
    "suffix": "note",
    "fileType": 1,
    "spaceType": 1,
    "collaborativeStatus": 1,
    "role": "owner",
    "permissions": {
      "read": true,
      "edit": true,
      "annotate": true,
      "comment": true,
      "create": true,
      "delete": true,
      "share": true,
      "export": true,
      "move": true,
      "copy": true,
      "updateCollaborator": true,
      "updateAdmin": true,
      "transferSpace": true
    },
    "collection": false,
    "top": false,
    "size": 0
  }
}

# 获取文档内容

功能:

获取文档内容,支持操作序列或者纯文本两种格式。

提示

可用于自定义导出格式,或者构建全文检索索引。

路径:fs/bs/content。

请求方法:GET。

请求参数:

参数 必须 类型 备注
fid 是 string 文档 ID
plain 是 boolean 是否返回纯文本

请求示例:

点击查看
/**
 * 获取文档内容
 * 支持操作序列或者纯文本两种格式。
 * 可用于自定义导出格式,或者构建全文检索索引。
 * @param fid 文件 ID
 * @param plain 是否返回纯文本
 * @param uid 用户 ID
 */
export async function GET(
  fid: string,
  plain: boolean,
  appUserId: string
): Promise<ResponseBody<IflydocsContent>> {
  const method = 'GET'
  const path = '/fs/bs/content'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    fid,
    plain,
    appUserId,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "success",
  "data": {
    "ops": [
      {
        "insert": "Hello, world!\n"
      }
    ],
    "docType": "note",
    "name": "test-content"
  }
}

# 离线上传内容

功能:

上传本地离线编辑产生的操作序列,支持离线创建新文档。

注意

当该文档或上级文件夹被删除或协作关系被移除时:

  1. 如果该文档是当前用户创建的或拥有的,则上传到我的空间。
  2. 如果该文档不是当前用户创建的或拥有的,或者删除超过保留时间无法恢复的,则直接删除。

路径:fs/bs/doc/offlineUpload。

请求方法:POST。

请求参数:

参数 必须 类型 备注
fid 是 string 文档 ID,离线创建的不传。
parentFid 是 string 上级文件夹 ID,如果为顶级则传 "0"。
docType 是 DocType 文档类型
spaceType 是 SpaceType 空间类型
name 是 string 文档名称
cover 是 boolean true 为全量覆盖,false 为增量修改。为 true 时传入的是 ops 字段。
ops 否 OP[] 修改对应的操作序列
v 否 number 表示离线编辑文字文档时是基于当时哪个版本,不传则为 0
pendingOps 否 OP[] 修改对应的操作序列 (采用 pendingOps 与 inflightOp 时不使用 ops)
inflightOp 否 OP 修改对应的操作序列 (采用 pendingOps 与 inflightOp 时不适用 ops)
appUserId 否 string appUserId
uid 否 number uid
commands 否 string 离线编辑表格产生的 commands 集合并将其压缩后的字符串。
version 否 string 不传或传入“v1”,v1 表示 commands 字段由新的压缩方式进行压缩。

请求示例:

点击查看
type OfflineContents =
  | { ops: OP[] }
  | { v: number; pendingOps: OP[]; inflightOp: OP }
  | { version: string; commands: string }

/**
 * 上传本地离线编辑产生的操作序列
 * @param parentFid 上级文件夹 ID
 * @param docType 文档类型
 * @param spaceType 空间类型
 * @param name 文档名称
 * @param uid 用户 ID
 * @param cover 是否覆盖,true 为全量覆盖,false 为增量修改
 * @param contents 离线内容
 * @param fid 文档 ID,如果是离线创建,则不传。
 */
export async function POST(
  parentFid: string,
  docType: DocType,
  spaceType: SpaceType,
  name: string,
  appUserId: string,
  cover: boolean,
  contents: OfflineContents,
  fid?: string
): Promise<ResponseBody<IflydocsOfflineUploadResult>> {
  const method = 'POST'
  const path = '/fs/bs/doc/offlineUpload'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = {
    fid,
    parentFid,
    docType,
    spaceType,
    name,
    appUserId,
    cover,
    ...contents,
  }

  if (typeof fid === 'undefined') {
    delete data.fid
  }

  const resp = await axios.post(path, data, {
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "success",
  "data": {
    "document": {
      "_id": "10tci",
      "name": "test-offline-upload",
      "ops": [
        {
          "insert": "abcd\n"
        }
      ],
      "_m": {
        "ctime": 1666859301962,
        "mtime": 1666859302297
      },
      "uid": 1657589576821,
      "_type": "http://sharejs.org/types/rich-text/v1",
      "_v": 2,
      "_o": "635a4126e313ff57ed740f7a",
      "titleSet": 1,
      "upid": "1657589576821"
    },
    "detail": {
      "status": 1,
      "fid": "10tci",
      "appId": "6da37dd3",
      "name": "test-offline-upload",
      "parentFid": "0",
      "createTime": 1666859301954,
      "modifyTime": 1666859302309,
      "creator": 1657589576821,
      "creatorName": "我",
      "modifier": 1657589576821,
      "modifierName": "我",
      "owner": 1657589576821,
      "ownerName": "我",
      "docType": "note",
      "type": 2,
      "sourceType": 1,
      "sourceId": "10tci",
      "suffix": "note",
      "fileType": 1,
      "spaceType": 1,
      "collaborativeStatus": 1,
      "role": "owner",
      "permissions": {
        "read": true,
        "edit": true,
        "annotate": true,
        "comment": true,
        "create": true,
        "delete": true,
        "share": true,
        "export": true,
        "move": true,
        "copy": true,
        "updateCollaborator": true,
        "updateAdmin": true,
        "transferSpace": true
      },
      "collection": false,
      "top": false,
      "size": 0
    },
    "type": 1
  }
}

# 清理文档

功能:清除文档历史版本中无用图片、附件、音频文件,仅保留文档当前版本引用的文件。

路径:fs/bs/file/clean。

请求方法:PUT。

请求参数:

参数 必须 类型 备注
appUserId 是 string 业务用户 ID
fid 是 string 文档 ID

请求示例:

点击查看
/**
 * 清除文档历史版本中无用图片、附件、音频文件,仅保留文档当前版本引用的文件。
 * @param appUserId 业务用户 ID
 * @param fid 文档 ID
 */
export async function PUT(
  appUserId: string,
  fid: string
): Promise<ResponseBody<null>> {
  const method = 'PUT'
  const path = '/fs/bs/file/clean'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = {
    appUserId,
    fid,
  }

  const resp = await axios.put(path, data, {
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "success",
  "data": null
}

# 发起文档导出

功能:

发起文档导出请求。

导出是异步的,需要轮询 查询导出结果 接口获取结果。

参考:文档导出进度、导出文件类型、导出任务处理状态

路径:fs/bs/export/start。

请求方法:GET。

请求参数:

参数 必须 类型 备注
fid 是 string 文档 ID
exportType 是 number 导出格式,详见:导出文件类型
appUserId 是 string 业务用户 ID

请求示例:

点击查看
/**
 * 发起文件导出请求
 * 导出是异步的,需要轮询 `fs/bs/export/result` 接口获取结果。
 * @param fid 文件 ID
 * @param exportType 导出文件格式。
 * @param appUserId 业务用户 ID
 */
export async function GET(
  fid: string,
  exportType: IflydocsExportFileType,
  appUserId: string
): Promise<ResponseBody<IflydocsExportProcess>> {
  const method = 'GET'
  const path = '/fs/bs/export/start'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    fid,
    exportType,
    appUserId,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "success",
  "data": {
    "uid": 1657589576821,
    "appId": "6da37dd3",
    "fid": "10tcp",
    "exportRequestId": "22bb37c613f142cdb425296f8c3971cd",
    "requestTime": 1666859311046,
    "startProcessTime": null,
    "overProcessTime": null,
    "fastFailTime": null,
    "status": 1,
    "container": null,
    "objectId": "6da37dd3/22bb37c613f142cdb425296f8c3971cd.docx",
    "exportFileType": 1,
    "withAnnotation": false,
    "downloadSafetyChain": null,
    "downloadFileSize": null,
    "safetyChainEndTime": null,
    "thirdResult": null
  }
}

# 查询导出结果

功能:查询文档导出结果。

路径:fs/bs/export/result。

请求方法:GET。

请求参数:

参数 必须 类型 备注
fid 是 string 文档 ID
exportRequestId 是 string 文档导出请求 ID
appUserId 是 string 业务用户 ID

请求示例:

点击查看
/**
 * 查询文件导出结果
 * @param fid 文件 ID
 * @param exportRequestId 导出请求 ID
 * @param appUserId 业务用户 ID
 */
export async function GET(
  fid: string,
  exportRequestId: string,
  appUserId: string
): Promise<ResponseBody<IflydocsExportProcess>> {
  const method = 'GET'
  const path = '/fs/bs/export/result'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    fid,
    exportRequestId,
    appUserId,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "success",
  "data": {
    "uid": 1657589576821,
    "appId": "6da37dd3",
    "fid": "10tcp",
    "exportRequestId": "22bb37c613f142cdb425296f8c3971cd",
    "requestTime": 1666859311046,
    "startProcessTime": 1666859311093,
    "overProcessTime": 1666859312097,
    "fastFailTime": null,
    "status": 3,
    "container": "export",
    "objectId": "6da37dd3/22bb37c613f142cdb425296f8c3971cd.docx",
    "exportFileType": 1,
    "withAnnotation": false,
    "downloadSafetyChain": "https://bjbdn.openstorage.cn/v1/agji/export/6da37dd3/22bb37c613f142cdb425296f8c3971cd.docx?token=f0f4740ca77071fc5a73258d5a4fee9b99b1e29c&e=1666862912",
    "downloadFileSize": 5977,
    "safetyChainEndTime": 1666862912097,
    "thirdResult": null
  }
}

# 发起文档导入

功能:

发起文档导入请求。

导出是异步的,需要轮询 查询导入结果 接口获取结果。

支持以下格式:

  • doc
  • docx
  • html
  • md(Markdown)
  • xlsx

参考:文档导入进度

路径:fs/bs/import/start。

请求方法:POST。

请求参数:

参数 必须 类型 备注
parentFid 是 string 上级文件夹 ID
appUserId 是 string 业务用户 ID
file 否 File 文件,file 和 downloadUrl 参数不能同时为空
downloadUrl 否 string 网络文件下载地址,支持 http https 协议,file 和 downloadUrl 参数不能同时为空
fileName 否 string 导入后的文件名称

注意

需要使用 FormData 的形式发起请求。

请求示例:

点击查看
/**
 * 发起文档导入请求
 * 支持 doc、docx、html、markdown 等多种格式。
 * 导出是异步的,需要轮询 `fs/bs/import/result` 接口获取结果。
 * @param parentFid 导入目标文件夹 ID
 * @param appUserId 业务用户 ID
 * @param file 导入源文件的本地路径
 * @param downloadUrl 网络文件下载地址,支持http https 协议,file 和 downloadUrl 参数不能同时为空
 * @param fileName 导入后的文件名称
 */
export async function POST(
  parentFid: string,
  appUserId: string,
  file?: string,
  downloadUrl?: string,
  fileName?: string
): Promise<ResponseBody<IflydocsImportProcess>> {
  const method = 'POST'
  const path = '/fs/bs/import/start'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const data = new FormData()
  data.append('parentFid', parentFid)
  data.append('appUserId', appUserId)
  if (file) {
    data.append('file', fs.createReadStream(file))
  }
  if (downloadUrl) {
    data.append('downloadUrl', downloadUrl)
  }
  if (fileName) {
    data.append('fileName', fileName)
  }

  const headers = {
    Authorization,
    nonce,
    timestamp,
    ...data.getHeaders(),
  }

  const resp = await axios.post(path, data, {
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "success",
  "data": {
    "uid": 1657589576821,
    "fid": "10tcY",
    "requestId": "f6f9cfcfab24449d8f0be57890f0801a",
    "requestTime": 1666859333269,
    "startProcessTime": 1666859333269,
    "overProcessTime": null,
    "status": 2,
    "message": null
  }
}

# 查询导入结果

功能:查询文档导入结果。

路径:fs/bs/import/result。

请求方法:GET。

请求参数:

参数 必须 类型 备注
requestId 是 string 导入请求 ID
appUserId 是 string 业务用户 ID

请求示例:

点击查看
/**
 * 查询文件导入结果
 * @param requestId 导入请求 ID
 * @param appUserId 业务用户 ID
 */
export async function GET(
  requestId: string,
  appUserId: string
): Promise<
  ResponseBody<{
    process: IflydocsImportProcess
    detail: IflydocsDocument
  }>
> {
  const method = 'GET'
  const path = '/fs/bs/import/result'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    requestId,
    appUserId,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "message": "导入成功",
  "data": {
    "process": {
      "uid": 1657589576821,
      "fid": "10tcY",
      "requestId": "f6f9cfcfab24449d8f0be57890f0801a",
      "requestTime": 1666859333269,
      "startProcessTime": 1666859333269,
      "overProcessTime": null,
      "status": 3,
      "message": "导入成功"
    },
    "detail": {
      "status": 1,
      "fid": "10tcY",
      "appId": "6da37dd3",
      "name": "test",
      "parentFid": "0",
      "createTime": 1666859333303,
      "modifyTime": 1666859333303,
      "creator": 1657589576821,
      "creatorName": "我",
      "modifier": 1657589576821,
      "modifierName": "我",
      "owner": 1657589576821,
      "ownerName": "我",
      "docType": "note",
      "type": 2,
      "sourceType": 1,
      "sourceId": "10tcY",
      "suffix": "note",
      "fileType": 1,
      "spaceType": 1,
      "collaborativeStatus": 1,
      "role": "owner",
      "permissions": {
        "read": true,
        "edit": true,
        "annotate": true,
        "comment": true,
        "create": true,
        "delete": true,
        "share": true,
        "export": true,
        "move": true,
        "copy": true,
        "updateCollaborator": true,
        "updateAdmin": true,
        "transferSpace": true
      },
      "collection": false,
      "top": false
    }
  }
}

# 获取文档历史记录

功能:

获取文字文档历史记录内容。

提示

可用于还原特定历史版本。

路径:quill/bs/his/list。

请求方法:GET。

请求参数:

参数 必须 类型 备注
fid 是 string 是否返回纯文本
appUserId 是 string 文档 ID
timestamp 否 string 时间戳,根据时间戳 timestamp 获取早于该时间的数据。
pageSize 否 string 默认 20。大于 20 小于 100

请求示例:

点击查看
type DocHistory = {
  hislist: Array<{
    _id: string
    fid: string
    uid: string
    startTime: number
    endTime: number
    type: string
    msg: string
  }>
  snapshot: {
    id: string
    v: number
    data: { ops: OP[] }
  }
  oplist: Array<{
    v: number
    d: string
    uid: number
    op: {
      ops: OP[]
    }
  }>
}

/**
 * 获取文字文档历史记录
 * @param fid 文件 ID
 * @param appUserId 业务用户 ID
 */
export async function GET(
  fid: string,
  appUserId: string
): Promise<ResponseBody<DocHistory>> {
  const method = 'GET'
  const path = '/quill/bs/his/list'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    fid,
    appUserId,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "data": {
    "hislist": [
      {
        "_id": "635a415bbf61b857f4c3a91f",
        "fid": "10tdw",
        "uid": "1657589576821",
        "startTime": 0,
        "endTime": 1666859355118,
        "type": "filecreate",
        "msg": " 创建了文档"
      }
    ],
    "snapshot": {
      "id": "10tdw",
      "v": 0,
      "type": null,
      "data": {
        "ops": [
          {
            "insert": "\n"
          }
        ]
      },
      "m": null
    },
    "oplist": [
      {
        "v": 0,
        "d": "10tdw",
        "uid": 1657589576821,
        "op": {
          "ops": [
            {
              "insert": "\n"
            }
          ]
        }
      }
    ],
    "histypes": {
      "EDITCONTENT": {
        "name": "editcontent",
        "tpl": "{user} 编辑了内容"
      },
      "INVITEROLE": {
        "name": "inviterole",
        "tpl": "{user} 邀请了 {customer}"
      },
      "CHANGEROLE": {
        "name": "changerole",
        "tpl": "{user} 设置 {customer} 为“{role}”"
      },
      "DELETEROLE": {
        "name": "deleterole",
        "tpl": "{user} 移除了 {customer}"
      },
      "QUITROLE": {
        "name": "quitrole",
        "tpl": "{user} 退出了协作"
      },
      "FILECREATE": {
        "name": "filecreate",
        "tpl": "{user} 创建了文档"
      },
      "FILEDELETE": {
        "name": "filedelete",
        "tpl": "{user} 删除了文档"
      },
      "FILEREVERT": {
        "name": "filerevert",
        "tpl": "{user} 恢复了文档"
      },
      "FILEREGAIN": {
        "name": "fileregain",
        "tpl": "{user} 还原到{revertpoint}的内容"
      },
      "FILEMOVE": {
        "name": "filemove",
        "tpl": "{user} 将文档移动至“{location}”"
      },
      "FILERENAME": {
        "name": "filerename",
        "tpl": "{user} 将文档重命名为“{detail}”"
      },
      "SHARE": {
        "name": "share",
        "tpl": "{user} 分享了文档"
      },
      "UNSHARE": {
        "name": "unshare",
        "tpl": "{user} 取消了文档分享"
      },
      "FILECOPY": {
        "name": "filecopy",
        "tpl": "{user} 创建了副本"
      },
      "TONOTE": {
        "name": "tonote",
        "tpl": "{user} 生成文字文档"
      },
      "AUDIO_EXPORT": {
        "name": "audio_export",
        "tpl": "{user} 导出音频"
      }
    },
    "roles": {
      "none": "无权限",
      "delete": "无权限",
      "reader": "仅查看",
      "editor": "可编辑",
      "admin": "可管理",
      "owner": "所有者",
      "inherit": "继承"
    }
  }
}

# 获取表格历史记录

功能:

获取表格文档历史记录内容。

提示

可用于还原特定历史版本。

路径:sheet/bs/his/list。

请求方法:GET。

请求参数:

参数 必须 类型 备注
fid 是 string 文档 ID
appUserId 是 string 业务用户 ID
timestamp 否 string 时间戳,根据时间戳 timestamp 获取早于该时间的数据。
pageSize 否 string 默认 20。大于 20 小于 100

请求示例:

点击查看
type SheetHistory = {
  hislist: Array<{
    _id: string
    fid: string
    uid: string
    startTime: number
    endTime: number
    type: string
    hisSymbol: number
    users: Array<{
      uid: string
      nickname: string
    }>
    msg: string
  }>
}

/**
 * 获取表格文档历史记录
 * @param fid 文件 ID
 * @param appUserId 业务用户 ID
 */
export async function GET(
  fid: string,
  appUserId: string
): Promise<ResponseBody<SheetHistory>> {
  const method = 'GET'
  const path = '/sheet/bs/his/list'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    fid,
    appUserId,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "data": {
    "hislist": [
      {
        "_id": "635a415bbf61b857f4c3a91f",
        "fid": "10tdw",
        "uid": "1657589576821",
        "startTime": 0,
        "endTime": 1666859355118,
        "type": "filecreate",
        "msg": " 创建了文档"
      }
    ],
    "snapshot": {
      "id": "10tdw",
      "v": 0,
      "type": null,
      "data": {
        "ops": [
          {
            "insert": "\n"
          }
        ]
      },
      "m": null
    },
    "oplist": [
      {
        "v": 0,
        "d": "10tdw",
        "uid": 1657589576821,
        "op": {
          "ops": [
            {
              "insert": "\n"
            }
          ]
        }
      }
    ],
    "histypes": {
      "EDITCONTENT": {
        "name": "editcontent",
        "tpl": "{user} 编辑了内容"
      },
      "INVITEROLE": {
        "name": "inviterole",
        "tpl": "{user} 邀请了 {customer}"
      },
      "CHANGEROLE": {
        "name": "changerole",
        "tpl": "{user} 设置 {customer} 为“{role}”"
      },
      "DELETEROLE": {
        "name": "deleterole",
        "tpl": "{user} 移除了 {customer}"
      },
      "QUITROLE": {
        "name": "quitrole",
        "tpl": "{user} 退出了协作"
      },
      "FILECREATE": {
        "name": "filecreate",
        "tpl": "{user} 创建了文档"
      },
      "FILEDELETE": {
        "name": "filedelete",
        "tpl": "{user} 删除了文档"
      },
      "FILEREVERT": {
        "name": "filerevert",
        "tpl": "{user} 恢复了文档"
      },
      "FILEREGAIN": {
        "name": "fileregain",
        "tpl": "{user} 还原到{revertpoint}的内容"
      },
      "FILEMOVE": {
        "name": "filemove",
        "tpl": "{user} 将文档移动至“{location}”"
      },
      "FILERENAME": {
        "name": "filerename",
        "tpl": "{user} 将文档重命名为“{detail}”"
      },
      "SHARE": {
        "name": "share",
        "tpl": "{user} 分享了文档"
      },
      "UNSHARE": {
        "name": "unshare",
        "tpl": "{user} 取消了文档分享"
      },
      "FILECOPY": {
        "name": "filecopy",
        "tpl": "{user} 创建了副本"
      },
      "TONOTE": {
        "name": "tonote",
        "tpl": "{user} 生成文字文档"
      },
      "AUDIO_EXPORT": {
        "name": "audio_export",
        "tpl": "{user} 导出音频"
      }
    },
    "roles": {
      "none": "无权限",
      "delete": "无权限",
      "reader": "仅查看",
      "editor": "可编辑",
      "admin": "可管理",
      "owner": "所有者",
      "inherit": "继承"
    }
  }
}

# 获取表格历史记录详情

功能:

获取表格文档历史编辑记录内容的详细内容。

路径:sheet/bs/his。

请求方法:GET。

请求参数:

参数 必须 类型 备注
fid 是 string 文档 ID
appUserId 是 string 业务用户 ID
id 否 string 历史记录 ID

请求示例:

点击查看
type SheetHistoryItem = {
  snapshot: {
    _id: string
    fid: string
    uid: string
    startTime: number
    endTime: number
    type: string
    hisSymbol: number
    snapshot: string
  }
  commands: Object[]
}

/**
 * 获取表格历史记录详情
 * @param fid 文件 ID
 * @param appUserId 业务用户 ID
 * @param id 历史记录 ID
 */
export async function GET(
  fid: string,
  appUserId: string,
  id: string
): Promise<ResponseBody<SheetHistoryItem>> {
  const method = 'GET'
  const path = '/sheet/bs/his'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    fid,
    appUserId,
    id,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "data": {
    "snapshot": {
      "_id": "635a415bd55a718399720f01",
      "fid": "10tdx",
      "uid": "1657589576821",
      "startTime": 0,
      "endTime": 1666859355576,
      "type": "filecreate",
      "hisSymbol": 1,
      "snapshot": "H4sIAAAAAAAAAyvNS0lNy8xLTQEATzDc/gkAAAA="
    },
    "commands": []
  }
}

# 获取表格内容

功能:

获取文档内容,返回的内容为压缩后的数据。

路径:sheet/bs/v1/api/getJson。

请求方法:GET。

请求参数:

参数 必须 类型 备注
sheetid 是 string 文档 ID
appUserId 是 string 业务用户 ID

请求示例:

点击查看
/**
 * 获取表格文档内容
 * @param sheetid 文件 ID
 * @param appUserId 业务用户 ID
 */
export async function GET(
  sheetid: string,
  appUserId: string
): Promise<ResponseBody<string>> {
  const method = 'GET'
  const path = '/sheet/bs/v1/api/getJson'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    sheetid,
    appUserId,
  }

  const resp = await axios.get(path, {
    params,
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例:

点击查看
{
  "code": 0,
  "data": "H4sIAAAAAAAAA+1XTW/iMBD9NTkWJRQKPZKQqpVKW0G11Z4qk0yIt46NbIdCf/06ceLY0I9tu6u9oCAUzzyPZ8ZvnLE3Cr1+fwNcYEbVm3c6Uf/BoOf3gmrYj9S/SDgjZIn4DG0nBK8aoOQlaECOV7mS5/KKbhDB6RRJtI9BhLDneCuBpndISJgjuoJ9UMLWu1p7CSgFfruWyi2hUb7tTLi7w1sg+/MzRmUTRR3YL2GiqseVfiF3BEyolPECERNqBXiAKpT3EAv80lk4X0tHeYEKTHZGfYfp6kLFuohO5rAqCeI11G/l6nURadE9ylmB9DtBVCpEDlgNRKKFM6yCFyxTC/o/Ua2rxAJRcSKA46xadTStfjqdpZCsuMaijWYYesNGt2RcZThihHHjq9c/nUZxEJ+ZgDTqAacyd3YhYxwO5g4H1WPmbiyuBA1R6m0NUfJ0MPliVD0d54BAUu1++Lqfp1E4GEcGnjBiORn4Z0asmTRnz5fWtvYbPX9HjPSyltlhE0XG2QtQgulhCpIk6ULIAaSw6VdLfFtCUdExyYuHXjjyJkMvHnjh1DuPvHjsqdxNxl0xYrGoUwPpPvllDpax2yzDCfR9v8tpaspSL67CnIFEXbXa/FCpKwv6tj6FDJVEVsobloITplVhTdl9iS3HanaqWe7WcGPzxeRZb1iGG0rQkpCGyCWBKagjEy/B0mmjrV3D9un/4sfyDw6EIxkcMuiD+RoyJynJB8e5lflgz9Q9W/8lS3Mrx9+1FTKpvmDfNvavSsd8X46lcyydY+l8pnSIyn8EhFzRFLYa1fSWkq1fV5ie0GmqnH5K1Z0zRY0jVrb0D0z9OSA1PgQ9HgTO2xtLFwJdmZbTSJvqdXz8qA99o339oA99o3t9xCLeJkCm2pGoPm2s6RkiAuyv/20pq2bW8RhLKFqBPppGzun1yTlqPxcSSRvf6pi2pN10bnw2CpWSzYCv9L3ximbMXekrlwbYSo4Ol8I28SzGivTpx/5FuRf0xsbe46bjwm8HRxIjWQ8AAA=="
}