universal-picgo 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/README.md +100 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +21675 -0
  4. package/dist/package.json +53 -0
  5. package/dist/src/core/ExternalPicgo.d.ts +24 -0
  6. package/dist/src/core/Lifecycle.d.ts +15 -0
  7. package/dist/src/core/PicListUploader.d.ts +50 -0
  8. package/dist/src/core/PicListUploader.spec.d.ts +1 -0
  9. package/dist/src/core/UniversalPicGo.d.ts +51 -0
  10. package/dist/src/core/UniversalPicGo.spec.d.ts +1 -0
  11. package/dist/src/db/config/index.d.ts +32 -0
  12. package/dist/src/db/config/index.spec.d.ts +1 -0
  13. package/dist/src/db/externalPicGo/index.d.ts +26 -0
  14. package/dist/src/db/pluginLoder/index.d.ts +24 -0
  15. package/dist/src/headless/UniversalPicGoHeadlessManager.d.ts +24 -0
  16. package/dist/src/headless/UniversalPicGoHeadlessManager.spec.d.ts +1 -0
  17. package/dist/src/headless/index.d.ts +3 -0
  18. package/dist/src/headless/types.d.ts +116 -0
  19. package/dist/src/headless/uploaderSchemas.d.ts +9 -0
  20. package/dist/src/i18n/browserI18nDb.d.ts +16 -0
  21. package/dist/src/i18n/en.d.ts +3 -0
  22. package/dist/src/i18n/index.d.ts +18 -0
  23. package/dist/src/i18n/simpleI18n.d.ts +19 -0
  24. package/dist/src/i18n/zh-CN.d.ts +143 -0
  25. package/dist/src/i18n/zh-TW.d.ts +3 -0
  26. package/dist/src/index.d.ts +25 -0
  27. package/dist/src/index.spec.d.ts +1 -0
  28. package/dist/src/lib/LifecyclePlugins.d.ts +18 -0
  29. package/dist/src/lib/PicGoRequest.d.ts +20 -0
  30. package/dist/src/lib/PicGoRequest.spec.d.ts +1 -0
  31. package/dist/src/lib/PluginHandler.d.ts +20 -0
  32. package/dist/src/lib/PluginLoader.d.ts +29 -0
  33. package/dist/src/plugins/transformer/base64.d.ts +6 -0
  34. package/dist/src/plugins/transformer/index.d.ts +4 -0
  35. package/dist/src/plugins/transformer/path.d.ts +6 -0
  36. package/dist/src/plugins/uploader/aliyun/index.d.ts +3 -0
  37. package/dist/src/plugins/uploader/aliyun/node.d.ts +1 -0
  38. package/dist/src/plugins/uploader/aliyun/web.d.ts +7 -0
  39. package/dist/src/plugins/uploader/aliyun/web.spec.d.ts +1 -0
  40. package/dist/src/plugins/uploader/awss3.d.ts +3 -0
  41. package/dist/src/plugins/uploader/github.d.ts +3 -0
  42. package/dist/src/plugins/uploader/gitlab.d.ts +3 -0
  43. package/dist/src/plugins/uploader/imgur.d.ts +3 -0
  44. package/dist/src/plugins/uploader/index.d.ts +4 -0
  45. package/dist/src/plugins/uploader/lsky/index.d.ts +3 -0
  46. package/dist/src/plugins/uploader/qiniu/digest.d.ts +7 -0
  47. package/dist/src/plugins/uploader/qiniu/index.d.ts +3 -0
  48. package/dist/src/plugins/uploader/qiniu/rs.d.ts +13 -0
  49. package/dist/src/plugins/uploader/qiniu/util.d.ts +8 -0
  50. package/dist/src/plugins/uploader/s3/uploader.d.ts +30 -0
  51. package/dist/src/plugins/uploader/s3/utils.d.ts +8 -0
  52. package/dist/src/plugins/uploader/s3/utils.spec.d.ts +1 -0
  53. package/dist/src/plugins/uploader/smms.d.ts +3 -0
  54. package/dist/src/plugins/uploader/tcyun.d.ts +9 -0
  55. package/dist/src/plugins/uploader/upyun/index.d.ts +3 -0
  56. package/dist/src/utils/CodingUtil.d.ts +39 -0
  57. package/dist/src/utils/CodingUtil.spec.d.ts +1 -0
  58. package/dist/src/utils/browserUtils.d.ts +12 -0
  59. package/dist/src/utils/clipboard/browser.d.ts +4 -0
  60. package/dist/src/utils/clipboard/electron.d.ts +4 -0
  61. package/dist/src/utils/common.d.ts +137 -0
  62. package/dist/src/utils/constants.d.ts +1 -0
  63. package/dist/src/utils/createContext.d.ts +9 -0
  64. package/dist/src/utils/cryptoUtil.d.ts +7 -0
  65. package/dist/src/utils/enums.d.ts +32 -0
  66. package/dist/src/utils/getClipboardImage.d.ts +4 -0
  67. package/dist/src/utils/hashUtil.d.ts +2 -0
  68. package/dist/src/utils/image-size/detector.d.ts +4 -0
  69. package/dist/src/utils/image-size/index.d.ts +12 -0
  70. package/dist/src/utils/image-size/types/bmp.d.ts +3 -0
  71. package/dist/src/utils/image-size/types/cur.d.ts +3 -0
  72. package/dist/src/utils/image-size/types/dds.d.ts +3 -0
  73. package/dist/src/utils/image-size/types/gif.d.ts +3 -0
  74. package/dist/src/utils/image-size/types/heif.d.ts +3 -0
  75. package/dist/src/utils/image-size/types/icns.d.ts +3 -0
  76. package/dist/src/utils/image-size/types/ico.d.ts +3 -0
  77. package/dist/src/utils/image-size/types/index.d.ts +21 -0
  78. package/dist/src/utils/image-size/types/interface.d.ts +15 -0
  79. package/dist/src/utils/image-size/types/j2c.d.ts +3 -0
  80. package/dist/src/utils/image-size/types/jp2.d.ts +3 -0
  81. package/dist/src/utils/image-size/types/jpg.d.ts +3 -0
  82. package/dist/src/utils/image-size/types/ktx.d.ts +3 -0
  83. package/dist/src/utils/image-size/types/png.d.ts +3 -0
  84. package/dist/src/utils/image-size/types/pnm.d.ts +3 -0
  85. package/dist/src/utils/image-size/types/psd.d.ts +3 -0
  86. package/dist/src/utils/image-size/types/svg.d.ts +3 -0
  87. package/dist/src/utils/image-size/types/tga.d.ts +3 -0
  88. package/dist/src/utils/image-size/types/tiff.d.ts +3 -0
  89. package/dist/src/utils/image-size/types/utils.d.ts +17 -0
  90. package/dist/src/utils/image-size/types/webp.d.ts +3 -0
  91. package/dist/src/utils/mimeLookup.d.ts +1 -0
  92. package/dist/src/utils/nodePolyfill.d.ts +4 -0
  93. package/dist/src/utils/nodeUtils.d.ts +31 -0
  94. package/dist/src/utils/os/index.d.ts +3 -0
  95. package/dist/src/utils/os/is-docker/index.d.ts +2 -0
  96. package/dist/src/utils/os/is-inside-container/index.d.ts +1 -0
  97. package/dist/src/utils/os/is-wsl/index.d.ts +2 -0
  98. package/dist/src/utils/pathObject.d.ts +4 -0
  99. package/dist/src/utils/pathObject.spec.d.ts +1 -0
  100. package/dist/src/utils/picgoEventBus.d.ts +4 -0
  101. package/dist/src/utils/pluginRuntime.d.ts +9 -0
  102. package/dist/src/utils/pluginRuntime.spec.d.ts +1 -0
  103. package/dist/vite.config.d.ts +2 -0
  104. package/package.json +2 -2
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "universal-picgo",
3
+ "version": "2.1.1",
4
+ "type": "module",
5
+ "description": "picgo lib for node, browser and electron",
6
+ "main": "./dist/index.js",
7
+ "typings": "./dist/index.d.ts",
8
+ "repository": "terwer/siyuan-plugin-picgo",
9
+ "homepage": "https://github.com/terwer/siyuan-plugin-picgo/tree/main/libs/Universal-PicGo-Core",
10
+ "author": "terwer",
11
+ "license": "MIT",
12
+ "files": [
13
+ "dist",
14
+ "README.md"
15
+ ],
16
+ "keywords": [
17
+ "zhi",
18
+ "lib"
19
+ ],
20
+ "scripts": {
21
+ "serve": "vite",
22
+ "dev": "vite build --watch",
23
+ "build": "vite build",
24
+ "start": "vite preview",
25
+ "test": "npx vitest --watch"
26
+ },
27
+ "devDependencies": {
28
+ "@terwer/eslint-config-custom": "^1.3.6",
29
+ "@terwer/vite-config-custom": "^0.7.6",
30
+ "@types/mime": "^4.0.0",
31
+ "vite-plugin-node-polyfills": "^0.22.0"
32
+ },
33
+ "dependencies": {
34
+ "@aws-sdk/client-s3": "^3.421.0",
35
+ "@aws-sdk/s3-request-presigner": "^3.421.0",
36
+ "@smithy/types": "^3.0.0",
37
+ "@smithy/protocol-http": "^4.0.0",
38
+ "@smithy/querystring-builder": "^3.0.0",
39
+ "@smithy/fetch-http-handler": "^3.0.1",
40
+ "axios": "^1.6.8",
41
+ "dayjs": "^1.11.11",
42
+ "hash.js": "^1.1.7",
43
+ "js-md5": "^0.8.3",
44
+ "js-yaml": "^4.1.0",
45
+ "mime": "^4.0.3",
46
+ "queue": "^7.0.0",
47
+ "universal-picgo-store": "workspace:*",
48
+ "zhi-lib-base": "^0.8.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }
@@ -0,0 +1,24 @@
1
+ import { IImgInfo, IPicGo } from '../types';
2
+ import { default as ExternalPicgoConfigDb } from '../db/externalPicGo';
3
+
4
+ /**
5
+ *外部的PicGO 上传 Api
6
+ *
7
+ * @since 0.6.0
8
+ * @version 1.6.0
9
+ * @author terwer
10
+ */
11
+ declare class ExternalPicgo {
12
+ private logger;
13
+ private requestUrl;
14
+ private readonly endpointUrl;
15
+ db: ExternalPicgoConfigDb;
16
+ constructor(ctx: IPicGo, isDev?: boolean);
17
+ /**
18
+ * 上传图片到PicGO
19
+ *
20
+ * @param input 路径数组,可为空,为空上传剪贴板
21
+ */
22
+ upload(input?: any[]): Promise<IImgInfo[] | Error>;
23
+ }
24
+ export { ExternalPicgo };
@@ -0,0 +1,15 @@
1
+ import { IPicGo } from '../types';
2
+ import { EventEmitter } from '../utils/nodePolyfill';
3
+
4
+ export declare class Lifecycle extends EventEmitter {
5
+ private readonly ctx;
6
+ private readonly logger;
7
+ constructor(ctx: IPicGo);
8
+ start(input: any[]): Promise<IPicGo>;
9
+ private beforeTransform;
10
+ private doTransform;
11
+ private beforeUpload;
12
+ private doUpload;
13
+ private afterUpload;
14
+ private handlePlugins;
15
+ }
@@ -0,0 +1,50 @@
1
+ import { IImgInfo, IPicGo } from '../types';
2
+ import { default as ExternalPicgoConfigDb } from '../db/externalPicGo';
3
+
4
+ /**
5
+ * 远程 PicList 上传 API
6
+ *
7
+ * 对接远程 PicList 容器的图片上传接口。
8
+ * 与本地 ExternalPicgo 不同,此上传器通过 multipart/form-data 直接携带图片二进制数据。
9
+ *
10
+ * 接口规范:
11
+ * - URL: POST {apiUrl}?key={apiKey}
12
+ * - Content-Type: multipart/form-data
13
+ * - Body: file 字段,包含图片文件
14
+ * - 响应: { success: true, result: "https://..." }
15
+ *
16
+ * @author terwer
17
+ */
18
+ declare class PicListUploader {
19
+ private readonly logger;
20
+ readonly db: ExternalPicgoConfigDb;
21
+ constructor(ctx: IPicGo, isDev?: boolean);
22
+ /**
23
+ * 上传图片到远程 PicList 服务
24
+ *
25
+ * @param input 文件路径、URL、Blob 或 File 数组。为空则上传剪贴板(不支持,会抛错)
26
+ * @returns 上传结果数组
27
+ */
28
+ upload(input?: any[]): Promise<IImgInfo[] | Error>;
29
+ /**
30
+ * 检查当前是否配置了 PicList(有远程 URL 和 API Key)
31
+ */
32
+ isPicListConfigured(): boolean;
33
+ /**
34
+ * 将输入项解析为 Blob 和文件名
35
+ */
36
+ private resolveFileData;
37
+ /**
38
+ * Node.js 环境:从文件系统读取图片
39
+ */
40
+ private resolveNodeFilePath;
41
+ /**
42
+ * 浏览器环境:通过 URL 获取图片数据
43
+ */
44
+ private resolveBrowserUrlOrPath;
45
+ /**
46
+ * 构建带 API Key 的请求 URL
47
+ */
48
+ private buildRequestUrl;
49
+ }
50
+ export { PicListUploader };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { PicGoRequestWrapper } from '../lib/PicGoRequest';
2
+ import { PluginHandler } from '../lib/PluginHandler';
3
+ import { IConfig, IHelper, II18nManager, IImgInfo, IPicGo, IPicGoPlugin, IPicGoPluginInterface, IPluginLoader, IStringKeyMap, IUniversalPicGoOptions } from '../types';
4
+ import { EventEmitter } from '../utils/nodePolyfill';
5
+ import { ILogger } from 'zhi-lib-base';
6
+
7
+ declare class UniversalPicGo extends EventEmitter implements IPicGo {
8
+ private _config;
9
+ private lifecycle;
10
+ private db;
11
+ private _pluginLoader;
12
+ configPath: string;
13
+ zhiNpmPath: string;
14
+ baseDir: string;
15
+ pluginBaseDir: string;
16
+ helper: IHelper;
17
+ log: ILogger;
18
+ output: IImgInfo[];
19
+ input: any[];
20
+ pluginHandler: PluginHandler;
21
+ requestWrapper: PicGoRequestWrapper;
22
+ i18n: II18nManager;
23
+ VERSION: string;
24
+ private readonly isDev;
25
+ private readonly usesOptionsObject;
26
+ get pluginLoader(): IPluginLoader;
27
+ getLogger(name?: string): ILogger;
28
+ get request(): PicGoRequestWrapper["PicGoRequest"];
29
+ constructor(options?: IUniversalPicGoOptions);
30
+ constructor(configPath?: string, pluginBaseDir?: string, zhiNpmPath?: string, isDev?: boolean);
31
+ /**
32
+ * easily mannually load a plugin
33
+ * if provide plugin name, will register plugin by name
34
+ * or just instantiate a plugin
35
+ */
36
+ use(plugin: IPicGoPlugin, name?: string): IPicGoPluginInterface;
37
+ getConfig<T>(name?: string, defaultValue?: any): T;
38
+ reloadConfig(): IConfig;
39
+ saveConfig(config: IStringKeyMap<any>): void;
40
+ removeConfig(key: string, propName: string): void;
41
+ setConfig(config: IStringKeyMap<any>): void;
42
+ unsetConfig(key: string, propName: string): void;
43
+ upload(input?: any[]): Promise<IImgInfo[] | Error>;
44
+ private normalizeOptions;
45
+ private getDefautBaseDir;
46
+ private initConfigPath;
47
+ private initZhiNpmPath;
48
+ private initConfig;
49
+ private init;
50
+ }
51
+ export { UniversalPicGo };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import { IJSON } from 'universal-picgo-store';
2
+ import { IConfig, IPicGo, IPicgoDb } from '../../types';
3
+
4
+ declare class ConfigDb implements IPicgoDb<IConfig> {
5
+ private readonly ctx;
6
+ private readonly db;
7
+ readonly key: string;
8
+ readonly initialValue: {
9
+ picBed: {
10
+ uploader: string;
11
+ current: string;
12
+ };
13
+ picgoPlugins: {};
14
+ siyuan: {
15
+ waitTimeout: number;
16
+ retryTimes: number;
17
+ autoUpload: boolean;
18
+ replaceLink: boolean;
19
+ txtImageSwitch: boolean;
20
+ };
21
+ };
22
+ constructor(ctx: IPicGo);
23
+ read(flush?: boolean): IJSON;
24
+ get(key: string): any;
25
+ set(key: string, value: any): void;
26
+ has(key: string): boolean;
27
+ unset(key: string, value: any): boolean;
28
+ saveConfig(config: Partial<IConfig>): void;
29
+ removeConfig(config: IConfig): void;
30
+ safeSet(key: string, value: any): void;
31
+ }
32
+ export default ConfigDb;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { PicgoTypeEnum } from '../../utils/enums';
2
+ import { IJSON } from 'universal-picgo-store';
3
+ import { IExternalPicgoConfig, IPicGo, IPicgoDb } from '../../types';
4
+
5
+ declare class ExternalPicgoConfigDb implements IPicgoDb<IExternalPicgoConfig> {
6
+ private readonly ctx;
7
+ private readonly db;
8
+ readonly key: string;
9
+ readonly initialValue: {
10
+ useBundledPicgo: boolean;
11
+ picgoType: PicgoTypeEnum;
12
+ extPicgoApiUrl: string;
13
+ picListApiUrl: string;
14
+ picListApiKey: string;
15
+ };
16
+ constructor(ctx: IPicGo);
17
+ read(flush?: boolean): IJSON;
18
+ get(key: string): any;
19
+ set(key: string, value: any): void;
20
+ has(key: string): boolean;
21
+ unset(key: string, value: any): boolean;
22
+ saveConfig(config: Partial<IExternalPicgoConfig>): void;
23
+ removeConfig(config: IExternalPicgoConfig): void;
24
+ safeSet(key: string, value: any): void;
25
+ }
26
+ export default ExternalPicgoConfigDb;
@@ -0,0 +1,24 @@
1
+ import { IJSON } from 'universal-picgo-store';
2
+ import { IPicGo, IPicgoDb } from '../../types';
3
+
4
+ declare class PluginLoaderDb implements IPicgoDb<any> {
5
+ private readonly ctx;
6
+ private readonly db;
7
+ readonly key: string;
8
+ readonly initialValue: {
9
+ name: string;
10
+ description: string;
11
+ repository: string;
12
+ license: string;
13
+ };
14
+ constructor(ctx: IPicGo);
15
+ read(flush?: boolean): IJSON;
16
+ get(key: string): any;
17
+ set(key: string, value: any): void;
18
+ has(key: string): boolean;
19
+ unset(key: string, value: any): boolean;
20
+ saveConfig(config: Partial<any>): void;
21
+ removeConfig(config: any): void;
22
+ safeSet(key: string, value: any): void;
23
+ }
24
+ export default PluginLoaderDb;
@@ -0,0 +1,24 @@
1
+ import { IPicGoHeadlessManager, PicGoHeadlessManagerOptions, PicGoHeadlessSaveUploaderConfigOptions, PicGoUploaderConfigSchema, PicGoUploaderListItem, PicGoUploaderSchemaAuditResult, PicGoValidationResult } from './types';
2
+ import { IConfig, IImgInfo, IPicGo } from '../types';
3
+
4
+ declare class UniversalPicGoHeadlessManager implements IPicGoHeadlessManager {
5
+ private readonly ctx;
6
+ constructor(options?: PicGoHeadlessManagerOptions);
7
+ getContext(): IPicGo;
8
+ getConfig(): IConfig;
9
+ getCurrentUploader(): string;
10
+ setCurrentUploader(uploaderId: string): PicGoValidationResult;
11
+ listUploaders(): PicGoUploaderListItem[];
12
+ getUploaderSchema(uploaderId: string): PicGoUploaderConfigSchema;
13
+ getUploaderConfig<T extends Record<string, unknown> = Record<string, unknown>>(uploaderId: string): T;
14
+ validateUploaderConfig(uploaderId: string, config: Record<string, unknown>): PicGoValidationResult;
15
+ saveUploaderConfig(uploaderId: string, config: Record<string, unknown>, options?: PicGoHeadlessSaveUploaderConfigOptions): PicGoValidationResult;
16
+ auditUploaderSchemas(): PicGoUploaderSchemaAuditResult;
17
+ upload(input?: any[]): Promise<IImgInfo[]>;
18
+ private hasUploader;
19
+ private withSchemaDefaults;
20
+ private unknownUploaderResult;
21
+ private unknownUploaderError;
22
+ }
23
+ declare const createPicGoHeadlessManager: (options?: PicGoHeadlessManagerOptions) => UniversalPicGoHeadlessManager;
24
+ export { UniversalPicGoHeadlessManager, createPicGoHeadlessManager };
@@ -0,0 +1,3 @@
1
+ export { UniversalPicGoHeadlessManager, createPicGoHeadlessManager } from './UniversalPicGoHeadlessManager';
2
+ export { BUILT_IN_UPLOADER_IDS, auditBuiltInUploaderSchemas, getPicGoUploaderSchema, isBuiltInUploaderId, listPicGoUploaders, type BuiltInUploaderId, } from './uploaderSchemas';
3
+ export { PICGO_HEADLESS_ERROR_CODES, PicGoHeadlessError, type IPicGoHeadlessManager, type PicGoHeadlessErrorCode, type PicGoHeadlessErrorInput, type PicGoHeadlessManagerOptions, type PicGoHeadlessSaveUploaderConfigOptions, type PicGoUploaderConfigSchema, type PicGoUploaderListItem, type PicGoUploaderSchemaAuditResult, type PicGoUploaderSchemaChoice, type PicGoUploaderSchemaField, type PicGoUploaderSchemaFieldType, type PicGoValidationFieldError, type PicGoValidationResult, } from './types';
@@ -0,0 +1,116 @@
1
+ import { IConfig, IImgInfo, IPicGo, IUniversalPicGoOptions } from '../types';
2
+
3
+ export declare const PICGO_HEADLESS_ERROR_CODES: {
4
+ readonly UNKNOWN_UPLOADER: "UNKNOWN_UPLOADER";
5
+ readonly SCHEMA_UNAVAILABLE: "SCHEMA_UNAVAILABLE";
6
+ readonly UNSUPPORTED_SCHEMA_FIELD: "UNSUPPORTED_SCHEMA_FIELD";
7
+ readonly MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD";
8
+ readonly INVALID_FIELD_TYPE: "INVALID_FIELD_TYPE";
9
+ readonly INVALID_FIELD_CHOICE: "INVALID_FIELD_CHOICE";
10
+ readonly VALIDATION_FAILED: "VALIDATION_FAILED";
11
+ readonly UPLOAD_FAILED: "UPLOAD_FAILED";
12
+ };
13
+ export type PicGoHeadlessErrorCode = (typeof PICGO_HEADLESS_ERROR_CODES)[keyof typeof PICGO_HEADLESS_ERROR_CODES];
14
+ export type PicGoUploaderSchemaFieldType = "input" | "password" | "confirm" | "list";
15
+ export interface PicGoUploaderSchemaChoice {
16
+ label: string;
17
+ value: string;
18
+ }
19
+ export interface PicGoUploaderListItem {
20
+ id: string;
21
+ name: string;
22
+ builtin: boolean;
23
+ schemaAvailable: boolean;
24
+ }
25
+ export interface PicGoUploaderSchemaField {
26
+ name: string;
27
+ type: PicGoUploaderSchemaFieldType;
28
+ label?: string;
29
+ alias?: string;
30
+ message?: string;
31
+ required: boolean;
32
+ default?: unknown;
33
+ valuePath: string;
34
+ sensitive: boolean;
35
+ choices?: PicGoUploaderSchemaChoice[];
36
+ }
37
+ export interface PicGoUploaderConfigSchema {
38
+ id: string;
39
+ name: string;
40
+ builtin: boolean;
41
+ fields: PicGoUploaderSchemaField[];
42
+ }
43
+ export interface PicGoValidationFieldError {
44
+ code: PicGoHeadlessErrorCode;
45
+ uploaderId: string;
46
+ field?: string;
47
+ message: string;
48
+ }
49
+ export interface PicGoValidationResult {
50
+ ok: boolean;
51
+ uploaderId: string;
52
+ errors: PicGoValidationFieldError[];
53
+ }
54
+ export interface PicGoUploaderSchemaAuditResult {
55
+ ok: boolean;
56
+ errors: PicGoValidationFieldError[];
57
+ }
58
+ export interface PicGoHeadlessManagerOptions extends IUniversalPicGoOptions {
59
+ /**
60
+ * Reuse an already initialized PicGo context. When provided, path options are
61
+ * ignored and no new UniversalPicGo instance is created.
62
+ */
63
+ picgo?: IPicGo;
64
+ }
65
+ export interface PicGoHeadlessSaveUploaderConfigOptions {
66
+ /**
67
+ * Also make this uploader the PicGo current uploader after a successful save.
68
+ */
69
+ setCurrent?: boolean;
70
+ /**
71
+ * Validate with the public schema before persisting. Defaults to true.
72
+ */
73
+ validate?: boolean;
74
+ /**
75
+ * Documented raw escape hatch for advanced callers. When true, validation is
76
+ * skipped but the write is still scoped to the target uploader section.
77
+ */
78
+ unsafeRaw?: boolean;
79
+ }
80
+ export interface IPicGoHeadlessManager {
81
+ getContext(): IPicGo;
82
+ getConfig(): IConfig;
83
+ getCurrentUploader(): string;
84
+ setCurrentUploader(uploaderId: string): PicGoValidationResult;
85
+ listUploaders(): PicGoUploaderListItem[];
86
+ getUploaderSchema(uploaderId: string): PicGoUploaderConfigSchema;
87
+ getUploaderConfig<T extends Record<string, unknown> = Record<string, unknown>>(uploaderId: string): T;
88
+ validateUploaderConfig(uploaderId: string, config: Record<string, unknown>): PicGoValidationResult;
89
+ saveUploaderConfig(uploaderId: string, config: Record<string, unknown>, options?: PicGoHeadlessSaveUploaderConfigOptions): PicGoValidationResult;
90
+ auditUploaderSchemas(): PicGoUploaderSchemaAuditResult;
91
+ upload(input?: any[]): Promise<IImgInfo[]>;
92
+ }
93
+ export interface PicGoHeadlessErrorInput {
94
+ code: PicGoHeadlessErrorCode;
95
+ message: string;
96
+ uploaderId?: string;
97
+ field?: string;
98
+ errors?: PicGoValidationFieldError[];
99
+ cause?: unknown;
100
+ }
101
+ export declare class PicGoHeadlessError extends Error {
102
+ readonly code: PicGoHeadlessErrorCode;
103
+ readonly uploaderId?: string;
104
+ readonly field?: string;
105
+ readonly errors?: PicGoValidationFieldError[];
106
+ readonly cause?: unknown;
107
+ constructor(input: PicGoHeadlessErrorInput);
108
+ toJSON(): {
109
+ name: string;
110
+ code: PicGoHeadlessErrorCode;
111
+ message: string;
112
+ uploaderId: string | undefined;
113
+ field: string | undefined;
114
+ errors: PicGoValidationFieldError[] | undefined;
115
+ };
116
+ }
@@ -0,0 +1,9 @@
1
+ import { PicGoUploaderConfigSchema, PicGoUploaderListItem, PicGoUploaderSchemaAuditResult } from './types';
2
+ import { IPicGo } from '../types';
3
+
4
+ export declare const BUILT_IN_UPLOADER_IDS: readonly ["github", "gitlab", "aliyun", "tcyun", "qiniu", "upyun", "smms", "imgur", "awss3", "lsky"];
5
+ export type BuiltInUploaderId = (typeof BUILT_IN_UPLOADER_IDS)[number];
6
+ export declare const isBuiltInUploaderId: (uploaderId: string) => uploaderId is "smms" | "github" | "gitlab" | "aliyun" | "tcyun" | "qiniu" | "upyun" | "imgur" | "awss3" | "lsky";
7
+ export declare const listPicGoUploaders: (ctx: IPicGo) => PicGoUploaderListItem[];
8
+ export declare const getPicGoUploaderSchema: (ctx: IPicGo, uploaderId: string) => PicGoUploaderConfigSchema | undefined;
9
+ export declare const auditBuiltInUploaderSchemas: (ctx: IPicGo) => PicGoUploaderSchemaAuditResult;
@@ -0,0 +1,16 @@
1
+ import { IBrowserLocal, IPicGo } from '../types';
2
+
3
+ declare class BrowserI18nDb {
4
+ private readonly ctx;
5
+ private readonly db;
6
+ private readonly hasRead;
7
+ private readonly i18nKey;
8
+ constructor(ctx: IPicGo);
9
+ read(flush?: boolean): IBrowserLocal[];
10
+ unset(): boolean;
11
+ get(key: string): any;
12
+ set(key: string, value: any): void;
13
+ has(key: string): boolean;
14
+ safeSet(key: string, value: any): void;
15
+ }
16
+ export default BrowserI18nDb;
@@ -0,0 +1,3 @@
1
+ import { ILocales } from './zh-CN';
2
+
3
+ export declare const EN: ILocales;
@@ -0,0 +1,18 @@
1
+ import { ILocalesKey } from './zh-CN';
2
+ import { II18nManager, ILocale, IPicGo, IStringKeyMap } from '../types';
3
+
4
+ declare class I18nManager implements II18nManager {
5
+ private readonly i18n;
6
+ private readonly objectAdapter;
7
+ private readonly ctx;
8
+ private readonly browserI18nDb?;
9
+ constructor(ctx: IPicGo);
10
+ translate<T extends string>(key: ILocalesKey | T, args?: IStringKeyMap<string>): string;
11
+ setLanguage(language: string): void;
12
+ addLocale(language: string, locales: ILocale): boolean;
13
+ addLanguage(language: string, locales: ILocale): boolean;
14
+ getLanguageList(): string[];
15
+ private getOutterI18nFolder;
16
+ private loadOutterI18n;
17
+ }
18
+ export { I18nManager };
@@ -0,0 +1,19 @@
1
+ import { ILocale } from '../types';
2
+
3
+ export declare class ObjectAdapter {
4
+ private locales;
5
+ constructor(locales: Record<string, ILocale>);
6
+ getLocale(language: string): ILocale;
7
+ setLocale(language: string, locales: ILocale): void;
8
+ }
9
+ export declare class I18n {
10
+ private readonly adapter;
11
+ private defaultLanguage;
12
+ private currentLanguage;
13
+ constructor(options: {
14
+ adapter: ObjectAdapter;
15
+ defaultLanguage: string;
16
+ });
17
+ setLanguage(language: string): void;
18
+ translate<T extends string>(phrase: T, args?: Record<string, string>): string | undefined;
19
+ }
@@ -0,0 +1,143 @@
1
+ export declare const ZH_CN: {
2
+ UPLOAD_FAILED: string;
3
+ CHECK_SETTINGS: string;
4
+ CHECK_SETTINGS_AND_NETWORK: string;
5
+ UPLOAD_FAILED_REASON: string;
6
+ SERVER_ERROR: string;
7
+ AUTH_FAILED: string;
8
+ PICBED_SMMS: string;
9
+ PICBED_SMMS_TOKEN: string;
10
+ PICBED_SMMS_BACKUP_DOMAIN: string;
11
+ PICBED_SMMS_MESSAGE_BACKUP_DOMAIN: string;
12
+ PICBED_ALICLOUD: string;
13
+ PICBED_ALICLOUD_ACCESSKEYID: string;
14
+ PICBED_ALICLOUD_ACCESSKEYSECRET: string;
15
+ PICBED_ALICLOUD_BUCKET: string;
16
+ PICBED_ALICLOUD_AREA: string;
17
+ PICBED_ALICLOUD_PATH: string;
18
+ PICBED_ALICLOUD_CUSTOMURL: string;
19
+ PICBED_ALICLOUD_OPTIONS: string;
20
+ PICBED_ALICLOUD_MESSAGE_AREA: string;
21
+ PICBED_ALICLOUD_MESSAGE_PATH: string;
22
+ PICBED_ALICLOUD_MESSAGE_OPTIONS: string;
23
+ PICBED_ALICLOUD_MESSAGE_CUSTOMURL: string;
24
+ PICBED_TENCENTCLOUD: string;
25
+ PICBED_TENCENTCLOUD_VERSION: string;
26
+ PICBED_TENCENTCLOUD_SECRETID: string;
27
+ PICBED_TENCENTCLOUD_SECRETKEY: string;
28
+ PICBED_TENCENTCLOUD_APPID: string;
29
+ PICBED_TENCENTCLOUD_BUCKET: string;
30
+ PICBED_TENCENTCLOUD_AREA: string;
31
+ PICBED_TENCENTCLOUD_ENDPOINT: string;
32
+ PICBED_TENCENTCLOUD_PATH: string;
33
+ PICBED_TENCENTCLOUD_OPTIONS: string;
34
+ PICBED_TENCENTCLOUD_CUSTOMURL: string;
35
+ PICBED_TENCENTCLOUD_SLIM: string;
36
+ PICBED_TENCENTCLOUD_SLIM_TIP: string;
37
+ PICBED_TENCENTCLOUD_SLIM_CONFIRM: string;
38
+ PICBED_TENCENTCLOUD_SLIM_CANCEL: string;
39
+ PICBED_TENCENTCLOUD_MESSAGE_APPID: string;
40
+ PICBED_TENCENTCLOUD_MESSAGE_AREA: string;
41
+ PICBED_TENCENTCLOUD_MESSAGE_ENDPOINT: string;
42
+ PICBED_TENCENTCLOUD_MESSAGE_PATH: string;
43
+ PICBED_TENCENTCLOUD_MESSAGE_CUSTOMURL: string;
44
+ PICBED_TENCENTCLOUD_MESSAGE_OPTIONS: string;
45
+ PICBED_GITHUB: string;
46
+ PICBED_GITHUB_TOKEN: string;
47
+ PICBED_GITHUB_REPO: string;
48
+ PICBED_GITHUB_PATH: string;
49
+ PICBED_GITHUB_BRANCH: string;
50
+ PICBED_GITHUB_CUSTOMURL: string;
51
+ PICBED_GITHUB_MESSAGE_REPO: string;
52
+ PICBED_GITHUB_MESSAGE_BRANCH: string;
53
+ PICBED_GITHUB_MESSAGE_PATH: string;
54
+ PICBED_GITHUB_MESSAGE_CUSTOMURL: string;
55
+ PICBED_GITLAB: string;
56
+ PICBED_GITLAB_URL: string;
57
+ PICBED_GITLAB_TOKEN: string;
58
+ PICBED_GITLAB_REPO: string;
59
+ PICBED_GITLAB_BRANCH: string;
60
+ PICBED_GITLAB_PATH: string;
61
+ PICBED_GITLAB_AUTHOR_MAIL: string;
62
+ PICBED_GITLAB_AUTHOR_NAME: string;
63
+ PICBED_GITLAB_COMMIT_MESSAGE: string;
64
+ PICBED_GITLAB_MESSAGE_URL: string;
65
+ PICBED_GITLAB_MESSAGE_REPO: string;
66
+ PICBED_GITLAB_MESSAGE_BRANCH: string;
67
+ PICBED_QINIU: string;
68
+ PICBED_QINIU_ACCESSKEY: string;
69
+ PICBED_QINIU_SECRETKEY: string;
70
+ PICBED_QINIU_BUCKET: string;
71
+ PICBED_QINIU_PATH: string;
72
+ PICBED_QINIU_URL: string;
73
+ PICBED_QINIU_OPTIONS: string;
74
+ PICBED_QINIU_AREA: string;
75
+ PICBED_QINIU_MESSAGE_PATH: string;
76
+ PICBED_QINIU_MESSAGE_AREA: string;
77
+ PICBED_QINIU_MESSAGE_OPTIONS: string;
78
+ PICBED_QINIU_MESSAGE_URL: string;
79
+ PICBED_IMGUR: string;
80
+ PICBED_IMGUR_CLIENTID: string;
81
+ PICBED_IMGUR_PROXY: string;
82
+ PICBED_IMGUR_MESSAGE_PROXY: string;
83
+ PICBED_UPYUN: string;
84
+ PICBED_UPYUN_BUCKET: string;
85
+ PICBED_UPYUN_OPERATOR: string;
86
+ PICBED_UPYUN_PASSWORD: string;
87
+ PICBED_UPYUN_PATH: string;
88
+ PICBED_UPYUN_URL: string;
89
+ PICBED_UPYUN_OPTIONS: string;
90
+ PICBED_UPYUN_MESSAGE_OPERATOR: string;
91
+ PICBED_UPYUN_MESSAGE_PASSWORD: string;
92
+ PICBED_UPYUN_MESSAGE_URL: string;
93
+ PICBED_UPYUN_MESSAGE_OPTIONS: string;
94
+ PICBED_UPYUN_MESSAGE_PATH: string;
95
+ PICBED_AWSS3PLIST: string;
96
+ PICBED_AWSS3PLIST_ACCESSKEYID: string;
97
+ PICBED_AWSS3PLIST_SECRET_ACCESSKEY: string;
98
+ PICBED_AWSS3PLIST_BUCKET: string;
99
+ PICBED_AWSS3PLIST_REGION: string;
100
+ PICBED_AWSS3PLIST_UPLOADPATH: string;
101
+ PICBED_AWSS3PLIST_ENDPOINT: string;
102
+ PICBED_AWSS3PLIST_CUSTOM_URL: string;
103
+ PICBED_AWSS3PLIST_PATHSTYLEACCESS: string;
104
+ PICBED_AWSS3PLIST_REJECTUNAUTHORIZED: string;
105
+ PICBED_AWSS3PLIST_ACL: string;
106
+ PICBED_AWSS3PLIST_CORS_PROXY: string;
107
+ PICBED_AWSS3PLIST_MESSAGE_ACCESSKEYID: string;
108
+ PICBED_AWSS3PLIST_MESSAGE_SECRET_ACCESSKEY: string;
109
+ PICBED_AWSS3PLIST_MESSAGE_BUCKET: string;
110
+ PICBED_AWSS3PLIST_MESSAGE_REGION: string;
111
+ PICBED_AWSS3PLIST_MESSAGE_UPLOADPATH: string;
112
+ PICBED_AWSS3PLIST_MESSAGE_ENDPOINT: string;
113
+ PICBED_AWSS3PLIST_MESSAGE_CUSTOM_URL: string;
114
+ PICBED_AWSS3PLIST_MESSAGE_PATHSTYLEACCESS: string;
115
+ PICBED_AWSS3PLIST_MESSAGE_REJECTUNAUTHORIZED: string;
116
+ PICBED_AWSS3PLIST_MESSAGE_ACL: string;
117
+ PICBED_AWSS3PLIST_MESSAGE_CORS_PROXY: string;
118
+ PICBED_LSKY: string;
119
+ PICBED_ISKY_SERVER: string;
120
+ PICBED_ISKY_MESSAGE_SERVER: string;
121
+ PICBED_ISKY_EMAIL: string;
122
+ PICBED_ISKY_MESSAGE_EMAIL: string;
123
+ PICBED_ISKY_PASSWORD: string;
124
+ PICBED_ISKY_MESSAGE_PASSWORD: string;
125
+ PICBED_ISKY_STRATEGYID: string;
126
+ PICBED_ISKY_MESSAGE_STRATEGYID: string;
127
+ PLUGIN_HANDLER_PLUGIN_INSTALL_SUCCESS: string;
128
+ PLUGIN_HANDLER_PLUGIN_INSTALL_FAILED: string;
129
+ PLUGIN_HANDLER_PLUGIN_INSTALL_FAILED_REASON: string;
130
+ PLUGIN_HANDLER_PLUGIN_INSTALL_FAILED_PATH: string;
131
+ PLUGIN_HANDLER_PLUGIN_UNINSTALL_SUCCESS: string;
132
+ PLUGIN_HANDLER_PLUGIN_UNINSTALL_FAILED: string;
133
+ PLUGIN_HANDLER_PLUGIN_UNINSTALL_FAILED_REASON: string;
134
+ PLUGIN_HANDLER_PLUGIN_UNINSTALL_FAILED_VALID: string;
135
+ PLUGIN_HANDLER_PLUGIN_UPDATE_SUCCESS: string;
136
+ PLUGIN_HANDLER_PLUGIN_UPDATE_FAILED: string;
137
+ PLUGIN_HANDLER_PLUGIN_UPDATE_FAILED_REASON: string;
138
+ PLUGIN_HANDLER_PLUGIN_UPDATE_FAILED_VALID: string;
139
+ CORS_ANYWHERE_REQUIRED: string;
140
+ CORS_ANYWHERE_REQUIRED_LOCALHOST: string;
141
+ };
142
+ export type ILocalesKey = keyof typeof ZH_CN;
143
+ export type ILocales = typeof ZH_CN;
@@ -0,0 +1,3 @@
1
+ import { ILocales } from './zh-CN';
2
+
3
+ export declare const ZH_TW: ILocales;