📦 Chore: update cos upload url

This commit is contained in:
PiEgg 2022-08-14 23:21:53 +08:00
parent 09ee0947cd
commit 86012c0c7b
2 changed files with 6 additions and 6 deletions

View File

@ -2,7 +2,7 @@ const pkg = require('../package.json')
const version = pkg.version const version = pkg.version
// TODO: use the same name format // TODO: use the same name format
const generateURL = (platform, ext, prefix = 'PicGo-') => { const generateURL = (platform, ext, prefix = 'PicGo-') => {
return `https://picgo-1251750343.cos.ap-chengdu.myqcloud.com/${prefix}${version}${platform}${ext}` return `https://picgo-1251750343.cos.ap-chengdu.myqcloud.com/${version}/${prefix}${version}${platform}${ext}`
} }
const platformExtList = [ const platformExtList = [

View File

@ -10,7 +10,7 @@ const path = require('path')
const distPath = path.join(__dirname, '../dist_electron') const distPath = path.join(__dirname, '../dist_electron')
const BUCKET = 'picgo-1251750343' const BUCKET = 'picgo-1251750343'
const AREA = 'ap-chengdu' // const AREA = 'ap-chengdu'
const VERSION = pkg.version const VERSION = pkg.version
const FILE_PATH = `${VERSION}/` const FILE_PATH = `${VERSION}/`
const SECRET_ID = process.env.PICGO_ENV_COS_SECRET_ID const SECRET_ID = process.env.PICGO_ENV_COS_SECRET_ID
@ -23,14 +23,14 @@ const SECRET_KEY = process.env.PICGO_ENV_COS_SECRET_KEY
*/ */
const generateSignature = (fileName, folder = FILE_PATH) => { const generateSignature = (fileName, folder = FILE_PATH) => {
const secretKey = SECRET_KEY const secretKey = SECRET_KEY
const area = AREA // const area = AREA
const bucket = BUCKET const bucket = BUCKET
const path = folder const path = folder
const today = Math.floor(new Date().getTime() / 1000) const today = Math.floor(new Date().getTime() / 1000)
const tomorrow = today + 86400 const tomorrow = today + 86400
const signTime = `${today};${tomorrow}` const signTime = `${today};${tomorrow}`
const signKey = crypto.createHmac('sha1', secretKey).update(signTime).digest('hex') const signKey = crypto.createHmac('sha1', secretKey).update(signTime).digest('hex')
const httpString = `put\n/${path}${fileName}\n\nhost=${bucket}.cos.${area}.myqcloud.com\n` const httpString = `put\n/${path}${fileName}\n\nhost=${bucket}.cos.accelerate.myqcloud.com\n`
const sha1edHttpString = crypto.createHash('sha1').update(httpString).digest('hex') const sha1edHttpString = crypto.createHash('sha1').update(httpString).digest('hex')
const stringToSign = `sha1\n${signTime}\n${sha1edHttpString}\n` const stringToSign = `sha1\n${signTime}\n${sha1edHttpString}\n`
const signature = crypto.createHmac('sha1', signKey).update(stringToSign).digest('hex') const signature = crypto.createHmac('sha1', signKey).update(stringToSign).digest('hex')
@ -50,9 +50,9 @@ const generateSignature = (fileName, folder = FILE_PATH) => {
const getReqOptions = (fileName, fileBuffer, signature, folder = FILE_PATH) => { const getReqOptions = (fileName, fileBuffer, signature, folder = FILE_PATH) => {
return { return {
method: 'PUT', method: 'PUT',
url: `http://${BUCKET}.cos.${AREA}.myqcloud.com/${encodeURI(folder)}${encodeURI(fileName)}`, url: `http://${BUCKET}.cos.accelerate.myqcloud.com/${encodeURI(folder)}${encodeURI(fileName)}`,
headers: { headers: {
Host: `${BUCKET}.cos.${AREA}.myqcloud.com`, Host: `${BUCKET}.cos.accelerate.myqcloud.com`,
Authorization: `q-sign-algorithm=sha1&q-ak=${SECRET_ID}&q-sign-time=${signature.signTime}&q-key-time=${signature.signTime}&q-header-list=host&q-url-param-list=&q-signature=${signature.signature}`, Authorization: `q-sign-algorithm=sha1&q-ak=${SECRET_ID}&q-sign-time=${signature.signTime}&q-key-time=${signature.signTime}&q-header-list=host&q-url-param-list=&q-signature=${signature.signature}`,
contentType: mime.lookup(fileName), contentType: mime.lookup(fileName),
useAgent: `PicGo;${pkg.version};null;null` useAgent: `PicGo;${pkg.version};null;null`