picgo 2.0.3 → 3.0.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 (54) hide show
  1. package/AGENTS.md +4 -1
  2. package/CLAUDE.md +1 -0
  3. package/CONTEXT.md +53 -0
  4. package/README.md +57 -2
  5. package/dist/core/Lifecycle.d.ts +4 -2
  6. package/dist/core/PicGo.d.ts +2 -2
  7. package/dist/i18n/ja.d.ts +2 -0
  8. package/dist/i18n/ko.d.ts +2 -0
  9. package/dist/i18n/zh-CN.d.ts +62 -0
  10. package/dist/index.cjs.js +1 -1
  11. package/dist/index.cjs.js.map +1 -1
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.esm.js +1 -1
  14. package/dist/index.esm.js.map +1 -1
  15. package/dist/lib/Cloud/ApiErrorCode.d.ts +11 -0
  16. package/dist/lib/Cloud/Request.d.ts +29 -1
  17. package/dist/lib/Cloud/__mocks__/lifecycleScenarios.d.ts +16 -0
  18. package/dist/lib/Cloud/index.d.ts +17 -4
  19. package/dist/lib/Cloud/services/AlbumService.d.ts +39 -0
  20. package/dist/lib/Cloud/services/BillingService.d.ts +9 -0
  21. package/dist/lib/Cloud/services/FileService.d.ts +20 -0
  22. package/dist/lib/Cloud/services/UserService.d.ts +3 -4
  23. package/dist/lib/Cloud/services/multipart/MultipartStorage.d.ts +37 -0
  24. package/dist/lib/Cloud/services/multipart/MultipartUploadService.d.ts +49 -0
  25. package/dist/lib/Cloud/utils.d.ts +8 -1
  26. package/dist/lib/Logger.d.ts +28 -1
  27. package/dist/lib/Server/index.d.ts +3 -0
  28. package/dist/lib/Server/routes.d.ts +3 -1
  29. package/dist/plugins/commander/cloud/actions/configSync.d.ts +7 -0
  30. package/dist/plugins/commander/cloud/actions/index.d.ts +3 -0
  31. package/dist/plugins/commander/cloud/actions/login.d.ts +2 -0
  32. package/dist/plugins/commander/cloud/actions/logout.d.ts +2 -0
  33. package/dist/plugins/commander/cloud/delete.d.ts +4 -0
  34. package/dist/plugins/commander/cloud/get.d.ts +4 -0
  35. package/dist/plugins/commander/cloud/import.d.ts +13 -0
  36. package/dist/plugins/commander/cloud/index.d.ts +3 -0
  37. package/dist/plugins/commander/cloud/list.d.ts +18 -0
  38. package/dist/plugins/commander/cloud/retry.d.ts +4 -0
  39. package/dist/plugins/commander/cloud/shared.d.ts +16 -0
  40. package/dist/plugins/commander/cloud/status.d.ts +16 -0
  41. package/dist/plugins/commander/cloud/update.d.ts +4 -0
  42. package/dist/plugins/commander/get.d.ts +16 -0
  43. package/dist/plugins/commander/upload.d.ts +1 -1
  44. package/dist/plugins/commander/utils/progressRenderer.d.ts +31 -0
  45. package/dist/plugins/uploader/picgoCloud.d.ts +3 -0
  46. package/dist/types/index.d.ts +351 -5
  47. package/dist/types/internal.d.ts +8 -2
  48. package/dist/utils/enum.d.ts +13 -1
  49. package/dist/utils/interfaces.d.ts +23 -1
  50. package/dist/utils/pluginConfig.d.ts +50 -0
  51. package/dist/utils/progressBar.d.ts +11 -0
  52. package/dist/utils/static.d.ts +18 -0
  53. package/dist/utils/uploadWithProgress.d.ts +39 -0
  54. package/package.json +5 -3
@@ -47,9 +47,247 @@ export interface ICloudManager {
47
47
  login: (token?: string) => Promise<void>;
48
48
  logout: () => void;
49
49
  disposeLoginFlow: () => void;
50
- getUserInfo: () => Promise<{
51
- user: string;
52
- } | null>;
50
+ album: ICloudAlbumManager;
51
+ uploader: ICloudUploaderManager;
52
+ getUserInfo: () => Promise<ICloudUserInfo | null>;
53
+ refreshUserInfo: () => Promise<ICloudUserInfo | null>;
54
+ setAutoImport: (autoImport: boolean) => Promise<ICloudUserInfo>;
55
+ getUsage: () => Promise<CloudUsage | null>;
56
+ getBillingOverview: () => Promise<CloudBillingOverview | null>;
57
+ }
58
+ /**
59
+ * Entry point picgo-gui and external plugins use to manage pending multipart upload sessions.
60
+ * The state machine itself (runMultipartUpload) is intentionally not exposed here — uploads
61
+ * should always go through FileService's size dispatch, not bypass it.
62
+ */
63
+ export interface ICloudUploaderManager {
64
+ /** Abort a remote multipart upload; fire-and-forget, errors swallowed (R2 lifecycle backstop). */
65
+ abort: (uploadId: string, objectKey: string) => Promise<void>;
66
+ /** List every pending multipart session for the current user (local state only). */
67
+ listPending: () => MultipartSession[];
68
+ /** Delete only the local entry (use abort() to also notify the remote). */
69
+ removePending: (fingerprint: string) => void;
70
+ }
71
+ export interface ICloudUserInfo {
72
+ user: string | null;
73
+ avatar?: string | null;
74
+ plan?: number;
75
+ autoImport?: boolean;
76
+ }
77
+ export type CloudUsageDimension = {
78
+ used: number;
79
+ limit: number | null;
80
+ };
81
+ export type CloudUsagePeriodInfo = {
82
+ used: number;
83
+ periodStart: string | null;
84
+ periodEnd: string | null;
85
+ };
86
+ export type CloudUsageConfigHistory = {
87
+ used: number;
88
+ limit: number;
89
+ appType: 'gui' | 'cli';
90
+ };
91
+ export type CloudUsage = {
92
+ /** Paid plan code(用于展示)。 */
93
+ plan: string;
94
+ /**
95
+ * 当前生效配额对应的 plan code(capabilityPlan)。grace/frozen/pending_cleanup
96
+ * 阶段会降级为 'free',此时 effectiveQuotaPlan !== plan。
97
+ */
98
+ effectiveQuotaPlan: string;
99
+ storage: CloudUsageDimension;
100
+ mediaCount: CloudUsageDimension;
101
+ monthlyServes: CloudUsagePeriodInfo;
102
+ configHistory: CloudUsageConfigHistory;
103
+ };
104
+ export type CloudBillingPlanInfo = {
105
+ /** 来自 entitlement 的付费 plan code,用于展示 / billing portal。 */
106
+ paid: string;
107
+ /** 用于 capability / 配额检查的 plan code(admin grant + entitlement 合并结果)。 */
108
+ capability: string;
109
+ /** 订阅计费周期类型:'monthly' / 'yearly' / null(免费用户)。 */
110
+ billingPeriod: string | null;
111
+ source: 'entitlement' | 'admin_grant' | 'both' | 'free';
112
+ };
113
+ export type CloudLifecyclePhase = 'active' | 'grace' | 'frozen' | 'pending_cleanup';
114
+ export type CloudLifecycleFlags = {
115
+ customDomainDisabledByLifecycle: boolean;
116
+ autoImportDisabledByLifecycle: boolean;
117
+ };
118
+ export type CloudLifecycleInfo = {
119
+ phase: CloudLifecyclePhase;
120
+ daysRemaining: number | null;
121
+ graceEndsAt: string | null;
122
+ freezeEndsAt: string | null;
123
+ /**
124
+ * 当前 lifecycle phase 结束时间。客户端用此字段统一展示套餐到期:
125
+ * - active → max(activeEnt.validUntil, grant.validUntil);永久 entitlement 为 null
126
+ * - grace → 等同 graceEndsAt
127
+ * - frozen → 等同 freezeEndsAt
128
+ * - pending_cleanup → null
129
+ */
130
+ currentPhaseEndsAt: string | null;
131
+ flags: CloudLifecycleFlags;
132
+ };
133
+ export type CloudSubscriptionInfo = {
134
+ status: string;
135
+ currentPeriodEnd: string | null;
136
+ };
137
+ export type CloudBillingOverview = {
138
+ plan: CloudBillingPlanInfo;
139
+ lifecycle: CloudLifecycleInfo;
140
+ subscription: CloudSubscriptionInfo | null;
141
+ };
142
+ export type ImportResult = {
143
+ total: number;
144
+ created: number;
145
+ skipped: number;
146
+ invalid: number;
147
+ failed: number;
148
+ pending: number;
149
+ items: IImgInfo[];
150
+ };
151
+ /**
152
+ * Generic progress base — the minimal common fields shared by every progress event payload.
153
+ * Consumers that only care about the ratio (CLI progress bar, future GUI progress widget) can
154
+ * read these three fields directly without having to discriminate on event type.
155
+ */
156
+ export type IProgress = {
157
+ /**
158
+ * Current progress count. Unit depends on the event:
159
+ * - `FILE_UPLOAD_PROGRESS` → bytes uploaded so far
160
+ * - `CLOUD_IMPORT_PROGRESS` → items processed so far
161
+ */
162
+ current: number;
163
+ /** Target total, same unit as current. */
164
+ total: number;
165
+ /** current / total clipped to [0, 1]. Provided so consumers don't have to divide. 0 when total is 0. */
166
+ fraction: number;
167
+ };
168
+ /**
169
+ * Per-file byte-level upload progress for the `FILE_UPLOAD_PROGRESS` event.
170
+ * current / total are bytes; multipart uploads also fill partsCompleted / totalParts,
171
+ * non-multipart paths use -1 to signal N/A.
172
+ */
173
+ export type IFileUploadProgress = IProgress & {
174
+ /** The file name currently being uploaded (= IImgInfo.fileName; lets consumers disambiguate multi-file flows). */
175
+ fileName: string;
176
+ /** Multipart: number of parts already completed. Non-multipart path uses -1. */
177
+ partsCompleted: number;
178
+ /** Multipart: total part count. Non-multipart path uses -1. */
179
+ totalParts: number;
180
+ /** Whether this is a resumed upload (multipart only). Always false on the non-resume path. */
181
+ resumed: boolean;
182
+ };
183
+ export type CloudImportProgress = IProgress & {
184
+ batchIndex: number;
185
+ batchTotal: number;
186
+ created: number;
187
+ skipped: number;
188
+ failed: number;
189
+ };
190
+ /**
191
+ * Metadata for a single multipart part. partNumber is 1-based; url is a server-presigned
192
+ * R2 endpoint the client PUTs the part bytes to.
193
+ */
194
+ export type MultipartPartInfo = {
195
+ partNumber: number;
196
+ url: string;
197
+ method: 'PUT';
198
+ headers: Record<string, string>;
199
+ };
200
+ /**
201
+ * Minimal record the client keeps after a single part finishes uploading.
202
+ * partNumber is 1-based; etag comes from the part PUT response header.
203
+ */
204
+ export type MultipartCompletedPart = {
205
+ partNumber: number;
206
+ etag: string;
207
+ };
208
+ /**
209
+ * Locally persisted multipart upload session. Drives resume across process crashes / restarts.
210
+ * `v` is a schema version field for future migrations.
211
+ */
212
+ export type MultipartSession = {
213
+ /** Schema version, currently 1. */
214
+ v: 1;
215
+ uploadId: string;
216
+ objectKey: string;
217
+ publicId: string;
218
+ url: string;
219
+ filename: string;
220
+ /** Total bytes. */
221
+ size: number;
222
+ contentType: string;
223
+ /** Per-part size (the last part may be smaller). */
224
+ partSize: number;
225
+ /** Total part count = Math.ceil(size / partSize). */
226
+ partCount: number;
227
+ /** Parts already finished, with their server-returned ETag, ready to submit at complete time. */
228
+ completedParts: MultipartCompletedPart[];
229
+ /** Epoch ms used for the 7-day TTL sweep. */
230
+ createdAt: number;
231
+ };
232
+ export declare enum AlbumListOrder {
233
+ ASC = "asc",
234
+ DESC = "desc"
235
+ }
236
+ export declare enum AlbumListSort {
237
+ NEWEST = "newest",
238
+ OLDEST = "oldest",
239
+ FILE_NAME = "fileName"
240
+ }
241
+ export type AlbumListQuery = {
242
+ contentType?: string;
243
+ type?: string;
244
+ ext?: string;
245
+ search?: string;
246
+ fileName?: string;
247
+ limit?: number;
248
+ offset?: number;
249
+ sort?: AlbumListSort | string;
250
+ order?: AlbumListOrder;
251
+ };
252
+ export type AlbumListResponse<T = IImgInfo> = {
253
+ success: boolean;
254
+ items: T[];
255
+ total: number;
256
+ limit: number;
257
+ offset: number;
258
+ };
259
+ export type AlbumFiltersResponse = {
260
+ success: boolean;
261
+ contentTypes: string[];
262
+ exts: string[];
263
+ };
264
+ export type BatchUpdateResult = {
265
+ updated: number;
266
+ skipped: number;
267
+ items: IImgInfo[];
268
+ };
269
+ export type AlbumStatsResponse = {
270
+ total: number;
271
+ types: {
272
+ type: string;
273
+ count: number;
274
+ }[];
275
+ };
276
+ export interface ICloudAlbumManager {
277
+ import: (items: IImgInfo[]) => Promise<ImportResult>;
278
+ list: (query?: AlbumListQuery) => Promise<AlbumListResponse>;
279
+ get: (id: string) => Promise<IImgInfo>;
280
+ update: (id: string, data: Partial<IImgInfo>) => Promise<IImgInfo>;
281
+ batchUpdate: (items: {
282
+ id: string;
283
+ data: Partial<IImgInfo>;
284
+ }[]) => Promise<BatchUpdateResult>;
285
+ delete: (id: string | string[]) => Promise<void>;
286
+ getStats: () => Promise<AlbumStatsResponse>;
287
+ getFilters: () => Promise<AlbumFiltersResponse>;
288
+ getPending: () => Promise<IImgInfo[]>;
289
+ addToPending: (items: IImgInfo[]) => Promise<IImgInfo[]>;
290
+ retryPending: () => Promise<ImportResult>;
53
291
  }
54
292
  export interface IPicGo extends NodeJS.EventEmitter {
55
293
  /**
@@ -157,7 +395,15 @@ export interface IPicGo extends NodeJS.EventEmitter {
157
395
  /**
158
396
  * upload gogogo
159
397
  */
160
- upload: (input?: any[]) => Promise<IImgInfo[] | Error>;
398
+ upload: (input?: any[], options?: UploadOptions) => Promise<IImgInfo[] | Error>;
399
+ }
400
+ export declare enum OutputFormat {
401
+ PRETTY = "pretty",
402
+ JSON = "json"
403
+ }
404
+ export interface UploadOptions {
405
+ /** Output format for the success message. Defaults to 'pretty'. */
406
+ outputFormat?: OutputFormat;
161
407
  }
162
408
  export interface IUploaderConfigItem {
163
409
  _id: string;
@@ -180,14 +426,97 @@ export interface IUploaderConfigManager {
180
426
  rename: (type: string, oldName: string, newName: string) => IUploaderConfigItem;
181
427
  remove: (type: string, configName: string) => void;
182
428
  }
429
+ /**
430
+ * Snapshot of the currently displayed values for all fields in a plugin config form.
431
+ *
432
+ * Passed to function-form `choices` / `default` so reactive fields can derive
433
+ * their value space from other fields. In the GUI this is the form's merged
434
+ * view (stored config + schema defaults + user edits); in the CLI this is
435
+ * inquirer's accumulated `answers`.
436
+ */
437
+ export type PluginConfigAnswers = Record<string, unknown>;
438
+ /**
439
+ * One choice for a `list` / `checkbox` field. May be a bare string (used as
440
+ * both label and value) or an object form.
441
+ */
442
+ export type IPluginConfigChoice = string | {
443
+ name?: string;
444
+ value: unknown;
445
+ checked?: boolean;
446
+ };
183
447
  /**
184
448
  * for plugin config
449
+ *
450
+ * @example Reactive cascading dropdown
451
+ * const config = (ctx) => [
452
+ * { name: 'uploader', type: 'list', required: true, choices: ['github', 'gitee'] },
453
+ * {
454
+ * name: 'repo',
455
+ * type: 'list',
456
+ * required: true,
457
+ * dependsOn: ['uploader'],
458
+ * choices: (answers) => {
459
+ * return answers.uploader === 'github'
460
+ * ? ['my-org/repo-a', 'my-org/repo-b']
461
+ * : ['gitee-org/repo-c']
462
+ * }
463
+ * }
464
+ * ]
465
+ *
466
+ * @example Multi-line text via `type: 'editor'` (3.0.0+)
467
+ * const config = (ctx) => [
468
+ * {
469
+ * name: 'script',
470
+ * type: 'editor',
471
+ * alias: 'Compression script',
472
+ * required: true,
473
+ * message: 'Enter your compression script (multi-line supported)'
474
+ * }
475
+ * ]
185
476
  */
186
477
  export interface IPluginConfig {
187
478
  name: string;
479
+ /**
480
+ * Field widget kind. The string is forwarded to inquirer in the CLI path and
481
+ * used by the GUI renderer to pick a control. Kept as `string` so plugin
482
+ * authors can pass through any inquirer-supported value PicGo has not
483
+ * documented. PicGo guarantees behavior for these known values:
484
+ *
485
+ * - `'input'` single-line text. CLI: inquirer text prompt; GUI: text input.
486
+ * - `'password'` single-line text rendered masked. CLI: inquirer password
487
+ * prompt; GUI: password input with show/hide toggle.
488
+ * - `'list'` pick one from `choices`. CLI: inquirer list prompt; GUI:
489
+ * single-select dropdown.
490
+ * - `'checkbox'` pick many from `choices`. CLI: inquirer checkbox prompt;
491
+ * GUI: multi-select combobox.
492
+ * - `'confirm'` boolean. CLI: inquirer confirm prompt; GUI: switch.
493
+ * - `'editor'` multi-line text (3.0.0+). Value is a `string` and MAY
494
+ * contain `\n`. CLI: inquirer editor prompt — spawns the
495
+ * user's external editor via `VISUAL` / `EDITOR` env vars
496
+ * (falls back to platform default: `vi` / `nano` on Unix,
497
+ * `notepad` on Windows); GUI: shadcn `<Textarea>` with
498
+ * user-resizable height.
499
+ */
188
500
  type: string;
189
501
  required: boolean;
190
- default?: any;
502
+ /**
503
+ * Default value for the field. May be a plain value or a function that
504
+ * receives the current `answers` snapshot and returns the value.
505
+ */
506
+ default?: any | ((answers: PluginConfigAnswers) => any);
507
+ /**
508
+ * Available options for `list` / `checkbox` fields. May be a static array
509
+ * or a function that receives the current `answers` snapshot and returns
510
+ * the array.
511
+ */
512
+ choices?: IPluginConfigChoice[] | ((answers: PluginConfigAnswers) => IPluginConfigChoice[]);
513
+ /**
514
+ * Names of other fields in the same schema this field's `choices` /
515
+ * `default` depends on. When any listed field's value changes, the GUI
516
+ * will re-evaluate this field. Has no effect in the CLI path (inquirer
517
+ * already passes the latest `answers` to every prompt).
518
+ */
519
+ dependsOn?: string[];
191
520
  alias?: string;
192
521
  message?: string;
193
522
  prefix?: string;
@@ -210,6 +539,7 @@ export interface IHelper {
210
539
  beforeTransformPlugins: ILifecyclePlugins;
211
540
  beforeUploadPlugins: ILifecyclePlugins;
212
541
  afterUploadPlugins: ILifecyclePlugins;
542
+ afterFinishPlugins: ILifecyclePlugins;
213
543
  }
214
544
  export interface ICommander extends ILifecyclePlugins {
215
545
  program: Command;
@@ -311,6 +641,7 @@ export type ILogColor = 'blue' | 'green' | 'yellow' | 'red';
311
641
  * for uploading image info
312
642
  */
313
643
  export interface IImgInfo {
644
+ id?: string;
314
645
  buffer?: Buffer;
315
646
  base64Image?: string;
316
647
  fileName?: string;
@@ -318,10 +649,20 @@ export interface IImgInfo {
318
649
  height?: number;
319
650
  extname?: string;
320
651
  imgUrl?: string;
652
+ /**
653
+ * if the imgUrl has been overwrite by url rewrite rule, then originImgUrl is the original url before rewrite
654
+ */
321
655
  originImgUrl?: string;
656
+ /** @deprecated use `contentType` */
322
657
  mimeType?: string;
658
+ _importToPicGoCloud?: boolean;
659
+ contentType?: string;
323
660
  filePath?: string;
324
661
  size?: number;
662
+ createdAt?: number | string | Date;
663
+ updatedAt?: number | string | Date;
664
+ /** the origin input of the image, before any processing or uploading */
665
+ origin?: string;
325
666
  [propName: string]: any;
326
667
  }
327
668
  export interface IUrlRewriteRule {
@@ -600,6 +941,11 @@ export interface ILogger {
600
941
  error: (...msg: ILogArgvTypeWithError[]) => void;
601
942
  warn: (...msg: ILogArgvType[]) => void;
602
943
  debug: (...msg: ILogArgvType[]) => void;
944
+ createLogger?: (options?: {
945
+ logPath?: string;
946
+ consoleOutput?: boolean;
947
+ respectSilent?: boolean;
948
+ }) => ILogger;
603
949
  }
604
950
  export interface IConfigChangePayload<T> {
605
951
  configName: string;
@@ -1,8 +1,14 @@
1
- import { Env, Handler } from "hono";
2
- import { IServerManager } from ".";
1
+ import { Env, Handler } from 'hono';
2
+ import { IImgInfo, IServerManager } from '.';
3
+ export interface IServerUploadAdapter {
4
+ uploadClipboard: () => Promise<IImgInfo[] | Error>;
5
+ uploadPaths: (paths: string[]) => Promise<IImgInfo[] | Error>;
6
+ getTempDir?: () => string;
7
+ }
3
8
  export interface IInternalServerManager<E extends Env = any> extends IServerManager<E> {
4
9
  registerGet<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
5
10
  registerPost<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
6
11
  registerPut<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
7
12
  registerDelete<P extends string>(path: P, handler: Handler<E, P>, isInternal?: boolean): void;
13
+ setUploadAdapter(adapter?: IServerUploadAdapter): void;
8
14
  }
@@ -2,23 +2,35 @@ export declare enum ILogType {
2
2
  success = "success",
3
3
  info = "info",
4
4
  warn = "warn",
5
- error = "error"
5
+ error = "error",
6
+ debug = "debug"
6
7
  }
7
8
  /**
8
9
  * these events will be caught by users
9
10
  */
10
11
  export declare enum IBuildInEvent {
11
12
  UPLOAD_PROGRESS = "uploadProgress",
13
+ FILE_UPLOAD_PROGRESS = "fileUploadProgress",
12
14
  FAILED = "failed",
13
15
  BEFORE_TRANSFORM = "beforeTransform",
14
16
  BEFORE_UPLOAD = "beforeUpload",
15
17
  AFTER_UPLOAD = "afterUpload",
18
+ CLOUD_IMPORT_PROGRESS = "cloudImportProgress",
19
+ CLOUD_ALBUM_UPDATED = "cloudAlbumUpdated",
16
20
  FINISHED = "finished",
17
21
  INSTALL = "install",
18
22
  UNINSTALL = "uninstall",
19
23
  UPDATE = "update",
20
24
  NOTIFICATION = "notification"
21
25
  }
26
+ export declare enum LifecycleStep {
27
+ IDLE = "idle",
28
+ BEFORE_TRANSFORM = "beforeTransform",
29
+ TRANSFORM = "transform",
30
+ BEFORE_UPLOAD = "beforeUpload",
31
+ UPLOAD = "upload",
32
+ AFTER_UPLOAD = "afterUpload"
33
+ }
22
34
  /**
23
35
  * these events will be caught only by picgo
24
36
  */
@@ -1,14 +1,30 @@
1
1
  /** This file is deprecated */
2
2
  import { PicGo } from '../core/PicGo';
3
3
  import LifecyclePlugins from '../lib/LifecyclePlugins';
4
+ /**
5
+ * Snapshot of the currently displayed values for all fields in a plugin config form.
6
+ * See `src/types/index.ts` for canonical documentation.
7
+ */
8
+ export type PluginConfigAnswers = Record<string, unknown>;
9
+ export type IPluginConfigChoice = string | {
10
+ name?: string;
11
+ value: unknown;
12
+ checked?: boolean;
13
+ };
4
14
  /**
5
15
  * for plugin config
16
+ *
17
+ * See `src/types/index.ts` for canonical documentation including the list of
18
+ * known `type` values (`'input' | 'password' | 'list' | 'checkbox' |
19
+ * 'confirm' | 'editor'`) and reactive `choices` / `default` examples.
6
20
  */
7
21
  export interface IPluginConfig {
8
22
  name: string;
9
23
  type: string;
10
24
  required: boolean;
11
- default?: any;
25
+ default?: any | ((answers: PluginConfigAnswers) => any);
26
+ choices?: IPluginConfigChoice[] | ((answers: PluginConfigAnswers) => IPluginConfigChoice[]);
27
+ dependsOn?: string[];
12
28
  [propName: string]: any;
13
29
  }
14
30
  /**
@@ -20,17 +36,23 @@ export interface IHelper {
20
36
  beforeTransformPlugins: LifecyclePlugins;
21
37
  beforeUploadPlugins: LifecyclePlugins;
22
38
  afterUploadPlugins: LifecyclePlugins;
39
+ afterFinishPlugins: LifecyclePlugins;
23
40
  }
24
41
  /**
25
42
  * for uploading image info
26
43
  */
27
44
  export interface IImgInfo {
45
+ id?: string;
28
46
  buffer?: Buffer;
29
47
  base64Image?: string;
30
48
  fileName?: string;
31
49
  width?: number;
32
50
  height?: number;
33
51
  extname?: string;
52
+ contentType?: string;
53
+ mimeType?: string;
54
+ createdAt?: number | string | Date;
55
+ updatedAt?: number | string | Date;
34
56
  [propName: string]: any;
35
57
  }
36
58
  export interface IPathTransformedImgInfo extends IImgInfo {
@@ -0,0 +1,50 @@
1
+ import { IPluginConfig, PluginConfigAnswers } from '../types';
2
+ interface EvaluatePluginConfigOptions {
3
+ /**
4
+ * Optional logger callback invoked when a `choices` or `default` function
5
+ * throws. The runtime can wire this to `ctx.log.warn` so degraded fields
6
+ * are visible. Receives `(fieldName, kind, error)`.
7
+ */
8
+ onError?: (fieldName: string, kind: 'choices' | 'default', error: unknown) => void;
9
+ }
10
+ /**
11
+ * Evaluate a Plugin Config Schema, resolving function-form `choices` and
12
+ * `default` against the given `answers` snapshot. Pure: never mutates the
13
+ * input schema or its field objects.
14
+ *
15
+ * Used by:
16
+ * - CLI: ideally as a no-op pass before handing the schema to inquirer
17
+ * (today the CLI relies on inquirer to evaluate the functions itself,
18
+ * so calling this without `answers` is safe and equivalent).
19
+ * - GUI: called twice — once at schema serialization (no `answers`) and
20
+ * again on reactive refresh (with the current form's value snapshot).
21
+ *
22
+ * @param schema the raw schema returned by `plugin.config(ctx)`
23
+ * @param answers field-value snapshot to pass to function-form choices/default
24
+ * (defaults to `{}` so functions that don't read answers are
25
+ * still safe to call)
26
+ * @param options optional error reporter
27
+ * @returns a new array of resolved IPluginConfig items
28
+ */
29
+ export declare function evaluatePluginConfig(schema: IPluginConfig[], answers?: PluginConfigAnswers, options?: EvaluatePluginConfigOptions): IPluginConfig[];
30
+ interface WrapPluginConfigForCliOptions {
31
+ /**
32
+ * Optional logger callback invoked when a `choices` or `default` function
33
+ * throws during inquirer evaluation. Receives `(fieldName, kind, error)`.
34
+ */
35
+ onError?: (fieldName: string, kind: 'choices' | 'default', error: unknown) => void;
36
+ }
37
+ /**
38
+ * Lazily wrap function-form `choices` / `default` with a try/catch so a
39
+ * single throwing field doesn't kill the entire inquirer prompt chain on
40
+ * the CLI side.
41
+ *
42
+ * Unlike `evaluatePluginConfig`, this does NOT eagerly invoke the
43
+ * functions — it preserves the function form so inquirer can still call
44
+ * them lazily with the latest accumulated `answers`. CLI cascade
45
+ * semantics are therefore unchanged. A throwing field degrades to
46
+ * `choices: []` / `default: undefined`, mirroring the GUI's field-level
47
+ * isolation guarantee provided by `evaluatePluginConfig`.
48
+ */
49
+ export declare function wrapPluginConfigForCli(schema: IPluginConfig[], options?: WrapPluginConfigForCliOptions): IPluginConfig[];
50
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Render a fixed 20-character progress bar (`█████░░░░░`).
3
+ *
4
+ * - `total <= 0` returns all-empty (`░ × 20`); the caller is responsible for any N/A label.
5
+ * - `current >= total` returns all-filled (`█ × 20`); never overflows.
6
+ * - Intermediate states round to the nearest cell based on `current / total`.
7
+ *
8
+ * Pure function with no external state — shared across the CLI (import progress, file
9
+ * upload progress, future progress events).
10
+ */
11
+ export declare const renderProgressBar: (current: number, total: number) => string;
@@ -1 +1,19 @@
1
1
  export declare const CLIPBOARD_IMAGE_FOLDER = "picgo-clipboard-images";
2
+ export declare const PICGO_CLOUD = "picgo-cloud";
3
+ export declare const PICGO_CLOUD_IMPORT_LOG_FILE = "picgo-cloud-import-list.log";
4
+ export declare const PICGO_CLOUD_IMPORT_PENDING_FILE = "picgo-cloud-import-list-pending.json";
5
+ export declare const PICGO_CLOUD_AUTO_IMPORT_PLUGIN = "picgoCloudAutoImport";
6
+ export declare const PICGO_CLOUD_MULTIPART_PENDING_FILE = "picgo-cloud-multipart-pending.json";
7
+ /** Bytes per megabyte. Reused by anything that formats / compares file sizes. */
8
+ export declare const BYTES_PER_MB: number;
9
+ /**
10
+ * Size threshold for multipart upload. Files >= this go through the multipart path; smaller
11
+ * files keep the single-PUT path. Must stay aligned with picgo-hub's MULTIPART_THRESHOLD_BYTES.
12
+ */
13
+ export declare const MULTIPART_THRESHOLD_BYTES: number;
14
+ /**
15
+ * Part size for multipart upload. R2/S3 require each part >= 5 MB (last part exempt),
16
+ * max 5 GB per part, max 10000 parts per upload. 8 MB × 128 = 1024 MB covers the 1 GB
17
+ * per-file ceiling with a comfortable retry granularity.
18
+ */
19
+ export declare const MULTIPART_PART_SIZE_BYTES: number;
@@ -0,0 +1,39 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import type { IOldReqOptions, IPicGo } from '../types';
3
+ /**
4
+ * Meta info for an `uploadWithProgress` call. `fileName` is required (consumers use it to
5
+ * disambiguate concurrent uploads); the rest are optional and default to the "non-multipart"
6
+ * placeholders.
7
+ */
8
+ export interface IUploadProgressMeta {
9
+ /** The file name currently being uploaded (i.e. IImgInfo.fileName). */
10
+ fileName: string;
11
+ /**
12
+ * Total bytes for this upload. Axios usually fills `total` in its progress event, but some
13
+ * transports (notably SDK-wrapped requests) don't — in that case the helper falls back to
14
+ * meta.totalBytes. If neither is available, emitted payloads use total = 0, fraction = 0.
15
+ */
16
+ totalBytes?: number;
17
+ /** Multipart-only: whether this upload is a resumed session. Defaults to false. */
18
+ resumed?: boolean;
19
+ /** Multipart-only: number of parts already completed. Defaults to -1 (N/A). */
20
+ partsCompleted?: number;
21
+ /** Multipart-only: total part count. Defaults to -1 (N/A). */
22
+ totalParts?: number;
23
+ }
24
+ type SupportedConfig = AxiosRequestConfig | IOldReqOptions;
25
+ /**
26
+ * Thin wrapper around `ctx.request` that injects axios's `onUploadProgress` hook and emits
27
+ * `IBuildInEvent.FILE_UPLOAD_PROGRESS` events as bytes flow out. Pass-through return type
28
+ * matches `ctx.request` exactly.
29
+ *
30
+ * Intent: establish a single convention for "emit progress while uploading" — built-in uploaders
31
+ * and external plugins can drop in a one-line replacement:
32
+ * `await ctx.request(opts)` → `await uploadWithProgress(ctx, opts, { fileName })`.
33
+ *
34
+ * Multipart's state machine does NOT use this helper. Per-part progress is emitted directly
35
+ * from the runner so it can include multipart-only fields (partsCompleted, resumed). This
36
+ * helper serves the simpler "one PUT/POST = one file" case.
37
+ */
38
+ export declare function uploadWithProgress<T>(ctx: IPicGo, options: SupportedConfig, meta: IUploadProgressMeta): Promise<T>;
39
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picgo",
3
- "version": "2.0.3",
3
+ "version": "3.0.1",
4
4
  "description": "A tool for image uploading",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "scripts": {
16
16
  "start": "node ./bin/picgo",
17
- "lint": "pnpm lint:dpdm && tsc --noEmit && eslint src --ext .ts",
17
+ "lint": "pnpm lint:dpdm && tsc --noEmit && eslint src --ext .ts --ignore-pattern 'src/**/__tests__/**' --ignore-pattern 'src/**/*.spec.ts' --fix",
18
18
  "test": "vitest run",
19
19
  "build": "cross-env NODE_ENV=production rimraf ./dist && rollup -c rollup.config.js",
20
20
  "dev": "cross-env NODE_ENV=development rollup -c rollup.config.js -w",
@@ -84,6 +84,7 @@
84
84
  "execa": "^5.1.1",
85
85
  "globals": "^16.5.0",
86
86
  "husky": "^9.1.7",
87
+ "ora": "^9.3.0",
87
88
  "rimraf": "^6.1.2",
88
89
  "rollup": "^4.53.3",
89
90
  "rollup-plugin-copy": "^3.5.0",
@@ -118,7 +119,8 @@
118
119
  "minimist": "^1.2.5",
119
120
  "open": "^11.0.0",
120
121
  "resolve": "^1.8.1",
121
- "tunnel": "^0.0.6"
122
+ "tunnel": "^0.0.6",
123
+ "write-file-atomic": "^7.0.1"
122
124
  },
123
125
  "repository": {
124
126
  "type": "git",