mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
Fuck: remove ali-oss
This commit is contained in:
parent
671c011feb
commit
5a25aa0b52
@ -1,4 +1,4 @@
|
|||||||
test/unit/coverage/**
|
test/unit/coverage/**
|
||||||
test/unit/*.js
|
test/unit/*.js
|
||||||
test/e2e/*.js
|
test/e2e/*.js
|
||||||
dist/
|
dist/
|
||||||
|
@ -71,8 +71,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ali-oss": "^5.3.0",
|
|
||||||
"axios": "^0.16.1",
|
"axios": "^0.16.1",
|
||||||
|
"dateformat": "^3.0.3",
|
||||||
"element-ui": "^2.0.5",
|
"element-ui": "^2.0.5",
|
||||||
"fecha": "^2.3.3",
|
"fecha": "^2.3.3",
|
||||||
"fs-extra": "^4.0.2",
|
"fs-extra": "^4.0.2",
|
||||||
|
@ -1,21 +1,32 @@
|
|||||||
|
import request from 'request-promise'
|
||||||
import * as img2Base64 from './img2base64'
|
import * as img2Base64 from './img2base64'
|
||||||
import db from '../../datastore/index'
|
import db from '../../datastore/index'
|
||||||
import { Notification, clipboard } from 'electron'
|
import { Notification, clipboard } from 'electron'
|
||||||
import { Wrapper as OSS } from 'ali-oss'
|
import crypto from 'crypto'
|
||||||
|
|
||||||
let client
|
// generate OSS signature
|
||||||
|
const generateSignature = (fileName) => {
|
||||||
// generate OSS Options
|
|
||||||
const generateOSSOptions = () => {
|
|
||||||
const options = db.read().get('picBed.aliyun').value()
|
const options = db.read().get('picBed.aliyun').value()
|
||||||
client = new OSS({
|
const date = new Date().toGMTString()
|
||||||
region: `${options.area}`,
|
const signString = `PUT\n\n\n${date}\n/${options.bucket}/${options.path}${fileName}`
|
||||||
accessKeyId: `${options.accessKeyId}`,
|
|
||||||
accessKeySecret: `${options.accessKeySecret}`,
|
const signature = crypto.createHmac('sha1', options.accessKeySecret).update(signString).digest('base64')
|
||||||
bucket: `${options.bucket}`,
|
return `OSS ${options.accessKeyId}:${signature}`
|
||||||
secure: true
|
}
|
||||||
})
|
|
||||||
return client
|
const postOptions = (fileName, signature, imgBase64) => {
|
||||||
|
const options = db.read().get('picBed.aliyun').value()
|
||||||
|
return {
|
||||||
|
method: 'PUT',
|
||||||
|
url: `https://${options.bucket}.${options.area}.aliyuncs.com/${encodeURI(options.path)}${encodeURI(fileName)}`,
|
||||||
|
headers: {
|
||||||
|
Host: `${options.bucket}.${options.area}.aliyuncs.com`,
|
||||||
|
Authorization: signature,
|
||||||
|
Date: new Date().toGMTString()
|
||||||
|
},
|
||||||
|
body: Buffer.from(imgBase64, 'base64'),
|
||||||
|
resolveWithFullResponse: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const aliYunUpload = async (img, type, webContents) => {
|
const aliYunUpload = async (img, type, webContents) => {
|
||||||
@ -27,15 +38,17 @@ const aliYunUpload = async (img, type, webContents) => {
|
|||||||
const customUrl = aliYunOptions.customUrl
|
const customUrl = aliYunOptions.customUrl
|
||||||
const path = aliYunOptions.path
|
const path = aliYunOptions.path
|
||||||
const length = imgList.length
|
const length = imgList.length
|
||||||
generateOSSOptions()
|
generateSignature()
|
||||||
for (let i in imgList) {
|
for (let i in imgList) {
|
||||||
let body = await client.put(`${path}${imgList[i].fileName}`, Buffer.from(imgList[i].base64Image, 'base64'))
|
const signature = generateSignature(imgList[i].fileName)
|
||||||
if (body.res.status === 200) {
|
const options = postOptions(imgList[i].fileName, signature, imgList[i].base64Image)
|
||||||
|
let body = await request(options)
|
||||||
|
if (body.statusCode === 200) {
|
||||||
delete imgList[i].base64Image
|
delete imgList[i].base64Image
|
||||||
if (customUrl) {
|
if (customUrl) {
|
||||||
imgList[i]['imgUrl'] = `${customUrl}/${path}${imgList[i].fileName}`
|
imgList[i]['imgUrl'] = `${customUrl}/${path}${imgList[i].fileName}`
|
||||||
} else {
|
} else {
|
||||||
imgList[i]['imgUrl'] = body.url
|
imgList[i]['imgUrl'] = `https://${aliYunOptions.bucket}.${aliYunOptions.area}.aliyuncs.com/${path}${imgList[0].fileName}`
|
||||||
}
|
}
|
||||||
imgList[i]['type'] = 'aliyun'
|
imgList[i]['type'] = 'aliyun'
|
||||||
if (i - length === -1) {
|
if (i - length === -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user