Skip to content

Commit

Permalink
✨ Feature: support imgur auth upload and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Apr 15, 2023
1 parent 6c5fdf1 commit d5f7121
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"mime-types": "^2.1.35",
"mitt": "^3.0.0",
"nodejs-file-downloader": "^4.10.6",
"piclist": "^0.5.0",
"piclist": "^0.5.1",
"pinia": "^2.0.32",
"pinia-plugin-persistedstate": "^3.1.0",
"qiniu": "^7.8.0",
Expand Down
21 changes: 16 additions & 5 deletions src/renderer/apis/imgur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@ import axios from 'axios'

export default class ImgurApi {
static async delete (configMap: IStringKeyMap): Promise<boolean> {
const clientId = configMap.config.clientId
const { hash } = configMap
const fullUrl = `https://api.imgur.com/3/image/${hash}`
const { config = {}, hash = '' } = configMap || {}
const { clientId = '', username = '', accessToken = '' } = config
const baseUrl = 'https://api.imgur.com/3'
let Authorization
let apiUrl
if (username && accessToken) {
Authorization = `Bearer ${accessToken}`
apiUrl = `${baseUrl}/account/${username}/image/${hash}`
} else if (clientId) {
Authorization = `Client-ID ${clientId}`
apiUrl = `${baseUrl}/image/${hash}`
} else {
return false
}
const headers = {
Authorization: `Client-ID ${clientId}`
Authorization
}
try {
const res = await axios.delete(fullUrl, {
const res = await axios.delete(apiUrl, {
headers,
timeout: 30000
})
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/manage/pages/logIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ function handleConfigImport (alias: string) {
async function getCurrentConfigList () {
const configList = await getPicBedsConfig<any>('uploader') ?? {}
const pbList = ['aliyun', 'tcyun', 'upyun', 'qiniu', 'smms', 'qiniu', 'github', 'webdavplist', 'aws-s3']
const pbList = ['aliyun', 'tcyun', 'upyun', 'qiniu', 'smms', 'qiniu', 'github', 'webdavplist', 'aws-s3', 'imgur']
const filteredConfigList = pbList.map((pb) => {
const config = configList[pb]
if (config && config.configList.length > 0) {
Expand Down Expand Up @@ -742,6 +742,18 @@ async function transUpToManage (config: IUploaderConfigListItem, picBedName: str
)
saveConfig(`picBed.${resultMap.alias}`, resultMap)
break
case 'imgur':
alias = `imgur-${config._configName ?? 'Default'}-imp`
if (!config.username || !config.accessToken || isImported(alias)) {
return
}
resultMap.alias = alias
resultMap.picBedName = 'imgur'
resultMap.imgurUserName = config.username
resultMap.accessToken = config.accessToken
resultMap.proxy = config.proxy || ''
saveConfig(`picBed.${resultMap.alias}`, resultMap)
break
default:
return
}
Expand Down
76 changes: 55 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5578,7 +5578,7 @@ consolidate@^0.15.1:

[email protected], content-disposition@^0.5.2:
version "0.5.4"
resolved "https://registry.npmmirror.com/content-disposition/download/content-disposition-0.5.4.tgz#8b82b4efac82512a02bb0b1dcec9d2c5e8eb5bfe"
resolved "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz#8b82b4efac82512a02bb0b1dcec9d2c5e8eb5bfe"
integrity sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==
dependencies:
safe-buffer "5.2.1"
Expand Down Expand Up @@ -8175,7 +8175,7 @@ globalthis@^1.0.1:

globby@^11.0.2, globby@^11.0.4, globby@^11.1.0:
version "11.1.0"
resolved "https://registry.npmmirror.com/globby/download/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
resolved "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
dependencies:
array-union "^2.1.0"
Expand Down Expand Up @@ -8278,16 +8278,21 @@ got@^9.6.0:
to-readable-stream "^1.0.0"
url-parse-lax "^3.0.0"

graceful-fs@^4.1.10, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.9:
version "4.2.10"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==
graceful-fs@^4.1.10:
version "4.2.11"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==

graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.8"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==

graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.9:
version "4.2.10"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==

"graceful-readlink@>= 1.0.0":
version "1.0.1"
resolved "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
Expand Down Expand Up @@ -8963,6 +8968,13 @@ is-core-module@^2.11.0, is-core-module@^2.8.1, is-core-module@^2.9.0:
dependencies:
has "^1.0.3"

is-core-module@^2.12.0:
version "2.12.0"
resolved "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.0.tgz#36ad62f6f73c8253fd6472517a12483cf03e7ec4"
integrity sha512-RECHCBCd/viahWmwj6enj19sKbHfJrddi/6cBDsNTKbNq0f7VeaUkBo60BqzvPqo/W54ChS62Z5qyun7cfOMqQ==
dependencies:
has "^1.0.3"

is-core-module@^2.5.0, is-core-module@^2.8.0:
version "2.8.0"
resolved "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.0.tgz#0321336c3d0925e497fd97f5d95cb114a5ccd548"
Expand Down Expand Up @@ -9096,7 +9108,7 @@ is-path-inside@^3.0.2, is-path-inside@^3.0.3:
is-plain-obj@^1.0.0, is-plain-obj@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4=
integrity sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==

is-plain-obj@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -10400,9 +10412,9 @@ no-case@^3.0.4:
tslib "^2.0.3"

node-abi@^3.3.0:
version "3.33.0"
resolved "https://registry.npmjs.org/node-abi/-/node-abi-3.33.0.tgz#8b23a0cec84e1c5f5411836de6a9b84bccf26e7f"
integrity sha512-7GGVawqyHF4pfd0YFybhv/eM9JwTtPqx0mAanQ146O3FlSh3pA24zf9IRQTOsfTSqXTNzPSP5iagAJ94jjuVog==
version "3.35.0"
resolved "https://registry.npmjs.org/node-abi/-/node-abi-3.35.0.tgz#c7f171af995cc5286fa95612c4ca97b3910eaa79"
integrity sha512-jAlSOFR1Bls963NmFwxeQkNTzqjUF0NThm8Le7eRIRGzFUVJuMOFZDLv5Y30W/Oaw+KEebEJLAigwO9gQHoEmw==
dependencies:
semver "^7.3.5"

Expand Down Expand Up @@ -11027,10 +11039,10 @@ performance-now@^2.1.0:
resolved "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==

piclist@^0.5.0:
version "0.5.0"
resolved "https://registry.npmjs.org/piclist/-/piclist-0.5.0.tgz#0eedf84e475514724b690de826c4f24631862890"
integrity sha512-bFdGsp7fLQ4uSf2y5cAct4tAUgry21vEFRCUE1ywIOf3nPTXPzrsNBt+rITANrIaVjQH/8MDirxnmgM7Cbll1Q==
piclist@^0.5.1:
version "0.5.1"
resolved "https://registry.npmjs.org/piclist/-/piclist-0.5.1.tgz#0d2b48c503e3a9eba73b26863c162642b0351b34"
integrity sha512-miF3+vunzE7uzAMuTaPoGYjgSrQWBrVLUOYa+V2NK2Y02CZ1d9AiFQMz73DsrQuch8GCXyDoauTpLZFQjbR5Bg==
dependencies:
"@picgo/i18n" "^1.0.0"
"@picgo/store" "^2.0.4"
Expand Down Expand Up @@ -11517,7 +11529,7 @@ progress@^2.0.3:
proto-list@~1.2.1:
version "1.2.4"
resolved "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=
integrity sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==

proxy-addr@~2.0.7:
version "2.0.7"
Expand Down Expand Up @@ -11778,7 +11790,20 @@ readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.0.6, readable-stre
string_decoder "^1.1.1"
util-deprecate "^1.0.1"

readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.3.0, readable-stream@^2.3.5, readable-stream@^2.3.6, readable-stream@~2.3.6:
readable-stream@^2.0.0, readable-stream@^2.3.0, readable-stream@^2.3.5:
version "2.3.8"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b"
integrity sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==
dependencies:
core-util-is "~1.0.0"
inherits "~2.0.3"
isarray "~1.0.0"
process-nextick-args "~2.0.0"
safe-buffer "~5.1.1"
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

readable-stream@^2.0.1, readable-stream@^2.3.6, readable-stream@~2.3.6:
version "2.3.7"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
Expand All @@ -11792,9 +11817,9 @@ readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.3.0, readable
util-deprecate "~1.0.1"

readable-stream@^3.1.1:
version "3.6.1"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.1.tgz#f9f9b5f536920253b3d26e7660e7da4ccff9bb62"
integrity sha512-+rQmrWMYGA90yenhTYsLWAsLsqVC8osOw6PKE1HDYiO0gdPeKe/xDHNzIAIn4C91YQ6oenEhfYqqc1883qHbjQ==
version "3.6.2"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967"
integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==
dependencies:
inherits "^2.0.3"
string_decoder "^1.1.1"
Expand Down Expand Up @@ -12047,7 +12072,7 @@ resolve@^1.10.0, resolve@^1.10.1, resolve@^1.14.2, resolve@^1.20.0:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@^1.22.0, resolve@^1.22.1, resolve@^1.3.0, resolve@^1.8.1:
resolve@^1.22.0, resolve@^1.22.1, resolve@^1.3.0:
version "1.22.1"
resolved "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177"
integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==
Expand All @@ -12056,6 +12081,15 @@ resolve@^1.22.0, resolve@^1.22.1, resolve@^1.3.0, resolve@^1.8.1:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@^1.8.1:
version "1.22.3"
resolved "https://registry.npmjs.org/resolve/-/resolve-1.22.3.tgz#4b4055349ffb962600972da1fdc33c46a4eb3283"
integrity sha512-P8ur/gp/AmbEzjr729bZnLjXK5Z+4P0zhIJgBgzqRih7hL7BOukHGtSTA3ACMY467GRFz3duQsi0bDZdR7DKdw==
dependencies:
is-core-module "^2.12.0"
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

[email protected], responselike@^1.0.2:
version "1.0.2"
resolved "https://registry.npmmirror.com/responselike/download/responselike-1.0.2.tgz#918720ef3b631c5642be068f15ade5a46f4ba1e7"
Expand Down Expand Up @@ -14370,7 +14404,7 @@ yargs@^17.0.1:
yauzl@^2.10.0, yauzl@^2.4.2:
version "2.10.0"
resolved "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"
integrity sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=
integrity sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==
dependencies:
buffer-crc32 "~0.2.3"
fd-slicer "~1.1.0"
Expand Down

1 comment on commit d5f7121

@Kuingsmile
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chung1912 @zhangninggit Molunerfinn/PicGo#1099
PicList now supports uploading and deleting to imgur accounts. This feature will be included in the next release version. You can try my app when this is published.
image

Please sign in to comment.