mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-19 23:29:37 +08:00
✨ Feature: add antileechtoken and expiretime for upyun manage
This commit is contained in:
@@ -42,16 +42,29 @@ class UpyunApi {
|
||||
bucket: string
|
||||
operator: string
|
||||
password: string
|
||||
antiLeechToken: string
|
||||
expireTime: number
|
||||
stopMarker = 'g2gCZAAEbmV4dGQAA2VvZg'
|
||||
logger: ManageLogger
|
||||
|
||||
constructor (bucket: string, operator: string, password: string, logger: ManageLogger) {
|
||||
constructor (bucket: string, operator: string, password: string, logger: ManageLogger, antiLeechToken?: string, expireTime?: number) {
|
||||
this.ser = new Upyun.Service(bucket, operator, password)
|
||||
this.cli = new Upyun.Client(this.ser)
|
||||
this.bucket = bucket
|
||||
this.operator = operator
|
||||
this.password = password
|
||||
this.logger = logger
|
||||
this.antiLeechToken = antiLeechToken || ''
|
||||
this.expireTime = expireTime || 24 * 60 * 60
|
||||
}
|
||||
|
||||
getAntiLeechParam (key: string): string {
|
||||
const uri = `/${encodeURIComponent(key)}`.replace(/%2F/g, '/').replace(/^\/+/g, '/')
|
||||
const now = Math.round(new Date().getTime() / 1000)
|
||||
const expire = this.expireTime ? now + parseInt(this.expireTime.toString(), 10) : now + 1800
|
||||
const sign = md5(`${this.antiLeechToken}&${expire}&${uri}`, 'hex')
|
||||
const upt = `${sign.substring(12, 20)}${expire}`
|
||||
return `_upt=${upt}`
|
||||
}
|
||||
|
||||
formatFolder (item: any, slicedPrefix: string) {
|
||||
@@ -72,6 +85,10 @@ class UpyunApi {
|
||||
|
||||
formatFile (item: any, slicedPrefix: string, urlPrefix: string) {
|
||||
const key = `${slicedPrefix}${item.name}`
|
||||
let url = `${urlPrefix}/${key}`
|
||||
if (this.antiLeechToken) {
|
||||
url = `${url}?${this.getAntiLeechParam(key)}`
|
||||
}
|
||||
return {
|
||||
...item,
|
||||
fileName: item.name,
|
||||
@@ -81,7 +98,7 @@ class UpyunApi {
|
||||
checked: false,
|
||||
match: false,
|
||||
isImage: isImage(item.name),
|
||||
url: `${urlPrefix}/${key}`,
|
||||
url,
|
||||
key
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
|
||||
case 'tcyun':
|
||||
return new API.TcyunApi(this.currentPicBedConfig.secretId, this.currentPicBedConfig.secretKey, this.logger)
|
||||
case 'upyun':
|
||||
return new API.UpyunApi(this.currentPicBedConfig.bucketName, this.currentPicBedConfig.operator, this.currentPicBedConfig.password, this.logger)
|
||||
return new API.UpyunApi(this.currentPicBedConfig.bucketName, this.currentPicBedConfig.operator, this.currentPicBedConfig.password, this.logger, this.currentPicBedConfig.antiLeechToken, this.currentPicBedConfig.expireTime)
|
||||
case 'webdavplist':
|
||||
return new API.WebdavplistApi(this.currentPicBedConfig.endpoint, this.currentPicBedConfig.username, this.currentPicBedConfig.password, this.currentPicBedConfig.sslEnabled, this.currentPicBedConfig.proxy, this.logger)
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user