Skip to content

新API CAT_fileStorage 提案 #127

@CodFrm

Description

@CodFrm

调用此 API,可以操控脚本同步配置的文件储存源,将会在设定目录下创建一个app目录供此 API 使用.

API 定义如下

/**
 * 操控脚本同步配置的文件储存源,将会在同步目录下创建一个app/(uuid或者storageName)目录供此 API 使用
 * 当声明了@storageName时,将会将文件上传至指定的@storageName目录,多个脚本也可用此声明公用一个文件夹
 * 上传时默认覆盖同名文件
 * @param action 操作类型 list 列出指定目录所有文件, upload 上传文件, download 下载文件, delete 删除文件
 */
declare function CAT_fileStorage(
  action: "list",
  details: {
    path?: string;
    onload?: (files: CATType.FileStorageFileInfo[]) => void;
    onerror?: (error: FileStorageError) => void;
  }
): void;
declare function CAT_fileStorage(
  action: "download",
  details: {
    filename: string;
    onload: (data: Blob) => void;
    onprogress?: (progress: number) => void;
    onerror?: (error: FileStorageError) => void;
  }
): void;

declare function CAT_fileStorage(
  action: "delete",
  details: {
    filename: string;
    onload?: () => void;
    onerror?: (error: FileStorageError) => void;
  }
): void;

declare function CAT_fileStorage(
  action: "upload",
  details: {
    filename: string;
    data: Blob;
    onload?: () => void;
    onprogress?: (progress: number) => void;
    onerror?: (error: FileStorageError) => void;
  }
): void;

  interface FileStorageError {
    // 错误码 1 用户未配置文件储存源 2 文件储存源配置错误 3 路径不存在
    // 4 文件不存在 5 文件已存在 6 上传失败 7 下载失败 8 删除失败
    code: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
    msg: string;
  }
  interface FileStorageFileInfo {
    path: string;
    name: string;
    size: number;
    isDir: boolean;
  }

论坛帖子:
脚本猫新API CAT_fileStorage 提案
https://bbs.tampermonkey.net.cn/thread-3881-1-1.html
(出处: 油猴中文网)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions