picgo 3.0.1 → 3.1.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.
package/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  <div align="center" markdown="1">
2
2
  <sup>Special thanks to:</sup>
3
3
  <br>
4
- <a href="https://go.warp.dev/picgo">
5
- <img alt="Warp sponsorship" width="400" src="https://raw.githubusercontent.com/warpdotdev/brand-assets/refs/heads/main/Github/Sponsor/Warp-Github-LG-03.png">
4
+ <a href="https://www.nocobase.com/?utm_source=picgo">
5
+ <img alt="NocoBase sponsorship" width="400" src="https://static-docs.nocobase.com/Logo-Black.png">
6
6
  </a>
7
7
 
8
- ### [Warp, the intelligent terminal for developers](https://go.warp.dev/picgo)
9
- [Available for MacOS, Linux, & Windows](https://go.warp.dev/picgo)<br>
8
+ ### [NocoBase, AI + No-Code Build reliable business systems](https://www.nocobase.com/?utm_source=picgo)
10
9
 
11
10
  </div>
12
11
 
@@ -97,6 +96,21 @@ $ picgo -h
97
96
  picgo upload /xxx/xx/xx.jpg
98
97
  ```
99
98
 
99
+ #### Upload with a saved configuration
100
+
101
+ Use `--configName` to choose a saved configuration for one upload. Add `--uploader` when the same name exists in multiple uploader types. You can also use `--configId`; a unique ID match takes precedence over the name, and an unresolved ID falls back to the name when provided.
102
+
103
+ ```bash
104
+ picgo upload ./photo.png --configName=Work
105
+ picgo upload ./photo.png --uploader=github --configName="Work Images"
106
+ picgo upload ./photo.png --uploader=github --configId=your-config-id --configName=Work
107
+
108
+ # Upload from the clipboard with a saved configuration.
109
+ picgo upload --configName=Work
110
+ ```
111
+
112
+ These options use the same lookup rules as HTTP and SDK uploads and do not change saved defaults. Without these options, `picgo upload` retains its existing default behavior. Existing local input files are retained after upload; only temporary multipart files and clipboard images created by PicGo are cleaned up. Clipboard filenames keep the existing `YYYYMMDDHHmmssSSS.png` format.
113
+
100
114
  #### Upload a picture from clipboard
101
115
 
102
116
  > picture from clipboard will be converted to `png`
@@ -113,6 +127,40 @@ Thanks to [vs-picgo](https://github.com/Spades-S/vs-picgo) && [Spades-S](https:/
113
127
  picgo server -p 36677 -h 127.0.0.1
114
128
  ```
115
129
 
130
+ ##### Select a configuration for one upload
131
+
132
+ Add `uploader`, `configName`, or `configId` to `POST /upload` to choose an existing saved configuration for that request. Configuration names are recommended for readability. Use URL encoding for names containing spaces, Chinese characters, or other special characters:
133
+
134
+ ```js
135
+ const url = new URL('http://127.0.0.1:36677/upload')
136
+ url.searchParams.set('uploader', 'github')
137
+ url.searchParams.set('configName', 'Work')
138
+
139
+ const response = await fetch(url, {
140
+ method: 'POST',
141
+ headers: { 'Content-Type': 'application/json' },
142
+ body: JSON.stringify({ list: ['/absolute/path/photo.png'] })
143
+ })
144
+ const result = await response.json()
145
+ ```
146
+
147
+ The same query parameters work with an empty body for clipboard uploads, JSON without `list` or with an empty `list`, and multipart uploads using the `files` field. If server authentication is enabled, include your existing `Authorization: Bearer <secret>` header.
148
+
149
+ | Upload options | Behavior |
150
+ | --- | --- |
151
+ | No upload options | Existing default upload behavior. |
152
+ | `uploader=github` | Use GitHub's currently selected configuration (`defaultId`, falling back to its first configuration). |
153
+ | `uploader=github&configName=Work` | Find `Work` within GitHub, ignoring case and surrounding whitespace. |
154
+ | `configName=Work` | Search registered uploader types; exactly one configuration must match. |
155
+ | `configId=<id>` | Search by exact ID, optionally restricted by `uploader`. IDs remain stable when configurations are renamed. |
156
+ | Both `configId` and `configName` | Use a unique ID match first; if it cannot be uniquely resolved, try the name. |
157
+
158
+ Unknown uploaders, missing or ambiguous configurations, and blank or repeated upload parameters return HTTP `400` with `{ success: false, result: [], items: [], code, message }`. Messages explain the lookup failure or ambiguity; specify `uploader` to disambiguate names shared across types. Invalid upload options never fall back to the global default uploader. Existing authentication failures remain HTTP `401`.
159
+
160
+ Upload options do not change global defaults or save the requested configuration to disk. Concurrent requests can use different configurations. Plugins that read configuration through the context passed to their lifecycle handler see the request's configuration; plugins that cache global configuration may need adaptation. Explicit plugin persistence and Cloud session maintenance retain their normal behavior. `uploader=picgo-cloud` uses the current Cloud login; these options do not switch Cloud accounts.
161
+
162
+ Applications providing a custom internal server upload adapter must forward the optional `UploadOptions` argument to `picgo.upload`: `uploadPaths(paths, options)` forwards to `picgo.upload(paths, options)`, and `uploadClipboard(options)` forwards to `picgo.upload(undefined, options)`. Existing adapters can still handle requests without selectors, but ignoring these options will ignore the requested destination.
163
+
116
164
  #### Login to [PicGo Cloud](https://cloud.picgo.app)
117
165
 
118
166
  ```bash
@@ -249,6 +297,43 @@ picgo.upload(['/xxx/xxx.jpg'])
249
297
  picgo.upload()
250
298
  ```
251
299
 
300
+ The SDK accepts the same selectors in the second argument:
301
+
302
+ ```js
303
+ import { PicGo, UploadOptionError } from 'picgo'
304
+
305
+ const picgo = new PicGo()
306
+
307
+ try {
308
+ await picgo.upload(['/absolute/path/photo.png'], {
309
+ uploader: 'github',
310
+ configName: 'Work'
311
+ })
312
+
313
+ // A globally unique name can identify both the uploader and its configuration.
314
+ await picgo.upload(undefined, { configName: 'Work' })
315
+ } catch (error) {
316
+ if (error instanceof UploadOptionError) {
317
+ console.error(error.code, error.message)
318
+ } else {
319
+ throw error
320
+ }
321
+ }
322
+ ```
323
+
324
+ Invalid upload options reject the upload promise before processing inputs. Error codes are `INVALID_UPLOAD_OPTION`, `UNKNOWN_UPLOADER`, `UPLOAD_CONFIG_NOT_FOUND`, and `UPLOAD_CONFIG_AMBIGUOUS`. Temporary `setConfig`/`unsetConfig` calls on a scoped upload context affect that upload only; explicit `saveConfig`/`removeConfig` calls remain persistent. Existing SDK calls without upload options keep their behavior.
325
+
326
+ ## Development
327
+
328
+ Use Node.js >= 22.13 and pnpm 11.7.0 for repository development. The package manager is pinned in `package.json`; `pnpm-workspace.yaml` records the allowed esbuild installation script. This tooling requirement does not change PicGo's published runtime requirements.
329
+
330
+ ```bash
331
+ pnpm install --frozen-lockfile
332
+ pnpm lint
333
+ pnpm test
334
+ pnpm build
335
+ ```
336
+
252
337
  ## Documentation
253
338
 
254
339
  For more details, you can checkout [documentation](https://docs.picgo.app/core/).
@@ -2,7 +2,6 @@ import { EventEmitter } from 'events';
2
2
  import { IPicGo, UploadOptions } from '../types';
3
3
  export declare class Lifecycle extends EventEmitter {
4
4
  private readonly ctx;
5
- private step;
6
5
  constructor(ctx: IPicGo);
7
6
  start(input: any[], options?: UploadOptions): Promise<IPicGo>;
8
7
  private beforeTransform;
@@ -13,4 +12,3 @@ export declare class Lifecycle extends EventEmitter {
13
12
  private buildSuccessMessage;
14
13
  private handlePlugins;
15
14
  }
16
- export default Lifecycle;
@@ -5,6 +5,14 @@ export declare const ZH_CN: {
5
5
  UPLOAD_FAILED_REASON: string;
6
6
  SERVER_ERROR: string;
7
7
  AUTH_FAILED: string;
8
+ CONFIG_INVALID_FORMAT: string;
9
+ CONFIG_KEY_READ_ONLY: string;
10
+ CONFIG_KEY_CANNOT_UNSET: string;
11
+ UPLOAD_OPTION_INVALID_PARAMETER: string;
12
+ UPLOAD_OPTION_ACTIVE_CONFIG: string;
13
+ UPLOAD_OPTION_UNKNOWN_UPLOADER: string;
14
+ UPLOAD_OPTION_CONFIG_NOT_FOUND: string;
15
+ UPLOAD_OPTION_CONFIG_AMBIGUOUS: string;
8
16
  CLOUD_LOGIN_CANCELLED: string;
9
17
  CLOUD_LOGIN_IN_PROGRESS: string;
10
18
  CLOUD_LOGIN_INVALID_TOKEN: string;