PlainApp
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

從資源 URL 或聊天附件建立下載;必須且只能提供一種來源。

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 }
}