API 参考
下载
通过 app.capabilities 判断功能支持,通过 app.access 和宿主权限判断访问授权。示例使用合成数据,调用前请替换路径、ID、输入和筛选条件。
类型定义
graphql
type Subscription {
downloadsChanged: Boolean!
}
type Mutation {
cancelDownload(id: ID!): Boolean!
createDownload(input: DownloadInput!): Download!
pauseDownload(id: ID!): Boolean!
removeDownload(id: ID!): Boolean!
resumeDownload(id: ID!): Boolean!
retryDownload(id: ID!): Boolean!
}
type Query {
downloads: [Download!]!
}
input ChatDownloadInput {
messageId: ID!
peerId: ID!
fileIds: [String!]!
}
type ChatDownloadSource {
messageId: ID!
peerId: ID!
fileIds: [String!]!
}
type Download {
id: ID!
title: String!
source: DownloadSource!
targetDir: String!
zipName: String
status: DownloadStatus!
downloadedBytes: Long!
totalBytes: Long!
bytesPerSecond: Long!
totalFiles: Int!
doneFiles: Int!
currentFile: String!
error: String!
failures: [DownloadFailure!]!
}
type DownloadFailure {
path: String!
error: String!
}
input DownloadInput @oneOf {
resources: ResourceDownloadInput
chat: ChatDownloadInput
}
union DownloadSource = ResourceDownloadSource | ChatDownloadSource
enum DownloadStatus {
PENDING
DOWNLOADING
PAUSED
PACKING
COMPLETED
PARTIAL
FAILED
CANCELED
}
scalar Long
input ResourceDownloadInput {
urls: [String!]!
targetDir: String!
zipName: String
}
type ResourceDownloadSource {
urls: [String!]!
}操作
subscription
downloadsChanged
接收下载进度变更信号。
graphql
subscription downloadsChanged {
downloadsChanged
}mutation
cancelDownload
停止任务,保留任务记录和已保存文件。
graphql
mutation cancelDownload($id: ID!) {
cancelDownload(id: $id)
}mutation
createDownload
创建资源或聊天附件下载任务;resources 与 chat 必须且只能提供一个。资源保存到执行此接口的设备,聊天附件保存到消息的附件存储。
graphql
mutation createDownload($input: DownloadInput!) {
createDownload(input: $input) { id title targetDir zipName status downloadedBytes totalBytes bytesPerSecond }
}mutation
pauseDownload
暂停指定下载任务,保留已完成文件。
graphql
mutation pauseDownload($id: ID!) {
pauseDownload(id: $id)
}mutation
removeDownload
停止任务并移除任务记录,保留已保存文件。
graphql
mutation removeDownload($id: ID!) {
removeDownload(id: $id)
}mutation
resumeDownload
继续已存在的暂停任务;未完成文件从头下载。
graphql
mutation resumeDownload($id: ID!) {
resumeDownload(id: $id)
}mutation
retryDownload
重试失败、部分完成或已取消的任务,跳过已完成文件。
graphql
mutation retryDownload($id: ID!) {
retryDownload(id: $id)
}query
downloads
列出通用下载任务及其进度、结果和错误。
graphql
query downloads {
downloads { id title targetDir zipName status downloadedBytes totalBytes bytesPerSecond }
}