PicGo-Core icon indicating copy to clipboard operation
PicGo-Core copied to clipboard

【refactor】Refactoring Request with Got

Open Molunerfinn opened this issue 3 years ago • 5 comments

Since the package request was deprecated, PicGo-Core will replace it with got which is active and maintained.

The timeline is the following:

  • v1.5.0: replace the request with got, but the API exposed to the outside world is still consistent. You can still use ctx.Request.request. However, it will be warned with deprecated. The new api is ctx.request.
  • v1.6.0: just simply use ctx.request is OK, though the request lib will be changed to got. And you can't use ctx.Request.request anymore.
  • v2.0.0: will add an adaptor layer for web & node environment. In the web env, we will use axios, in the node env, we will use got. But the outside world is still ctx.request.

Molunerfinn avatar Jan 18 '21 02:01 Molunerfinn

@Molunerfinn So all the uploaders will have to change their implementation?

upupming avatar Jan 18 '21 03:01 upupming

@Molunerfinn So all the uploaders will have to change their implementation?

Yes. In v1.5.0, we will provide both ctx.Reqeust.request & ctx.request for developers to change their implementation. It will be a long time since v1.5.0 upgrade to v1.6.0 so developers can have enough time to upgrade. But in v1.6.0, the ctx.Request.request will be removed.

Before v1.5.0, PicGo-Core will provide a way to install a specific version of plugins.

Molunerfinn avatar Jan 18 '21 03:01 Molunerfinn

@Molunerfinn This is very nice~

upupming avatar Jan 18 '21 03:01 upupming

v2.0.0: will add an adaptor layer for web & node environment. In the web env, we will use axios, in the node env, we will use got. But the outside world is still ctx.request.

@Molunerfinn At the present, PicGo CLI (ctx.cmd) and plugin install feature (ctx.pluginHandler) is coupled in PicGo class, all of these only works in node environment, so it will be difficult to support web environment. Also, now that we will migarte axios finally, why not using axios now (axios supports both web and node environment), but using got?

upupming avatar Oct 05 '21 04:10 upupming

yes we can use axios

Molunerfinn avatar Oct 09 '21 02:10 Molunerfinn

The next alpha version of PicGo-Core will change request to axios.

For plugin developers:

  1. the old request options will also be available but will not be 100% OK, it's recommend to change to new axios options.
  2. support axios options. However, cause we need to be compatible with the old request options, so if your options do not provide resolveWithFullResponse, the result of ctx.request will be just data. See the following examples:
const res = await ctx.request({
  // other options
  resolveWithFullResponse: true
})

console.log(res) // { status, data,  headers, config, request }

const res2 = await ctx.request({
  // other options
})

console.log(res2) // { ...data }

Molunerfinn avatar Sep 03 '22 02:09 Molunerfinn

v1.5.0-alpha.9 is release

Molunerfinn avatar Sep 04 '22 04:09 Molunerfinn

See docs: https://picgo.github.io/PicGo-Core-Doc/zh/api/#request

Molunerfinn avatar Nov 14 '22 01:11 Molunerfinn