picgo 3.0.2 → 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 +86 -0
- package/dist/core/Lifecycle.d.ts +0 -2
- package/dist/i18n/zh-CN.d.ts +8 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/UploadOption.d.ts +13 -0
- package/dist/types/index.d.ts +14 -1
- package/dist/types/internal.d.ts +4 -4
- package/dist/utils/createClipboardImagePath.d.ts +1 -0
- package/dist/utils/createContext.d.ts +2 -2
- package/dist/utils/getClipboardImage.d.ts +1 -2
- package/package.json +2 -1
- package/pnpm-workspace.yaml +3 -0
package/README.md
CHANGED
|
@@ -96,6 +96,21 @@ $ picgo -h
|
|
|
96
96
|
picgo upload /xxx/xx/xx.jpg
|
|
97
97
|
```
|
|
98
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
|
+
|
|
99
114
|
#### Upload a picture from clipboard
|
|
100
115
|
|
|
101
116
|
> picture from clipboard will be converted to `png`
|
|
@@ -112,6 +127,40 @@ Thanks to [vs-picgo](https://github.com/Spades-S/vs-picgo) && [Spades-S](https:/
|
|
|
112
127
|
picgo server -p 36677 -h 127.0.0.1
|
|
113
128
|
```
|
|
114
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
|
+
|
|
115
164
|
#### Login to [PicGo Cloud](https://cloud.picgo.app)
|
|
116
165
|
|
|
117
166
|
```bash
|
|
@@ -248,6 +297,43 @@ picgo.upload(['/xxx/xxx.jpg'])
|
|
|
248
297
|
picgo.upload()
|
|
249
298
|
```
|
|
250
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
|
+
|
|
251
337
|
## Documentation
|
|
252
338
|
|
|
253
339
|
For more details, you can checkout [documentation](https://docs.picgo.app/core/).
|
package/dist/core/Lifecycle.d.ts
CHANGED
|
@@ -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;
|
package/dist/i18n/zh-CN.d.ts
CHANGED
|
@@ -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;
|