mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-07 05:32:52 +08:00
✨ Feature: add remote file delete , picBed management
First version of PicList. In album, you can delete remote file now. Add picBed management function.
This commit is contained in:
@@ -2,24 +2,24 @@
|
||||
|
||||
// macos
|
||||
const darwin = [{
|
||||
appNameWithPrefix: 'PicGo-',
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.dmg',
|
||||
arch: '-arm64',
|
||||
'version-file': 'latest-mac.yml'
|
||||
}, {
|
||||
appNameWithPrefix: 'PicGo-',
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.dmg',
|
||||
arch: '-x64',
|
||||
'version-file': 'latest-mac.yml'
|
||||
}]
|
||||
|
||||
const linux = [{
|
||||
appNameWithPrefix: 'PicGo-',
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.AppImage',
|
||||
arch: '',
|
||||
'version-file': 'latest-linux.yml'
|
||||
}, {
|
||||
appNameWithPrefix: 'picgo_',
|
||||
appNameWithPrefix: 'piclist_',
|
||||
ext: '.snap',
|
||||
arch: '_amd64',
|
||||
'version-file': 'latest-linux.yml'
|
||||
@@ -27,17 +27,17 @@ const linux = [{
|
||||
|
||||
// windows
|
||||
const win32 = [{
|
||||
appNameWithPrefix: 'PicGo-Setup-',
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '-ia32',
|
||||
'version-file': 'latest.yml'
|
||||
}, {
|
||||
appNameWithPrefix: 'PicGo-Setup-',
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '-x64',
|
||||
'version-file': 'latest.yml'
|
||||
}, {
|
||||
appNameWithPrefix: 'PicGo-Setup-',
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '', // 32 & 64
|
||||
'version-file': 'latest.yml'
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
const pkg = require('../package.json')
|
||||
const version = pkg.version
|
||||
// TODO: use the same name format
|
||||
const generateURL = (platform, ext, prefix = 'PicGo-') => {
|
||||
return `https://picgo-1251750343.cos.ap-chengdu.myqcloud.com/${version}/${prefix}${version}${platform}${ext}`
|
||||
const generateURL = (platform, ext, prefix = 'PicList-') => {
|
||||
return `https://release.piclist.cn/${version}/${prefix}${version}${platform}${ext}`
|
||||
}
|
||||
|
||||
const platformExtList = [
|
||||
['-arm64', '.dmg', 'PicGo-'],
|
||||
['-x64', '.dmg', 'PicGo-'],
|
||||
['', '.AppImage', 'PicGo-'],
|
||||
['-ia32', '.exe', 'PicGo-Setup-'],
|
||||
['-x64', '.exe', 'PicGo-Setup-'],
|
||||
['', '.exe', 'PicGo-Setup-'],
|
||||
['_amd64', '.snap', 'picgo_']
|
||||
['-arm64', '.dmg', 'PicList-'],
|
||||
['-x64', '.dmg', 'PicList-'],
|
||||
['', '.AppImage', 'PicList-'],
|
||||
['-ia32', '.exe', 'PicList-Setup-'],
|
||||
['-x64', '.exe', 'PicList-Setup-'],
|
||||
['', '.exe', 'PicList-Setup-'],
|
||||
['_amd64', '.snap', 'piclist_']
|
||||
]
|
||||
|
||||
const links = platformExtList.map(([arch, ext, prefix]) => {
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
// upload dist bundled-app to cos
|
||||
require('dotenv').config()
|
||||
const crypto = require('crypto')
|
||||
const fs = require('fs')
|
||||
const mime = require('mime-types')
|
||||
const pkg = require('../package.json')
|
||||
const configList = require('./config')
|
||||
const axios = require('axios').default
|
||||
const path = require('path')
|
||||
const distPath = path.join(__dirname, '../dist_electron')
|
||||
|
||||
const BUCKET = 'picgo-1251750343'
|
||||
// const AREA = 'ap-chengdu'
|
||||
const VERSION = pkg.version
|
||||
const FILE_PATH = `${VERSION}/`
|
||||
const SECRET_ID = process.env.PICGO_ENV_COS_SECRET_ID
|
||||
const SECRET_KEY = process.env.PICGO_ENV_COS_SECRET_KEY
|
||||
|
||||
// https://cloud.tencent.com/document/product/436/7778#signature
|
||||
/**
|
||||
* @param {string} fileName
|
||||
* @returns
|
||||
*/
|
||||
const generateSignature = (fileName, folder = FILE_PATH) => {
|
||||
const secretKey = SECRET_KEY
|
||||
// const area = AREA
|
||||
const bucket = BUCKET
|
||||
const path = folder
|
||||
const today = Math.floor(new Date().getTime() / 1000)
|
||||
const tomorrow = today + 86400
|
||||
const signTime = `${today};${tomorrow}`
|
||||
const signKey = crypto.createHmac('sha1', secretKey).update(signTime).digest('hex')
|
||||
const httpString = `put\n/${path}${fileName}\n\nhost=${bucket}.cos.accelerate.myqcloud.com\n`
|
||||
const sha1edHttpString = crypto.createHash('sha1').update(httpString).digest('hex')
|
||||
const stringToSign = `sha1\n${signTime}\n${sha1edHttpString}\n`
|
||||
const signature = crypto.createHmac('sha1', signKey).update(stringToSign).digest('hex')
|
||||
return {
|
||||
signature,
|
||||
signTime
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} fileName
|
||||
* @param {Buffer} fileBuffer
|
||||
* @param {{ signature: string, signTime: string }} signature
|
||||
* @returns
|
||||
*/
|
||||
const getReqOptions = (fileName, fileBuffer, signature, folder = FILE_PATH) => {
|
||||
return {
|
||||
method: 'PUT',
|
||||
url: `http://${BUCKET}.cos.accelerate.myqcloud.com/${encodeURI(folder)}${encodeURI(fileName)}`,
|
||||
headers: {
|
||||
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}`,
|
||||
contentType: mime.lookup(fileName),
|
||||
useAgent: `PicGo;${pkg.version};null;null`
|
||||
},
|
||||
maxContentLength: Infinity,
|
||||
maxBodyLength: Infinity,
|
||||
data: fileBuffer,
|
||||
resolveWithFullResponse: true
|
||||
}
|
||||
}
|
||||
|
||||
const uploadFile = async () => {
|
||||
try {
|
||||
const platform = process.platform
|
||||
if (configList[platform]) {
|
||||
let versionFileHasUploaded = false
|
||||
for (const [index, config] of configList[platform].entries()) {
|
||||
const fileName = `${config.appNameWithPrefix}${VERSION}${config.arch}${config.ext}`
|
||||
const filePath = path.join(distPath, fileName)
|
||||
const versionFilePath = path.join(distPath, config['version-file'])
|
||||
let versionFileName = config['version-file']
|
||||
if (VERSION.toLocaleLowerCase().includes('beta')) {
|
||||
versionFileName = versionFileName.replace('.yml', '.beta.yml')
|
||||
}
|
||||
// upload dist file
|
||||
const signature = generateSignature(fileName)
|
||||
const reqOptions = getReqOptions(fileName, fs.readFileSync(filePath), signature)
|
||||
console.log('[PicGo Dist] Uploading...', fileName, `${index + 1}/${configList[platform].length}`)
|
||||
await axios.request(reqOptions)
|
||||
|
||||
// upload version file
|
||||
if (!versionFileHasUploaded) {
|
||||
const signature = generateSignature(versionFileName, '')
|
||||
const reqOptions = getReqOptions(versionFileName, fs.readFileSync(versionFilePath), signature, '')
|
||||
console.log('[PicGo Version File] Uploading...', versionFileName)
|
||||
await axios.request(reqOptions)
|
||||
versionFileHasUploaded = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.warn('platform not supported!', platform)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
uploadFile()
|
||||
67
scripts/upload-dist-to-r2.js
Normal file
67
scripts/upload-dist-to-r2.js
Normal file
@@ -0,0 +1,67 @@
|
||||
// upload dist bundled-app to r2
|
||||
require('dotenv').config()
|
||||
const S3 = require('aws-sdk/clients/s3')
|
||||
const pkg = require('../package.json')
|
||||
const configList = require('./config')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const BUCKET = 'piclist-dl'
|
||||
const VERSION = pkg.version
|
||||
const FILE_PATH = `${VERSION}/`
|
||||
const ACCOUNT_ID = process.env.R2_ACCOUNT_ID
|
||||
const SECRET_ID = process.env.R2_SECRET_ID
|
||||
const SECRET_KEY = process.env.R2_SECRET_KEY
|
||||
console.log(ACCOUNT_ID, SECRET_ID, SECRET_KEY)
|
||||
|
||||
const s3 = new S3({
|
||||
endpoint: `https://${ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
||||
accessKeyId: SECRET_ID,
|
||||
secretAccessKey: SECRET_KEY,
|
||||
signatureVersion: 'v4',
|
||||
})
|
||||
|
||||
const uploadFile = async () => {
|
||||
try {
|
||||
const platform = process.platform
|
||||
if (configList[platform]) {
|
||||
let versionFileHasUploaded = false
|
||||
for (const [index, config] of configList[platform].entries()) {
|
||||
const fileName = `${config.appNameWithPrefix}${VERSION}${config.arch}${config.ext}`
|
||||
const distPath = path.join(__dirname, '../dist_electron')
|
||||
let versionFileName = config['version-file']
|
||||
console.log('[PicList Dist] Uploading...', fileName, `${index + 1}/${configList[platform].length}`)
|
||||
const fileBuffer = fs.readFileSync(path.join(distPath, fileName))
|
||||
await s3.upload({
|
||||
Bucket: BUCKET,
|
||||
Key: `${FILE_PATH}${fileName}`,
|
||||
Body: fileBuffer
|
||||
}).promise()
|
||||
// upload version file
|
||||
if (!versionFileHasUploaded) {
|
||||
console.log('[PicList Version File] Uploading...', versionFileName)
|
||||
let versionFilePath
|
||||
if (platform === 'win32') {
|
||||
versionFilePath = path.join(distPath, 'latest.yml')
|
||||
} else if (platform === 'darwin') {
|
||||
versionFilePath = path.join(distPath, 'latest-mac.yml')
|
||||
} else {
|
||||
versionFilePath = path.join(distPath, 'latest-linux.yml')
|
||||
}
|
||||
const versionFileBuffer = fs.readFileSync(versionFilePath)
|
||||
await s3.upload({
|
||||
Bucket: BUCKET,
|
||||
Key: `${versionFileName}`,
|
||||
Body: versionFileBuffer
|
||||
}).promise()
|
||||
versionFileHasUploaded = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.warn('platform not supported!', platform)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
uploadFile()
|
||||
Reference in New Issue
Block a user