Skip to content

Commit 4955b40

Browse files
committed
feat: add docs
1 parent cc037da commit 4955b40

File tree

6 files changed

+577
-15
lines changed

6 files changed

+577
-15
lines changed

docs/api/index.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,56 @@ Same as above, but does not support `config`.
359359

360360
Same as above, but does not support `config`.
361361

362+
## uploaderConfig <Badge text="1.8.0+" />
363+
364+
Uploader multi-config manager.
365+
366+
It manages per-uploader named configs stored under `uploader.<type>` and keeps `picBed.<type>` synced as a mirror of the active config.
367+
368+
Config names are matched case-insensitively (whitespace is trimmed).
369+
370+
### uploaderConfig.listUploaderTypes()
371+
372+
List installed/available uploader types.
373+
374+
### uploaderConfig.getConfigList(type)
375+
376+
Get all configs for an uploader type.
377+
378+
### uploaderConfig.getActiveConfig(type)
379+
380+
Get the active config for an uploader type (may be `undefined` if no configs exist).
381+
382+
### uploaderConfig.use(type, configName?)
383+
384+
Activate a config (by name) for an uploader type, and set it as the current uploader (`picBed.current` / `picBed.uploader`).
385+
386+
### uploaderConfig.createOrUpdate(type, configName?, configPatch?)
387+
388+
Create a config or update an existing config (by name), and **activate it on save**.
389+
390+
### uploaderConfig.copy(type, configName, newConfigName)
391+
392+
Copy a config into a new config name (**does not** switch current uploader).
393+
394+
### uploaderConfig.rename(type, oldName, newName)
395+
396+
Rename a config.
397+
398+
### uploaderConfig.remove(type, configName)
399+
400+
Remove a config. If you remove the last config, PicGo clears `picBed.<type>` to avoid credential residue.
401+
402+
Example:
403+
404+
```js
405+
// Switch to a named uploader config
406+
picgo.uploaderConfig.use('github', 'Work')
407+
408+
// Create/update a config and activate it
409+
picgo.uploaderConfig.createOrUpdate('github', 'Work', { repo: 'user/repo' })
410+
```
411+
362412
## Request.request <Badge type="warning" text="deprecate" />
363413

364414
**Since v1.5.0 this property is deprecated. Use [`ctx.request`](#request) instead.**

docs/guide/commands.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ $ picgo -h
2020
install|add [options] <plugins...> install picgo plugin
2121
uninstall|rm <plugins...> uninstall picgo plugin
2222
update [options] <plugins...> update picgo plugin
23-
set|config <module> [name] configure config of picgo modules
23+
set|config <module> [name] [configName] configure config of picgo modules
2424
upload|u [input...] upload, go go go
25-
use [module] use modules of picgo
25+
use [module] [name] [configName] use modules of picgo
26+
uploader [command] manage uploader configurations
2627
i18n [lang] change picgo language
2728
help [command] display help for command
2829
```
@@ -46,9 +47,9 @@ The CLI is built with [commander.js](https://github.com/tj/commander.js/) and [i
4647
```bash
4748
$ picgo use -h
4849

49-
Usage: use [module]
50+
Usage: use [module] [name] [configName]
5051

51-
use modules of picgo
52+
use a module (uploader/transformer/plugin) of picgo
5253
```
5354

5455
PicGo ships with the following built-ins:
@@ -84,28 +85,60 @@ $ picgo use
8485
(Move up and down to reveal more choices)
8586
```
8687

88+
Starting from PicGo-Core `v1.8.0`, uploaders support multiple named configs. If an uploader has multiple configs, the interactive flow will ask you to choose one. You can also specify it directly:
89+
90+
```bash
91+
picgo use uploader <type> <configName>
92+
```
93+
94+
`configName` is matched case-insensitively.
95+
8796
After you choose, PicGo will upload using the selected module. Some modules need configuration before you can use them (for example, tokens/keys for an image host). In that case, use `set|config` (described below) to configure the module.
8897

89-
## config|set
98+
## uploader <Badge text="1.8.0+" />
99+
100+
Manage uploader configurations (multi-config).
101+
102+
- `picgo uploader` opens an interactive prompt (list/rename/copy/delete).
103+
- `picgo uploader list [type]` lists configs (marks current uploader and default config).
104+
- `picgo uploader rename <type> <oldName> <newName>`
105+
- `picgo uploader copy <type> <configName> <newConfigName>` (does not switch current uploader)
106+
- `picgo uploader rm <type> <configName>`
107+
108+
Config names are matched case-insensitively.
109+
110+
Examples:
111+
112+
```bash
113+
picgo uploader list
114+
picgo uploader list github
115+
picgo uploader rename github Work Personal
116+
picgo uploader copy github Work Staging
117+
picgo uploader rm github Staging
118+
```
119+
120+
## set
90121

91122
> Configure module settings. There are three kinds of modules: 1) transformer 2) uploader 3) plugins
92123
93124
```bash
94125
$ picgo set -h
95126

96-
Usage: set|config [options] <module> [name]
127+
Usage: set [options] <module> [name] [configName]
97128

98-
configure config of picgo modules
129+
configure config of picgo modules (uploader/transformer/plugin)
99130

100131
Options:
101132

102133
-h, --help output usage information
103134
```
104135

105136
::: tip Tip
106-
Most of the time you only need to configure an Uploader. You can run `picgo set uploader` (or `picgo set uploader weibo|tcyun|...`) to jump straight into the interactive prompt.
137+
Most of the time you only need to configure an uploader. You can run `picgo set uploader` (or `picgo set uploader <type> [configName]`) to jump straight into the interactive prompt.
107138
:::
108139

140+
Starting from PicGo-Core `v1.8.0`, `set uploader` works with uploader multi-config: you can choose an existing config (by name) or create a new one, and the saved config becomes the active config for that uploader.
141+
109142
For the detailed configuration fields of built-in uploaders (image hosts), refer to PicGo’s configuration [wiki](https://github.com/Molunerfinn/PicGo/wiki/%E8%AF%A6%E7%BB%86%E7%AA%97%E5%8F%A3%E7%9A%84%E4%BD%BF%E7%94%A8)
110143

111144
If an uploader/transformer/plugin has no configurable options, PicGo will still report success—this is expected.

docs/guide/config.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,51 @@ Example:
190190
}
191191
```
192192

193+
## uploader <Badge text="1.8.0+" />
194+
195+
PicGo supports multiple named configurations per uploader type.
196+
197+
The source of truth is stored under `uploader.<type>`:
198+
199+
- `uploader.<type>.configList`: an array of configs.
200+
- `uploader.<type>.defaultId`: the `_id` of the active config.
201+
202+
Each item in `configList` includes metadata fields:
203+
204+
- `_id` (UUID v4)
205+
- `_configName` (unique within the same uploader type, case-insensitive)
206+
- `_createdAt` / `_updatedAt` (timestamps)
207+
208+
For plugin compatibility, `picBed.<type>` is a **read-only mirror** of the active config and will be overwritten when you switch configs.
209+
210+
::: tip Migration
211+
If you previously configured an uploader under `picBed.<type>`, PicGo migrates it automatically on startup.
212+
:::
213+
214+
Example:
215+
216+
```json
217+
{
218+
"uploader": {
219+
"github": {
220+
"defaultId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
221+
"configList": [
222+
{
223+
"_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
224+
"_configName": "Work",
225+
"_createdAt": 1700000000000,
226+
"_updatedAt": 1700000000000,
227+
"repo": "user/repo",
228+
"token": "******"
229+
}
230+
]
231+
}
232+
}
233+
}
234+
```
235+
236+
To manage or switch configs, see [CLI Commands](/guide/commands) (`picgo use uploader ...`, `picgo uploader ...`) or use the Node.js API (`ctx.uploaderConfig`).
237+
193238
## picgoPlugins
194239

195240
This section stores all plugin names and is mainly used to determine whether a plugin is enabled or disabled. **It is generated by PicGo automatically—you don’t need to edit it.**
@@ -203,6 +248,159 @@ Example:
203248
}
204249
```
205250

251+
## settings
252+
253+
General settings not tied to a specific uploader/transformer/plugin.
254+
255+
### settings.urlRewrite.rules <Badge text="1.8.1+" />
256+
257+
Opt-in URL rewrite rules. When configured, PicGo applies URL rewrite **after uploader execution** and **before `afterUploadPlugins`**.
258+
259+
- type: Array\<Rule\>
260+
- default: not set (no rewrite; no warnings)
261+
262+
Each rule supports:
263+
264+
- `match` (string, required): JavaScript `RegExp` source (no surrounding `/`).
265+
- `replace` (string, required): Replacement string (supports `$1`, `$2`, ...).
266+
- `enable` (boolean, optional): defaults to `true`; only explicit `false` disables the rule.
267+
- `global` (boolean, optional): maps to the regex `g` flag; defaults to `false`.
268+
- `ignoreCase` (boolean, optional): maps to the regex `i` flag; defaults to `false`.
269+
270+
Behavior:
271+
272+
- Rules are evaluated in array order; **first enabled match wins** (only one rule is applied per image).
273+
- If rewrite changes `imgUrl`, PicGo stores the original URL in `originImgUrl` (set once and never overwritten).
274+
- Invalid regex patterns are logged and skipped without failing the upload.
275+
- If a rewrite produces an empty string, PicGo logs a warning and continues.
276+
277+
#### For plugin authors and Node.js users
278+
279+
- `afterUploadPlugins` will see the **rewritten** `imgUrl` in `ctx.output`; use `originImgUrl` to access the original URL produced by the uploader.
280+
- `picgo.upload()` (Node.js API) returns `IImgInfo[]` with the **rewritten** `imgUrl`; use `originImgUrl` if you need the pre-rewrite value.
281+
- `originImgUrl` is only set when PicGo actually rewrites the URL; otherwise it stays `undefined`.
282+
283+
#### Examples
284+
285+
Example (simple prefix rewrite / switch to CDN):
286+
287+
Rewrite:
288+
289+
- `https://example.com/images/2026/1.png`
290+
-`https://cdn.example.com/blog-images/2026/1.png`
291+
292+
```json
293+
{
294+
"settings": {
295+
"urlRewrite": {
296+
"rules": [
297+
{
298+
"match": "https://example.com/images/",
299+
"replace": "https://cdn.example.com/blog-images/"
300+
}
301+
]
302+
}
303+
}
304+
}
305+
```
306+
307+
Example (ignore case: normalize file extension):
308+
309+
Rewrite:
310+
311+
- `https://cdn.example.com/blog-images/2026/1.PNG`
312+
-`https://cdn.example.com/blog-images/2026/1.png`
313+
314+
```json
315+
{
316+
"settings": {
317+
"urlRewrite": {
318+
"rules": [
319+
{
320+
"match": "PNG",
321+
"replace": "png",
322+
"ignoreCase": true
323+
}
324+
]
325+
}
326+
}
327+
}
328+
```
329+
330+
Example (global: replace all underscores in the URL):
331+
332+
Rewrite:
333+
334+
- `https://cdn.example.com/blog_images/2026/hello_world.png`
335+
-`https://cdn.example.com/blog-images/2026/hello-world.png`
336+
337+
```json
338+
{
339+
"settings": {
340+
"urlRewrite": {
341+
"rules": [
342+
{
343+
"match": "_",
344+
"replace": "-",
345+
"global": true
346+
}
347+
]
348+
}
349+
}
350+
}
351+
```
352+
353+
::: tip Regex and escaping
354+
`match` is a JavaScript regular expression source. For advanced patterns you may need to escape backslashes in JSON strings, e.g. `\\.` for a literal dot.
355+
:::
356+
357+
Advanced: capture groups (`$1`, `$2`, ...)
358+
359+
Rewrite:
360+
361+
- `https://example.com/images/2026/1.png`
362+
-`https://cdn.example.com/blog-images/2026/1.png`
363+
364+
If your `match` uses parentheses to capture parts of the URL, you can reference them in `replace` (e.g. `$1` for the first group, `$2` for the second).
365+
In this example, `$1` is the captured `images`, and `$2` is the rest of the path (`2026/1.png`):
366+
367+
```json
368+
{
369+
"settings": {
370+
"urlRewrite": {
371+
"rules": [
372+
{
373+
"match": "^https://example\\.com/(images)/(.*)$",
374+
"replace": "https://cdn.example.com/blog-$1/$2"
375+
}
376+
]
377+
}
378+
}
379+
}
380+
```
381+
382+
Advanced example (rewrite GitHub raw URLs to jsDelivr):
383+
384+
Rewrite:
385+
386+
- `https://raw.githubusercontent.com/user/repo/main/path/to/1.png`
387+
-`https://cdn.jsdelivr.net/gh/user/repo@main/path/to/1.png`
388+
389+
```json
390+
{
391+
"settings": {
392+
"urlRewrite": {
393+
"rules": [
394+
{
395+
"match": "^https://raw\\.githubusercontent\\.com/([^/]+)/([^/]+)/([^/]+)/(.*)$",
396+
"replace": "https://cdn.jsdelivr.net/gh/$1/$2@$3/$4"
397+
}
398+
]
399+
}
400+
}
401+
}
402+
```
403+
206404
## transformer
207405

208406
This section stores configuration for Transformers provided by third-party plugins.

0 commit comments

Comments
 (0)