universal-picgo 2.0.1 → 3.0.0

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 (32) hide show
  1. package/dist/index.js +7670 -6716
  2. package/dist/package.json +4 -3
  3. package/dist/src/config/DefaultRecognition.d.ts +55 -0
  4. package/dist/src/config/DefaultRecognition.spec.d.ts +1 -0
  5. package/dist/src/config/ExternalPicgoDefaultSurvival.spec.d.ts +1 -0
  6. package/dist/src/config/MaskUtils.d.ts +51 -0
  7. package/dist/src/config/MaskUtils.spec.d.ts +1 -0
  8. package/dist/src/config/SettingsStorePattern.spec.d.ts +1 -0
  9. package/dist/src/config/UnifiedConfigFacade.d.ts +21 -0
  10. package/dist/src/config/UnifiedConfigFacade.integration.spec.d.ts +1 -0
  11. package/dist/src/config/UnifiedConfigFacade.spec.d.ts +1 -0
  12. package/dist/src/config/UnifiedConfigTypes.d.ts +323 -0
  13. package/dist/src/config/UnifiedConfigTypes.spec.d.ts +1 -0
  14. package/dist/src/config/V3MigrationService.d.ts +36 -0
  15. package/dist/src/config/V3MigrationService.spec.d.ts +1 -0
  16. package/dist/src/config/index.d.ts +11 -0
  17. package/dist/src/core/ExternalPicgo.d.ts +4 -4
  18. package/dist/src/core/PicListUploader.d.ts +50 -0
  19. package/dist/src/core/PicListUploader.spec.d.ts +1 -0
  20. package/dist/src/core/UniversalPicGo.d.ts +15 -6
  21. package/dist/src/db/config/index.d.ts +5 -0
  22. package/dist/src/db/externalPicGo/index.d.ts +18 -0
  23. package/dist/src/headless/UniversalPicGoHeadlessManager.d.ts +6 -5
  24. package/dist/src/headless/types.d.ts +5 -5
  25. package/dist/src/headless/uploaderSchemas.d.ts +1 -1
  26. package/dist/src/index.d.ts +3 -1
  27. package/dist/src/lib/PicGoRequest.d.ts +0 -1
  28. package/dist/src/lib/PicGoRequest.spec.d.ts +1 -0
  29. package/dist/src/plugins/uploader/aliyun/web.d.ts +5 -2
  30. package/dist/src/plugins/uploader/aliyun/web.spec.d.ts +1 -0
  31. package/dist/src/utils/common.d.ts +6 -4
  32. package/package.json +4 -3
@@ -1,4 +1,6 @@
1
+ import { ReadyUnifiedPicGoConfigFacade } from '../config';
1
2
  import { PicGoRequestWrapper } from '../lib/PicGoRequest';
3
+ import { StorageAdapter } from 'universal-picgo-store';
2
4
  import { PluginHandler } from '../lib/PluginHandler';
3
5
  import { IConfig, IHelper, II18nManager, IImgInfo, IPicGo, IPicGoPlugin, IPicGoPluginInterface, IPluginLoader, IStringKeyMap, IUniversalPicGoOptions } from '../types';
4
6
  import { EventEmitter } from '../utils/nodePolyfill';
@@ -9,6 +11,8 @@ declare class UniversalPicGo extends EventEmitter implements IPicGo {
9
11
  private lifecycle;
10
12
  private db;
11
13
  private _pluginLoader;
14
+ /** Storage adapter factory from options. Passed to DB constructors. */
15
+ readonly storageAdapterFactory?: (dbPath: string) => StorageAdapter;
12
16
  configPath: string;
13
17
  zhiNpmPath: string;
14
18
  baseDir: string;
@@ -23,19 +27,25 @@ declare class UniversalPicGo extends EventEmitter implements IPicGo {
23
27
  VERSION: string;
24
28
  private readonly isDev;
25
29
  private readonly usesOptionsObject;
30
+ private readyPromise;
31
+ private unifiedConfigFacade?;
26
32
  get pluginLoader(): IPluginLoader;
33
+ get storageMode(): "sync" | "async";
27
34
  getLogger(name?: string): ILogger;
28
35
  get request(): PicGoRequestWrapper["PicGoRequest"];
29
36
  constructor(options?: IUniversalPicGoOptions);
30
37
  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
- */
38
+ /** Async init: wait for config DB from remote storage, then refresh config. */
39
+ private initAsync;
40
+ /** Wait for config and plugins to be ready. */
41
+ init(): Promise<void>;
42
+ attachConfigFacade(facade: ReadyUnifiedPicGoConfigFacade): void;
43
+ getConfigFacade(): ReadyUnifiedPicGoConfigFacade | undefined;
36
44
  use(plugin: IPicGoPlugin, name?: string): IPicGoPluginInterface;
37
45
  getConfig<T>(name?: string, defaultValue?: any): T;
38
46
  reloadConfig(): IConfig;
47
+ reloadConfigAsync(): Promise<IConfig>;
48
+ flushConfig(): Promise<void>;
39
49
  saveConfig(config: IStringKeyMap<any>): void;
40
50
  removeConfig(key: string, propName: string): void;
41
51
  setConfig(config: IStringKeyMap<any>): void;
@@ -46,6 +56,5 @@ declare class UniversalPicGo extends EventEmitter implements IPicGo {
46
56
  private initConfigPath;
47
57
  private initZhiNpmPath;
48
58
  private initConfig;
49
- private init;
50
59
  }
51
60
  export { UniversalPicGo };
@@ -19,6 +19,7 @@ declare class ConfigDb implements IPicgoDb<IConfig> {
19
19
  txtImageSwitch: boolean;
20
20
  };
21
21
  };
22
+ private initReady;
22
23
  constructor(ctx: IPicGo);
23
24
  read(flush?: boolean): IJSON;
24
25
  get(key: string): any;
@@ -27,6 +28,10 @@ declare class ConfigDb implements IPicgoDb<IConfig> {
27
28
  unset(key: string, value: any): boolean;
28
29
  saveConfig(config: Partial<IConfig>): void;
29
30
  removeConfig(config: IConfig): void;
31
+ get isAsync(): boolean;
32
+ ensureReady(): Promise<void>;
33
+ flush(): Promise<void>;
34
+ private doSafeSet;
30
35
  safeSet(key: string, value: any): void;
31
36
  }
32
37
  export default ConfigDb;
@@ -10,7 +10,10 @@ declare class ExternalPicgoConfigDb implements IPicgoDb<IExternalPicgoConfig> {
10
10
  useBundledPicgo: boolean;
11
11
  picgoType: PicgoTypeEnum;
12
12
  extPicgoApiUrl: string;
13
+ picListApiUrl: string;
14
+ picListApiKey: string;
13
15
  };
16
+ private initReady;
14
17
  constructor(ctx: IPicGo);
15
18
  read(flush?: boolean): IJSON;
16
19
  get(key: string): any;
@@ -19,6 +22,21 @@ declare class ExternalPicgoConfigDb implements IPicgoDb<IExternalPicgoConfig> {
19
22
  unset(key: string, value: any): boolean;
20
23
  saveConfig(config: Partial<IExternalPicgoConfig>): void;
21
24
  removeConfig(config: IExternalPicgoConfig): void;
25
+ get isAsync(): boolean;
26
+ /**
27
+ * Wait for async backend to load remote data.
28
+ *
29
+ * PicGo 3.0: Local defaults are seeded immediately in the constructor
30
+ * for UI display. When ensureReady() resolves:
31
+ * - If remote data exists, it replaces the local defaults.
32
+ * - If remote data is missing, local defaults are kept and persisted.
33
+ *
34
+ * This prevents the v2 bug where constructor-time safeSet would
35
+ * overwrite real remote user configuration with generated defaults.
36
+ */
37
+ ensureReady(): Promise<void>;
38
+ flush(): Promise<void>;
39
+ private doSafeSet;
22
40
  safeSet(key: string, value: any): void;
23
41
  }
24
42
  export default ExternalPicgoConfigDb;
@@ -5,17 +5,18 @@ declare class UniversalPicGoHeadlessManager implements IPicGoHeadlessManager {
5
5
  private readonly ctx;
6
6
  constructor(options?: PicGoHeadlessManagerOptions);
7
7
  getContext(): IPicGo;
8
- getConfig(): IConfig;
9
- getCurrentUploader(): string;
10
- setCurrentUploader(uploaderId: string): PicGoValidationResult;
8
+ getConfig(): Promise<IConfig>;
9
+ getCurrentUploader(): Promise<string>;
10
+ setCurrentUploader(uploaderId: string): Promise<PicGoValidationResult>;
11
11
  listUploaders(): PicGoUploaderListItem[];
12
12
  getUploaderSchema(uploaderId: string): PicGoUploaderConfigSchema;
13
- getUploaderConfig<T extends Record<string, unknown> = Record<string, unknown>>(uploaderId: string): T;
13
+ getUploaderConfig<T extends Record<string, unknown> = Record<string, unknown>>(uploaderId: string): Promise<T>;
14
14
  validateUploaderConfig(uploaderId: string, config: Record<string, unknown>): PicGoValidationResult;
15
- saveUploaderConfig(uploaderId: string, config: Record<string, unknown>, options?: PicGoHeadlessSaveUploaderConfigOptions): PicGoValidationResult;
15
+ saveUploaderConfig(uploaderId: string, config: Record<string, unknown>, options?: PicGoHeadlessSaveUploaderConfigOptions): Promise<PicGoValidationResult>;
16
16
  auditUploaderSchemas(): PicGoUploaderSchemaAuditResult;
17
17
  upload(input?: any[]): Promise<IImgInfo[]>;
18
18
  private hasUploader;
19
+ private ensureReady;
19
20
  private withSchemaDefaults;
20
21
  private unknownUploaderResult;
21
22
  private unknownUploaderError;
@@ -79,14 +79,14 @@ export interface PicGoHeadlessSaveUploaderConfigOptions {
79
79
  }
80
80
  export interface IPicGoHeadlessManager {
81
81
  getContext(): IPicGo;
82
- getConfig(): IConfig;
83
- getCurrentUploader(): string;
84
- setCurrentUploader(uploaderId: string): PicGoValidationResult;
82
+ getConfig(): Promise<IConfig>;
83
+ getCurrentUploader(): Promise<string>;
84
+ setCurrentUploader(uploaderId: string): Promise<PicGoValidationResult>;
85
85
  listUploaders(): PicGoUploaderListItem[];
86
86
  getUploaderSchema(uploaderId: string): PicGoUploaderConfigSchema;
87
- getUploaderConfig<T extends Record<string, unknown> = Record<string, unknown>>(uploaderId: string): T;
87
+ getUploaderConfig<T extends Record<string, unknown> = Record<string, unknown>>(uploaderId: string): Promise<T>;
88
88
  validateUploaderConfig(uploaderId: string, config: Record<string, unknown>): PicGoValidationResult;
89
- saveUploaderConfig(uploaderId: string, config: Record<string, unknown>, options?: PicGoHeadlessSaveUploaderConfigOptions): PicGoValidationResult;
89
+ saveUploaderConfig(uploaderId: string, config: Record<string, unknown>, options?: PicGoHeadlessSaveUploaderConfigOptions): Promise<PicGoValidationResult>;
90
90
  auditUploaderSchemas(): PicGoUploaderSchemaAuditResult;
91
91
  upload(input?: any[]): Promise<IImgInfo[]>;
92
92
  }
@@ -3,7 +3,7 @@ import { IPicGo } from '../types';
3
3
 
4
4
  export declare const BUILT_IN_UPLOADER_IDS: readonly ["github", "gitlab", "aliyun", "tcyun", "qiniu", "upyun", "smms", "imgur", "awss3", "lsky"];
5
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";
6
+ export declare const isBuiltInUploaderId: (uploaderId: string) => uploaderId is "smms" | "lsky" | "github" | "gitlab" | "aliyun" | "tcyun" | "qiniu" | "upyun" | "imgur" | "awss3";
7
7
  export declare const listPicGoUploaders: (ctx: IPicGo) => PicGoUploaderListItem[];
8
8
  export declare const getPicGoUploaderSchema: (ctx: IPicGo, uploaderId: string) => PicGoUploaderConfigSchema | undefined;
9
9
  export declare const auditBuiltInUploaderSchemas: (ctx: IPicGo) => PicGoUploaderSchemaAuditResult;
@@ -9,10 +9,11 @@ import { picgoEventBus } from './utils/picgoEventBus';
9
9
  import { default as ExternalPicgoConfigDb } from './db/externalPicGo';
10
10
  import { default as PluginLoaderDb } from './db/pluginLoder';
11
11
  import { default as ConfigDb } from './db/config';
12
+ import { PicListUploader } from './core/PicListUploader';
12
13
  import { ExternalPicgo } from './core/ExternalPicgo';
13
14
  import { UniversalPicGo } from './core/UniversalPicGo';
14
15
 
15
- export { UniversalPicGo, ExternalPicgo, picgoEventBus };
16
+ export { UniversalPicGo, ExternalPicgo, PicListUploader, picgoEventBus };
16
17
  export { UniversalPicGoHeadlessManager, createPicGoHeadlessManager };
17
18
  export { ConfigDb, PluginLoaderDb, ExternalPicgoConfigDb };
18
19
  export { PicgoTypeEnum, IBusEvent };
@@ -20,5 +21,6 @@ export { isFileOrBlob, calculateMD5, isSiyuanProxyAvailable };
20
21
  export { deepMerge, getByPath, setByPath, unsetByPath };
21
22
  export { isElectronRuntime, isPicGoPluginPackageName, isThirdPartyPluginRuntimeAvailable };
22
23
  export { win, currentWin, parentWin, hasNodeEnv };
24
+ export { createUnifiedPicGoConfigFacade, type ConfigDomain, type ReadyUnifiedPicGoConfigFacade, type UnifiedConfigSnapshot, type UnifiedConfigMigrationState, type UnifiedPicGoConfigFacadeOptions, type UnifiedConfigPaths, type PasteTakeoverSnapshot, type SiyuanConfigLike, UNIFIED_CONFIG_MIGRATION_VERSION, ConfigReadError, ConfigFlushError, ConfigNotReadyError, } from './config';
23
25
  export { type IPicGo, type IImgInfo, type IPicgoDb, type IConfig, type IExternalPicgoConfig, type IPicBedType, type IUploaderConfigItem, type IUploaderConfigListItem, type IPluginConfig, type IPicGoPlugin, type IUniversalPicGoOptions, };
24
26
  export { BUILT_IN_UPLOADER_IDS, PICGO_HEADLESS_ERROR_CODES, PicGoHeadlessError, auditBuiltInUploaderSchemas, getPicGoUploaderSchema, isBuiltInUploaderId, listPicGoUploaders, type BuiltInUploaderId, 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 './headless';
@@ -5,7 +5,6 @@ declare class PicGoRequestWrapper {
5
5
  private readonly ctx;
6
6
  private readonly logger;
7
7
  private proxy;
8
- private siyuanProxy;
9
8
  private options;
10
9
  constructor(ctx: IPicGo);
11
10
  private init;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,7 @@
1
- import { IPicGo } from '../../../types';
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { IAliyunConfig, IPicGo } from '../../../types';
2
3
 
4
+ declare const generateSignature: (options: IAliyunConfig, fileName: string, date: string) => string;
5
+ declare const postOptions: (options: IAliyunConfig, fileName: string, signature: string, image: Buffer, date: string) => AxiosRequestConfig;
3
6
  declare const handleWeb: (ctx: IPicGo) => Promise<IPicGo>;
4
- export { handleWeb };
7
+ export { handleWeb, generateSignature, postOptions };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { ILogger } from 'zhi-lib-base';
2
2
  import { Buffer } from './nodePolyfill';
3
3
  import { win } from 'universal-picgo-store';
4
- import { IImgSize, IPathTransformedImgInfo, IPicGo, IPluginNameType, Undefinable } from '../types';
4
+ import { IImgSize, IPathTransformedImgInfo, IPicGo, IPluginNameType } from '../types';
5
5
 
6
6
  export declare const isUrl: (url: string) => boolean;
7
7
  /**
@@ -128,8 +128,10 @@ export declare const getProcessPluginName: (nameOrPath: string, logger: ILogger)
128
128
  */
129
129
  export declare const getNormalPluginName: (nameOrPath: string, logger: ILogger) => string;
130
130
  /**
131
- * 思源笔记代理是否可用
131
+ * 思源笔记内置代理是否可用。
132
132
  *
133
- * @param siyuanProxy
133
+ * 快速路径:`win.siyuan` 全局对象存在(iframe / Electron)→ 直接 true。
134
+ * 回退路径:同域浏览器直开时通过同步 HEAD 请求验证 API 可达性。
134
135
  */
135
- export declare const isSiyuanProxyAvailable: (siyuanProxy: Undefinable<string>) => boolean | "" | undefined;
136
+ export declare const isSiyuanProxyAvailable: () => boolean;
137
+ export declare const getSiyuanProxyUrl: () => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universal-picgo",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "description": "picgo lib for node, browser and electron",
6
6
  "main": "./dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "mime": "^4.0.3",
39
39
  "queue": "^7.0.0",
40
40
  "zhi-lib-base": "^0.8.0",
41
- "universal-picgo-store": "2.0.1"
41
+ "universal-picgo-store": "3.0.0"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"
@@ -48,6 +48,7 @@
48
48
  "dev": "vite build --watch",
49
49
  "build": "vite build",
50
50
  "start": "vite preview",
51
- "test": "npx vitest --watch"
51
+ "test": "vitest run",
52
+ "test:watch": "npx vitest --watch"
52
53
  }
53
54
  }