@@ -322,7 +322,7 @@ helper 是 picgo 的主要插件的集中管理者,包含 5 个部件,拥有
322322
323323如果你只是要开发一个简单的插件,而不是发布一个 npm 包的话(发布 picgo 的 npm 插件包请查看 [ 插件开发指南] ( /zh/dev-guide/cli.html ) ),那么只需要调用` helper[module].register ` 方法即可。
324324
325- 第一个参数代表插件的 id(相同的部件只能拥有唯一的 id,不过不同的部件可以拥有相同的 id),第二个参数应当是一个对象,至少包括一个` handle ` 方法供 picgo 调用。如果你还想要拥有 [ 配置项] ( /zh/dev-guide/cli.html#配置项的处理 ) 功能,可以考虑再加入` config ` 方法供 picgo 调用。
325+ 第一个参数代表插件的 id(相同的部件只能拥有唯一的 id,不过不同的部件可以拥有相同的 id),第二个参数应当是一个对象,至少包括一个` handle ` 方法供 picgo 调用。如果你还想要拥有 [ 配置项] ( /zh/dev-guide/cli.html#配置项的处理 ) 功能,可以考虑再加入` config ` 方法供 picgo 调用。
326326
327327示例:
328328
@@ -353,16 +353,19 @@ picgo.helper.transformer.register('test', {
353353
354354同上,不过不拥有配置项功能。
355355
356- ## Request.request
356+ ## Request.request < Badge type = " warning " text = " deprecate " />
357357
358- ** v1.5.0开始这个属性将被废弃,请直接使用 [ ` ctx.request ` ] ( #request ) 。**
358+ ** v1.5.0开始这个属性被废弃,请直接使用 [ ` ctx.request ` ] ( #request ) 。**
359+
360+ 以下是 1.5.0 之前的文档,已经被废弃不再维护:
359361
360362Request.request 是 picgo 内部暴露的一个 [ Request-Promise-Native] ( https://github.com/request/request-promise-native ) 对象,拥有一个可以使用 [ request] ( https://github.com/request/request ) 库里的所有方法,并且返回的是原生的 Promise。
361363
362364::: tip 小贴士
363365值得注意的是,使用这个对象来发送请求的话,能自动读取用户配置给 picgo 的 ` proxy ` 值。比较适合用于书写 Uploder 的核心部分。
364366:::
365367
368+
366369示例:
367370
368371``` js
@@ -373,18 +376,81 @@ picgo.Request.request({
373376})
374377```
375378
376- ## request <Badge text =" 1.4.16+ " />
379+ ## request <Badge text =" 1.4.16+ " /> <Badge text =" 1.5.0+ " />
380+
381+ ::: tip 小贴士
382+ 值得注意的是,使用这个对象来发送请求的话,能自动读取用户配置给 picgo 的 ` proxy ` 值。比较适合用于书写 Uploder 的核心部分。
383+ :::
384+
385+ 从 ` v1.4.16 ` 开始,默认的请求方法从 ` ctx.Request.request ` 换成了 ` ctx.request ` 。
377386
378- 从 ` v1.4.16 ` 开始,默认的请求方法从 ` ctx.Request.request ` 换成了 ` ctx.request ` 。目前的底层实现是 [ Request-Promise-Native] ( https://github.com/request/request-promise-native ) ,从 ` v1.5.0 ` 开始,将会换成 [ got] ( https://github.com/sindresorhus/got ) 。
387+ - ` v1.5.0 ` 之前底层实现是 [ Request-Promise-Native] ( https://github.com/request/request-promise-native )
388+ - ` v1.5.0 ` 开始,底层实现是 [ axios] ( https://github.com/axios/axios )
389+
390+ 这里将不再介绍旧的实现的使用方法,而是直接介绍新的实现的使用方法。
391+
392+ 总体而言,请求的配置可以参考 [ axios 文档 request-config 部分] ( https://github.com/axios/axios#request-config ) ,不过 picgo 为了兼容旧的 ` request ` API,做了如下的处理,希望开发者注意:
393+
394+ 1 . 请求体里如果不带有 ` resolveWithFullResponse: true ` , 那么返回的是 ` response.data ` ,而不是 ` response ` (带有 ` status ` 等信息)。
395+ 2 . 如果希望返回值是 ` Buffer ` ,请把 ` responseType ` 设置为 ` arraybuffer ` 。
396+
397+ picgo 提供了几个比较有用的类型方便开发者使用:
398+
399+ 1 . ` IReqOptions ` :带有 ` resolveWithFullResponse: true ` 的请求配置类型。
400+ 2 . ` IReqOptionsWithArrayBufferRes ` :带有 ` resolveWithFullResponse: true ` 和 ` responseType: 'arraybuffer' ` 的请求配置类型。
401+ 3 . ` IReqOptionsWithBodyResOnly ` : ` axios ` 的原始请求配置类型,返回值只有 ` response.data ` 。
402+
403+ ::: tip 注意
404+ request 接口的返回值依然是个 Promise,所以依然推荐使用 ` async/await ` 的方式来使用。
405+ :::
379406
380407示例:
381408
382- ``` js
383- picgo .request ({
409+ ``` ts
410+ import { IReqOptions } from ' picgo'
411+
412+ const opt: IReqOptions = {
384413 method: ' post' ,
385- uri: ' xxxx' ,
386- body: fs .readFileSync (' yyy' )
387- })
414+ url: ' xxxx' ,
415+ data: {},
416+ resolveWithFullResponse: true // <-- 这里设置为 true,返回值会带上 status 等
417+ }
418+
419+ interface IRes {
420+ // ...
421+ }
422+
423+ const res = await ctx .request (opt ) // { status: number, data: IRes }
424+
425+ // ------------------------------
426+
427+ import { IReqOptionsWithArrayBufferRes } from ' picgo'
428+
429+ const opt: IReqOptions = {
430+ method: ' post' ,
431+ url: ' xxxx' ,
432+ data: {},
433+ resolveWithFullResponse: true // <-- 这里设置为 true,返回值会带上 status 等
434+ responseType : ' arraybuffer' // <-- 这里设置为 arraybuffer,返回值 data 会是 Buffer
435+ }
436+
437+ const res = await ctx .request (opt ) // { status: number, data: Buffer }
438+
439+ // ------------------------------
440+
441+ import { IReqOptionsWithBodyResOnly } from ' picgo'
442+
443+ const opt: IReqOptions = {
444+ method: ' post' ,
445+ url: ' xxxx' ,
446+ data: {},
447+ }
448+
449+ interface IRes {
450+ // ...
451+ }
452+
453+ const res: IRes = await ctx .request (opt ) // IRes
388454```
389455
390456## cmd
@@ -407,7 +473,7 @@ picgo.cmd.program
407473
408474### cmd.inquirer
409475
410- 用于提供 CLI 命令行交互。实际上是一个 [ inquirer.js] ( https://github.com/SBoudrias/Inquirer.js/ ) 的实例,用法和` inquirer.js ` 一致。参考 [ 配置项的处理] (/zh/dev-guide/cli.html#配置项的处理) 一章。通常 PicGo 内部会将其和插件的 [ config] (/zh/dev-guide/cli.html#config 方法) 方法一起使用。
476+ 用于提供 CLI 命令行交互。实际上是一个 [ inquirer.js] ( https://github.com/SBoudrias/Inquirer.js/ ) 的实例,用法和` inquirer.js ` 一致。参考 [ 配置项的处理] ( /zh/dev-guide/cli.html#配置项的处理 ) 一章。通常 PicGo 内部会将其和插件的 [ config] ( /zh/dev-guide/cli.html#config方法 ) 方法一起使用。
411477
412478示例:
413479
@@ -422,7 +488,7 @@ const handleConfig = async ctx => {
422488```
423489
424490:::tip 提示
425- 你可以通过这个工具来制作你自己的命令行交互。不过需要注意的是,通常你应该直接使用插件的 [ config] (/zh/dev-guide/cli.html#config 方法) 方法来实现命令行交互,并且 PicGo 会自动存储` config ` 相关配置项的结果。
491+ 你可以通过这个工具来制作你自己的命令行交互。不过需要注意的是,通常你应该直接使用插件的 [ config] ( /zh/dev-guide/cli.html#config方法 ) 方法来实现命令行交互,并且 PicGo 会自动存储` config ` 相关配置项的结果。
426492:::
427493
428494## log
@@ -431,7 +497,7 @@ const handleConfig = async ctx => {
431497
432498截图:
433499
434- ![ ] ( https://raw.githubusercontent .com/Molunerfinn/test/master/ picgo/20180912153940 .png )
500+ ![ ] ( https://pic.molunerfinn .com/picgo/docs/logs .png )
435501
436502### log.info(message)
437503
@@ -617,6 +683,125 @@ const plugin = picgo.pluginLoader.getPlugin('xxx')
617683const res = picgo .pluginLoader .hasPlugin (' xxx' ) // true or false
618684```
619685
686+ ## use <Badge text =" 1.5.0+ " />
687+
688+ 比 [ PluginLoader] ( #pluginloader ) 更加简单的插件加载方式。适合在 Node 项目中使用 picgo 时动态引入插件。
689+
690+ - (plugin: IPicGoPlugin, name?: string): IPicGoPluginInterface
691+
692+ 1 . 第一个参数是 picgo 插件导出对象,通常是以 npm 包的形式出现的。
693+ 2 . 如果第二个参数 ` name ` 为空,则只会实例化这个插件而不会把插件注册进 PicGo 的列表里。这通常在你需要动态加载插件的时候使用。以下是实际例子:
694+
695+ ``` js
696+ const { PicGo } = require (' picgo' )
697+ const PluginMigrater = require (' picgo-plugin-pic-migrater' )
698+ const MinioUploader = require (' picgo-plugin-minio' )
699+
700+ const picgo = new PicGo ()
701+
702+ const plugin = picgo .use (PluginMigrater) // will not register this plugin, just use it
703+ picgo .use (MinioUploader, ' minio' ) // will register this plugin
704+
705+ picgo .setConfig ({
706+ ' picgo-plugin-pic-migrater' : {
707+ newFileSuffix: ' _new' ,
708+ include: ' ' ,
709+ exclude: ' '
710+ },
711+ picBed: {
712+ current: ' minio' , // use minio config
713+ uploader: ' minio' ,
714+ minio: {
715+ endpoint: ' http://localhost:9000' ,
716+ accessKey: ' minioadmin' ,
717+ secretKey: ' minioadmin' ,
718+ bucket: ' picgo' ,
719+ path: ' /' ,
720+ useSSL: false
721+ }
722+ }
723+ })
724+
725+ // will use minio for migrating
726+ plugin .migrateFiles ([' /xxx/yyy.md' ]) // { total: number, success: number }
727+ ```
728+
729+ ## i18n <Badge text =" 1.5.0+ " />
730+
731+ 提供国际化支持。目前支持的语言有:
732+
733+ - ` zh-CN ` (默认)
734+ - ` zh-TW `
735+ - ` en `
736+
737+ 如果想为 picgo 添加默认的语言支持,请参考这个 [ PR] ( https://github.com/PicGo/PicGo-Core/pull/135 ) 。
738+
739+ ### i18n.addLocale(language: string, locales: ILocale)
740+
741+ 用于向已有的语言中添加语言包。
742+
743+ - language: string
744+ - locales: ` [key: string]: any `
745+ - return: 返回 boolean ,表示是否添加成功
746+
747+ ``` js
748+ picgo .i18n .addLocale (' zh-CN' , {
749+ ' PICGO_CURRENT_PICBED' : ' 当前图床'
750+ })
751+
752+ const text = picgo .i18n .translate (' PICGO_CURRENT_PICBED' ) // 当前图床
753+ ```
754+
755+ ### i18n.translate(key: T, args?: {}) => string)
756+
757+ 翻译文本。
758+
759+ - key: string | T (T 是一个枚举类型,包含了所有的文本 key)
760+ - args: object (可选),如果文本带有参数可以通过这个来传入
761+ - return: string
762+
763+ ``` js
764+ picgo .i18n .addLocale (' zh-CN' , {
765+ ' PICGO_CURRENT_PICBED' : ' 当前图床是 ${current}'
766+ })
767+
768+ const text = picgo .i18n .translate (' PICGO_CURRENT_PICBED' , {
769+ current: ' sm.ms'
770+ }) // 当前图床是 sm.ms
771+ ```
772+
773+ ### i18n.setLanguage(language: string)
774+
775+ 设置语言。
776+
777+ ``` js
778+ picgo .i18n .setLanguage (' zh-TW' )
779+ ```
780+
781+ ### i18n.addLanguage(language: string, locales: ILocale)
782+
783+ - language: string
784+ - locales: ` [key: string]: any `
785+
786+ 添加一种新的语言类型。注意如果添加一种新的语言,那么建议请先实现默认的语言包里的 [ 所有文本] ( https://github.com/PicGo/PicGo-Core/blob/dev/src/i18n/zh-CN.ts ) ,否则可能会出现未知的问题。
787+
788+ ``` js
789+ picgo .i18n .addLanguage (' jp' , {
790+ // ...
791+ })
792+ ```
793+
794+ ### i18n.getLanguageList()
795+
796+ - return: string[ ]
797+
798+ 返回当前所有的语言列表。
799+
800+ ``` js
801+ const list = picgo .i18n .getLanguageList () // ['zh-CN', 'zh-TW', 'en']
802+ ```
803+
804+
620805## guiApi <Badge text =" GUI VERSION 2.0.0+ " />
621806
622807** guiApi 仅在 electron 版本的 PicGo 里提供,详细信息可以参考 [ GUI 插件开发一章] ( /zh/dev-guide/gui.html ) 。**
@@ -838,3 +1023,12 @@ const guiMenu = ctx => {
8381023根据id删除某张图片的信息。无返回值。
8391024
8401025** 注意,删除图片是敏感操作,GUI版本会提示用户是否允许删除。**
1026+
1027+ #### galleryDB.overwrite(value)
1028+
1029+ - value: [ IImgInfo[ ]] ( https://github.com/PicGo/PicGo-Core/blob/f133d57562c413b0b6f9a9ca9a93bf19c1768f1f/src/types/index.d.ts#L169-L178 )
1030+ - return: Promise<[ IResult[ ]] ( https://github.com/PicGo/store/blob/dev/src/types/index.ts ) >
1031+
1032+ 覆盖相册中的数据。 ** 覆盖前会清空原有数据。**
1033+
1034+ ** 注意,覆盖图片列表是敏感操作,GUI版本会提示用户是否允许覆盖。**
0 commit comments