API 参考
文件
通过 app.capabilities 判断功能支持,通过 app.access 和宿主权限判断访问授权。示例使用合成数据,调用前请替换路径、ID、输入和筛选条件。
类型定义
graphql
type Subscription {
fileSearchResults(root: String!, query: String!, offset: Int!, limit: Int!, sortBy: FileSortBy!): FileSearchResults!
}
type Mutation {
cacheZipEntry(path: String!): String!
copyFileToDirectory(src: String!, directory: String!, name: String!): String!
createDir(path: String!): File!
createFile(path: String!): File!
createFileTask(type: FileTaskType!, title: String!, ops: [FileTaskOpInput!]!, waitForCompletion: Boolean! = false): FileTask!
createZipArchive(paths: [String!]!, target: String!): String!
deleteFiles(paths: [String!]!): ActionResult!
deleteTrashedFile(path: String!): Boolean!
extractZipArchive(path: String!, target: String!): String!
renameFile(path: String!, name: String!): String
restoreFiles(paths: [String!]!): ActionResult!
trashFiles(paths: [String!]!): ActionResult!
writeTextFile(path: String!, content: String!, overwrite: Boolean!): File!
}
type Query {
fileCount(root: String!, query: String!): Int!
fileInfo(path: String!): FileInfo
fileTasks(query: String!, offset: Int!, limit: Int!): [FileTask!]!
files(root: String!, query: String!, offset: Int!, limit: Int!, sortBy: FileSortBy!): [File!]!
recentFiles: [File!]!
trashedFileCount(query: String!): Int!
trashedFiles(query: String!, offset: Int!, limit: Int!, sortBy: TrashedFileSortBy!): [TrashedFile!]!
}
type ActionResult {
affectedCount: Int!
}
type AudioFileInfo {
durationMs: Long!
location: Location
}
type File {
permission: String!
mediaId: ID
name: String!
path: String!
createdAt: Instant
updatedAt: Instant!
size: Long!
isDir: Boolean!
childCount: Int!
url: String!
isSystem: Boolean!
}
type FileInfo {
path: String!
updatedAt: Instant!
size: Long!
data: MediaFileInfo
}
type FileSearchResults {
items: [File!]!
offset: Long!
count: Long!
complete: Boolean!
}
enum FileSortBy {
UPDATED_AT_ASC
UPDATED_AT_DESC
SIZE_ASC
SIZE_DESC
NAME_ASC
NAME_DESC
}
type FileTask {
id: ID!
clientId: ID!
type: FileTaskType!
title: String!
status: FileTaskStatus!
error: String!
totalBytes: Long!
doneBytes: Long!
totalItems: Long!
doneItems: Long!
createdAt: Instant!
updatedAt: Instant!
completedOps: [FileTaskCompletedOp!]!
}
type FileTaskCompletedOp {
src: String!
dst: String!
}
input FileTaskOpInput {
src: String!
dst: String!
overwrite: Boolean!
}
enum FileTaskStatus {
QUEUED
RUNNING
DONE
ERROR
}
enum FileTaskType {
COPY
MOVE
}
type ImageFileInfo {
make: String!
model: String!
rotation: Int!
colorSpace: String!
apertureValue: Float!
exposureTime: String!
focalLength: String!
isoSpeed: Int!
takenAt: Instant
flash: Int!
fNumber: Float!
exposureProgram: Int!
meteringMode: Int!
whiteBalance: Int!
creator: String!
resolutionX: Int!
resolutionY: Int!
description: String!
width: Int!
height: Int!
location: Location
}
scalar Instant
type Location {
latitude: Float!
longitude: Float!
}
scalar Long
union MediaFileInfo = ImageFileInfo | AudioFileInfo | VideoFileInfo
type TrashedFile {
id: ID!
type: TrashedFileType!
originalPath: String!
disk: String!
trashRelPath: String!
deletedAt: Instant!
uid: Int!
gid: Int!
mode: Int!
sizeBytes: Long
entryCount: Int
displayName: String!
trashedPath: String!
}
enum TrashedFileSortBy {
DATE_ASC
DATE_DESC
SIZE_ASC
SIZE_DESC
NAME_ASC
NAME_DESC
}
enum TrashedFileType {
FILE
DIR
}
type VideoFileInfo {
width: Int!
height: Int!
durationMs: Long!
rotation: Int!
displayWidth: Int!
displayHeight: Int!
bitrate: Long!
frameRate: Float!
title: String!
artist: String!
album: String!
genre: String!
takenAt: Instant
writer: String!
composer: String!
location: Location
}操作
subscription
fileSearchResults
接收指定根路径、筛选条件、页码和排序顺序的文件搜索结果快照。
graphql
subscription fileSearchResults($root: String!, $query: String!, $offset: Int!, $limit: Int!, $sortBy: FileSortBy!) {
fileSearchResults(root: $root, query: $query, offset: $offset, limit: $limit, sortBy: $sortBy) { offset count complete }
}mutation
cacheZipEntry
将指定 ZIP 条目解压到缓存并返回路径。
graphql
mutation cacheZipEntry($path: String!) {
cacheZipEntry(path: $path)
}mutation
copyFileToDirectory
按指定目标名称将文件复制到目录,在可用时返回路径。
graphql
mutation copyFileToDirectory($src: String!, $directory: String!, $name: String!) {
copyFileToDirectory(src: $src, directory: $directory, name: $name)
}mutation
createDir
创建目录,并以 File 对象返回。
graphql
mutation createDir($path: String!) {
createDir(path: $path) { permission mediaId name path createdAt updatedAt size isDir }
}mutation
createFile
在指定路径创建空文件,并返回其元数据。
graphql
mutation createFile($path: String!) {
createFile(path: $path) { permission mediaId name path createdAt updatedAt size isDir }
}mutation
createFileTask
创建批量复制或移动任务;可选择等待完成后再返回任务状态。
graphql
mutation createFileTask($type: FileTaskType!, $title: String!, $ops: [FileTaskOpInput!]!, $waitForCompletion: Boolean!) {
createFileTask(type: $type, title: $title, ops: $ops, waitForCompletion: $waitForCompletion) { id clientId type title status error totalBytes doneBytes }
}mutation
createZipArchive
将所选路径打包为目标路径下的 ZIP 文件。
graphql
mutation createZipArchive($paths: [String!]!, $target: String!) {
createZipArchive(paths: $paths, target: $target)
}mutation
deleteFiles
按精确路径删除一个或多个文件或目录。
graphql
mutation deleteFiles($paths: [String!]!) {
deleteFiles(paths: $paths) { affectedCount }
}mutation
deleteTrashedFile
永久删除文件回收站中的指定项目。
graphql
mutation deleteTrashedFile($path: String!) {
deleteTrashedFile(path: $path)
}mutation
extractZipArchive
将 ZIP 文件解压到目标目录。
graphql
mutation extractZipArchive($path: String!, $target: String!) {
extractZipArchive(path: $path, target: $target)
}mutation
renameFile
重命名文件或目录。
graphql
mutation renameFile($path: String!, $name: String!) {
renameFile(path: $path, name: $name)
}mutation
restoreFiles
恢复指定的回收站文件路径,并返回受影响数量。
graphql
mutation restoreFiles($paths: [String!]!) {
restoreFiles(paths: $paths) { affectedCount }
}mutation
trashFiles
将指定文件路径移入回收站,并返回受影响数量。
graphql
mutation trashFiles($paths: [String!]!) {
trashFiles(paths: $paths) { affectedCount }
}mutation
writeTextFile
按指定覆盖策略,将文本写入给定的文件路径。
graphql
mutation writeTextFile($path: String!, $content: String!, $overwrite: Boolean!) {
writeTextFile(path: $path, content: $content, overwrite: $overwrite) { permission mediaId name path createdAt updatedAt size isDir }
}query
fileCount
统计指定根目录下匹配文件搜索的结果数,不受分页影响。
graphql
# Total matches for the same query, ignoring paging.
query fileCount($root: String!, $query: String!) {
fileCount(root: $root, query: $query)
}query
fileInfo
读取路径对应的文件属性及支持的媒体元数据。路径不存在时返回 null;访问被拒绝或读取失败时返回错误。
graphql
query fileInfo($path: String!) {
fileInfo(path: $path) { path updatedAt size }
}query
fileTasks
分页读取符合查询条件的文件操作任务。
graphql
query fileTasks($query: String!, $offset: Int!, $limit: Int!) {
fileTasks(query: $query, offset: $offset, limit: $limit) { id clientId type title status error totalBytes doneBytes }
}query
files
分页列出和搜索根路径下的文件;query 为空时列出全部文件。
graphql
# One page of a directory listing, filtered and sorted by the search
# DSL. `query` may carry a `parent` field to redirect the root, which
# is what the file manager's breadcrumb links send.
query files($root: String!, $query: String!, $offset: Int!, $limit: Int!, $sortBy: FileSortBy!) {
files(root: $root, query: $query, offset: $offset, limit: $limit, sortBy: $sortBy) { permission mediaId name path createdAt updatedAt size isDir }
}query
recentFiles
列出最近打开的文件。
graphql
# Recently-opened files. Reading them is a storage read, so this one
# gates — plain-app's `recentFiles` calls `checkEnabledAsync`.
query recentFiles {
recentFiles { permission mediaId name path createdAt updatedAt size isDir }
}query
trashedFileCount
统计文件回收站中的项目数。
graphql
query trashedFileCount($query: String!) {
trashedFileCount(query: $query)
}query
trashedFiles
分页搜索回收站文件,并支持排序。
graphql
query trashedFiles($query: String!, $offset: Int!, $limit: Int!, $sortBy: TrashedFileSortBy!) {
trashedFiles(query: $query, offset: $offset, limit: $limit, sortBy: $sortBy) { id type originalPath disk trashRelPath deletedAt uid gid }
}