import { Command } from 'commander'; import { Inquirer } from 'inquirer'; import { IRequestPromiseOptions } from './oldRequest'; import type { Env, Handler, Hono, MiddlewareHandler } from 'hono'; /** * Type definition for the plugin router setup callback. * The plugin receives a Hono instance created by the Host. */ export type PluginRouterSetup = (router: Hono) => void; export interface IServerManager { /** * * @param port * @param host * @param ignoreExistingExternalServer PicGo GUI may start a server instance already, if you want to start a new one, set this to true * @param secret shared secret for server authentication * @returns */ listen: (port?: number, host?: string, ignoreExistingExternalServer?: boolean, secret?: string) => Promise; shutdown: () => void; isListening: () => boolean; /** * Get current server listening address if running. * e.g. "http://127.0.0.1:36677/" */ getServerInfo: () => string; registerGet

(path: P, handler: Handler): void; registerPost

(path: P, handler: Handler): void; registerPut

(path: P, handler: Handler): void; registerDelete

(path: P, handler: Handler): void; registerMiddleware

(path: P, handler: MiddlewareHandler): void; /** * Register a static file server route. * @param path - The URL prefix (e.g. '/static') * @param root - The local file system path */ registerStatic: (path: string, root: string) => void; /** * Mount a sub-router for plugins. * * PicGo creates a new Hono instance (to ensure version consistency) * and passes it to the setup callback for the plugin to configure. */ mount: (path: string, setup: PluginRouterSetup) => void; } export interface ICloudManager { login: (token?: string) => Promise; logout: () => void; disposeLoginFlow: () => void; getUserInfo: () => Promise<{ user: string; } | null>; } export interface IPicGo extends NodeJS.EventEmitter { /** * picgo configPath * * if do not provide, then it will use default configPath */ configPath: string; /** * the picgo configPath's baseDir */ baseDir: string; /** * picgo logger factory */ log: ILogger; /** * picgo commander, for cli */ cmd: ICommander; /** * picgo server manager */ server: IServerManager; /** * picgo cloud manager */ cloud: ICloudManager; /** * after transformer, the input will be output */ output: IImgInfo[]; /** * the origin input */ input: any[]; /** * register\unregister\get picgo's plugin */ pluginLoader: IPluginLoader; /** * install\uninstall\update picgo's plugin via npm */ pluginHandler: IPluginHandler; /** * @deprecated will be removed in v1.5.0+ * * use request instead. * * http request tool */ Request: IRequest; /** * plugin system core part transformer\uploader\beforeTransformPlugins... */ helper: IHelper; /** * uploader multi-config manager */ uploaderConfig: IUploaderConfigManager; /** * picgo-core version */ VERSION: string; /** * electron picgo's version */ GUI_VERSION?: string; /** * will be released in v1.5.0+ * * replace old Request * * http request tool */ request: IRequest['request']; /** * Opens a URL in the default browser. * * Default implementation uses the `open` package in Node.js. * Consumers (Electron/VSCode extensions) can overwrite this method. */ openUrl: (url: string) => Promise; i18n: II18nManager; /** * get picgo config */ getConfig: (name?: string) => T; /** * save picgo config to configPath */ saveConfig: (config: IStringKeyMap) => void; /** * remove some [propName] in config[key] && save config to configPath */ removeConfig: (key: string, propName: string) => void; /** * set picgo config to ctx && will not save to configPath */ setConfig: (config: IStringKeyMap) => void; /** * unset picgo config to ctx && will not save to configPath */ unsetConfig: (key: string, propName: string) => void; /** * upload gogogo */ upload: (input?: any[]) => Promise; } export interface IUploaderConfigItem { _id: string; _configName: string; _createdAt: number; _updatedAt: number; [key: string]: unknown; } export interface IUploaderTypeConfigs { configList: IUploaderConfigItem[]; defaultId: string; } export interface IUploaderConfigManager { listUploaderTypes: () => string[]; getConfigList: (type: string) => IUploaderConfigItem[]; getActiveConfig: (type: string) => IUploaderConfigItem | undefined; use: (type: string, configName?: string) => IUploaderConfigItem; createOrUpdate: (type: string, configName?: string, configPatch?: IStringKeyMap) => IUploaderConfigItem; copy: (type: string, configName: string, newConfigName: string) => IUploaderConfigItem; rename: (type: string, oldName: string, newName: string) => IUploaderConfigItem; remove: (type: string, configName: string) => void; } /** * for plugin config */ export interface IPluginConfig { name: string; type: string; required: boolean; default?: any; alias?: string; message?: string; prefix?: string; [propName: string]: any; } /** * for lifecycle plugins */ export interface ILifecyclePlugins { register: (id: string, plugin: IPlugin) => void; unregister: (id: string) => void; getName: () => string; get: (id: string) => IPlugin | undefined; getList: () => IPlugin[]; getIdList: () => string[]; } export interface IHelper { transformer: ILifecyclePlugins; uploader: ILifecyclePlugins; beforeTransformPlugins: ILifecyclePlugins; beforeUploadPlugins: ILifecyclePlugins; afterUploadPlugins: ILifecyclePlugins; } export interface ICommander extends ILifecyclePlugins { program: Command; inquirer: Inquirer; } export interface IPluginLoader { /** * register [local plugin] or [provided plugin] * * if the second param (plugin) is provided * * then picgo will register this plugin and enable it by default * * but picgo won't write any config to config file * * you should use ctx.setConfig to change the config context */ registerPlugin: (name: string, plugin?: IPicGoPlugin) => void; unregisterPlugin: (name: string) => void; getPlugin: (name: string) => IPicGoPluginInterface | undefined; /** * get enabled plugin list */ getList: () => string[]; /** * get all plugin list (enabled or not) */ getFullList: () => string[]; hasPlugin: (name: string) => boolean; } export interface IRequestOld { request: import('axios').AxiosInstance; } export type IOldReqOptions = Omit; export type IOldReqOptionsWithFullResponse = IOldReqOptions & { resolveWithFullResponse: true; }; export type IOldReqOptionsWithJSON = IOldReqOptions & { json: true; }; /** * for PicGo new request api, the response will be json format */ export type IReqOptions = AxiosRequestConfig & { resolveWithFullResponse: true; }; /** * for PicGo new request api, the response will be Buffer */ export type IReqOptionsWithArrayBufferRes = IReqOptions & { responseType: 'arraybuffer'; }; /** * for PicGo new request api, the response will be just response data. (not statusCode, headers, etc.) */ export type IReqOptionsWithBodyResOnly = AxiosRequestConfig; export type IFullResponse = AxiosResponse & { statusCode: number; body: T; }; type AxiosResponse = import('axios').AxiosResponse; type AxiosRequestConfig = import('axios').AxiosRequestConfig; interface IRequestOptionsWithFullResponse { resolveWithFullResponse: true; } interface IRequestOptionsWithJSON { json: true; } interface IRequestOptionsWithResponseTypeArrayBuffer { responseType: 'arraybuffer'; } /** * T is the response data type * U is the config type */ export type IResponse = U extends IRequestOptionsWithFullResponse ? IFullResponse : U extends IRequestOptionsWithJSON ? T : U extends IRequestOptionsWithResponseTypeArrayBuffer ? Buffer : U extends IOldReqOptionsWithFullResponse ? IFullResponse : U extends IOldReqOptionsWithJSON ? T : U extends IOldReqOptions ? string : U extends IReqOptionsWithBodyResOnly ? T : string; /** * the old request lib will be removed in v1.5.0+ * the request options have the following properties */ export interface IRequestLibOnlyOptions { proxy?: string; body?: any; formData?: { [key: string]: any; } | undefined; form?: { [key: string]: any; } | string | undefined; } export type IRequestConfig = T extends IRequestLibOnlyOptions ? IOldReqOptions : AxiosRequestConfig; export interface IRequest { request: extends IOldReqOptions ? IOldReqOptions : IRequestConfig extends AxiosRequestConfig ? AxiosRequestConfig : never)>(config: U) => Promise>; } export type ILogColor = 'blue' | 'green' | 'yellow' | 'red'; /** * for uploading image info */ export interface IImgInfo { buffer?: Buffer; base64Image?: string; fileName?: string; width?: number; height?: number; extname?: string; imgUrl?: string; originImgUrl?: string; mimeType?: string; filePath?: string; size?: number; [propName: string]: any; } export interface IUrlRewriteRule { match: string; replace: string; enable?: boolean; global?: boolean; ignoreCase?: boolean; } export interface IPathTransformedImgInfo extends IImgInfo { success: boolean; } export interface IStringKeyMap { [key: string]: T extends T ? T : any; } export interface ICLIConfigs { [module: string]: IStringKeyMap; } /** SM.MS 图床配置项 */ export interface ISmmsConfig { token: string; backupDomain?: string; } /** 七牛云图床配置项 */ export interface IQiniuConfig { accessKey: string; secretKey: string; /** 存储空间名 */ bucket: string; /** 自定义域名 */ url: string; /** 存储区域编号 */ area: 'z0' | 'z1' | 'z2' | 'na0' | 'as0' | string; /** 网址后缀,比如使用 `?imageslim` 可进行[图片瘦身](https://developer.qiniu.com/dora/api/1271/image-thin-body-imageslim) */ options: string; /** 自定义存储路径,比如 `img/` */ path: string; } /** 又拍云图床配置项 */ export interface IUpyunConfig { /** 存储空间名,及你的服务名 */ bucket: string; /** 操作员 */ operator: string; /** 密码 */ password: string; /** 针对图片的一些后缀处理参数 */ options: string; /** 自定义存储路径,比如 `img/` */ path: string; /** 加速域名,注意要加 `http://` 或者 `https://` */ url: string; } /** 腾讯云图床配置项 */ export interface ITcyunConfig { secretId: string; secretKey: string; /** 存储桶名,v4 和 v5 版本不一样 */ bucket: string; appId: string; /** 存储区域,例如 ap-beijing-1 */ area: string; /** 请求的 ENDPOINT,设置后 `area` 字段会失效 */ endpoint: string; /** 自定义存储路径,比如 img/ */ path: string; /** 自定义域名,注意要加 `http://` 或者 `https://` */ customUrl: string; /** COS 版本,v4 或者 v5 */ version: 'v5' | 'v4'; /** 针对图片的一些后缀处理参数 PicGo 2.4.0+ PicGo-Core 1.5.0+ */ options: string; /** 是否支持极智压缩 */ slim: boolean; } /** GitHub 图床配置项 */ export interface IGithubConfig { /** 仓库名,格式是 `username/reponame` */ repo: string; /** github token */ token: string; /** 自定义存储路径,比如 `img/` */ path: string; /** 自定义域名,注意要加 `http://` 或者 `https://` */ customUrl: string; /** 分支名,默认是 `main` */ branch: string; } /** 阿里云图床配置项 */ export interface IAliyunConfig { accessKeyId: string; accessKeySecret: string; /** 存储空间名 */ bucket: string; /** 存储区域代号 */ area: string; /** 自定义存储路径 */ path: string; /** 自定义域名,注意要加 `http://` 或者 `https://` */ customUrl: string; /** 针对图片的一些后缀处理参数 PicGo 2.2.0+ PicGo-Core 1.4.0+ */ options: string; } /** Imgur 图床配置项 */ export interface IImgurConfig { /** imgur 的 `clientId` */ clientId: string; /** 代理地址,仅支持 http 代理 */ proxy: string; } /** PicGo 配置文件类型定义 */ export interface IConfig { picBed: { uploader: string; current?: string; smms?: ISmmsConfig; qiniu?: IQiniuConfig; upyun?: IUpyunConfig; tcyun?: ITcyunConfig; github?: IGithubConfig; aliyun?: IAliyunConfig; imgur?: IImgurConfig; transformer?: string; /** for uploader */ proxy?: string; [others: string]: any; }; picgoPlugins: { [pluginName: string]: boolean; }; debug?: boolean; silent?: boolean; settings?: { logLevel?: string[]; logPath?: string; /** for npm */ npmRegistry?: string; /** for npm */ npmProxy?: string; picgoCloud?: { token?: string; [others: string]: any; }; server?: { port?: number; host?: string; enable?: boolean; secret?: string; [others: string]: any; }; [others: string]: any; }; [configOptions: string]: any; } /** * for an uploader/transformer/beforeTransformHandler/beforeUploadHandler/afterUploadHandler */ export interface IPlugin { handle: ((ctx: IPicGo) => Promise) | ((ctx: IPicGo) => void); /** The name of this handler */ name?: string; /** The config of this handler */ config?: (ctx: IPicGo) => IPluginConfig[]; [propName: string]: any; } export type IPluginNameType = 'simple' | 'scope' | 'normal' | 'unknown'; export interface IPluginProcessResult { success: boolean; /** * the package.json's name filed */ pkgName: string; /** * the plugin name or the fs absolute path */ fullName: string; } export interface IPluginHandler { install: (plugins: string[], options: IPluginHandlerOptions, env?: IProcessEnv) => Promise>; update: (plugins: string[], options: IPluginHandlerOptions, env?: IProcessEnv) => Promise>; uninstall: (plugins: string[], env?: IProcessEnv) => Promise>; } export interface IPluginHandlerResult { success: T; body: T extends true ? string[] : string; } export interface IPluginHandlerOptions { npmProxy?: string; npmRegistry?: string; } /** * for picgo npm plugins */ export type IPicGoPlugin = (ctx: IPicGo) => IPicGoPluginInterface; /** * interfaces for PicGo plugin */ export interface IPicGoPluginInterface { /** * since PicGo-Core v1.5, register will inject ctx */ register: (ctx: IPicGo) => void; /** * this plugin's config */ config?: (ctx: IPicGo) => IPluginConfig[]; /** * register uploader name */ uploader?: string; /** * register transformer name */ transformer?: string; /** * for picgo gui plugins */ guiMenu?: (ctx: IPicGo) => IGuiMenuItem[]; /** * for picgo gui plugins * short key -> command */ commands?: (ctx: IPicGo) => ICommandItem[]; [propName: string]: any; } export interface IGuiMenuItem { label: string; handle: (ctx: IPicGo, guiApi: any) => Promise; } export interface ICommandItem { label: string; name: string; key: string; handle: (ctx: IPicGo, guiApi: any) => Promise; } /** * for spawn output */ export interface IResult { code: number; data: string; } /** * for transformer - path */ export interface IImgSize { width: number; height: number; real?: boolean; extname?: string; } /** * for clipboard image */ export interface IClipboardImage { imgPath: string; /** * if the path is generate by picgo -> false * if the path is a real file path in system -> true */ shouldKeepAfterUploading: boolean; } /** * for install command environment variable */ export interface IProcessEnv { [propName: string]: Undefinable; } export type ILogArgvType = string | number; export type ILogArgvTypeWithError = ILogArgvType | Error | unknown; export type Nullable = T | null; export type Undefinable = T | undefined; export interface ILogger { success: (...msg: ILogArgvType[]) => void; info: (...msg: ILogArgvType[]) => void; error: (...msg: ILogArgvTypeWithError[]) => void; warn: (...msg: ILogArgvType[]) => void; debug: (...msg: ILogArgvType[]) => void; } export interface IConfigChangePayload { configName: string; value: T; } export interface ILocale { [key: string]: any; } export interface II18nManager { /** * translate text */ translate: (key: T, args?: IStringKeyMap) => string; /** * add locale to current i18n language * default locale list * - zh-CN * - en */ addLocale: (language: string, locales: ILocale) => boolean; /** * set current language */ setLanguage: (language: string) => void; /** * dynamic add new language & locales */ addLanguage: (language: string, locales: ILocale) => boolean; /** * get language list */ getLanguageList: () => string[]; } export {};