mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-22 22:28:14 -05:00
✨ Feature(custom): add support for cf worker short url service
ISSUES CLOSED: #170
This commit is contained in:
parent
cafb4d590a
commit
9c6504c218
@ -249,6 +249,7 @@ SETTINGS_SHORT_URL_SERVER: Short url server
|
||||
SETTINGS_SHORT_URL_C1N_TOKEN: C1N Token
|
||||
SETTINGS_SHORT_URL_YOURLS_DOMAIN: YOURLS domain
|
||||
SETTINGS_SHORT_URL_YOURLS_SIGNATURE: YOURLS signature
|
||||
SETTINGS_SHORT_URL_CF_WORKER_HOST: Cloudflare Worker Host
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: Delete local file after upload
|
||||
SETTINGS_SYNC_CONFIG: Settings Sync Configuration
|
||||
SETTINGS_SYNC_CONFIG_TITLE: Sync Settings
|
||||
|
@ -252,6 +252,7 @@ SETTINGS_SHORT_URL_SERVER: 短链接服务
|
||||
SETTINGS_SHORT_URL_C1N_TOKEN: C1N Token
|
||||
SETTINGS_SHORT_URL_YOURLS_DOMAIN: YOURLS域名
|
||||
SETTINGS_SHORT_URL_YOURLS_SIGNATURE: YOURLS signature
|
||||
SETTINGS_SHORT_URL_CF_WORKER_HOST: Cloudflare Worker域名
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: 上传后删除本地文件
|
||||
SETTINGS_SYNC_CONFIG: 设置配置同步
|
||||
SETTINGS_SYNC_CONFIG_TITLE: 同步设置
|
||||
|
@ -250,6 +250,7 @@ SETTINGS_SHORT_URL_SERVER: 短網址服務
|
||||
SETTINGS_SHORT_URL_C1N_TOKEN: C1N Token
|
||||
SETTINGS_SHORT_URL_YOURLS_DOMAIN: YOURLS域名
|
||||
SETTINGS_SHORT_URL_YOURLS_SIGNATURE: YOURLS signature
|
||||
SETTINGS_SHORT_URL_CF_WORKER_HOST: Cloudflare Worker Host
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: 上傳後刪除本地檔案
|
||||
SETTINGS_SYNC_CONFIG: 設置同步配置
|
||||
SETTINGS_SYNC_CONFIG_TITLE: 同步設置
|
||||
|
@ -169,6 +169,23 @@ export const generateShortUrl = async (url: string) => {
|
||||
} else {
|
||||
logger.warn('Yourls server or signature is not set')
|
||||
}
|
||||
} else if (server === 'cf_worker') {
|
||||
let cfWorkerHost = db.get('settings.cfWorkerHost') || ''
|
||||
cfWorkerHost = cfWorkerHost.replace(/\/$/, '')
|
||||
if (cfWorkerHost) {
|
||||
try {
|
||||
const res = await axios.post(cfWorkerHost, {
|
||||
url
|
||||
})
|
||||
if (res.data.status === 200 && res.data.key.startsWith('/')) {
|
||||
return `${cfWorkerHost}${res.data.key}`
|
||||
}
|
||||
} catch (e: any) {
|
||||
logger.error(e)
|
||||
}
|
||||
} else {
|
||||
logger.warn('CF Worker host is not set')
|
||||
}
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
@ -521,6 +521,18 @@
|
||||
@change="handleYourlsSignatureChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="form.useShortUrl && form.shortUrlServer === 'cf_worker'"
|
||||
:label="$T('SETTINGS_SHORT_URL_CF_WORKER_HOST')"
|
||||
>
|
||||
<el-input
|
||||
v-model="form.cfWorkerHost"
|
||||
size="small"
|
||||
style="width: 50%"
|
||||
:placeholder="$T('SETTINGS_SHORT_URL_CF_WORKER_HOST')"
|
||||
@change="handleCfWorkerHostChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
:label="$T('SETTINGS_ENCODE_OUTPUT_URL')"
|
||||
>
|
||||
@ -1686,6 +1698,10 @@ const shortUrlServerList = [{
|
||||
{
|
||||
label: 'yourls',
|
||||
value: 'yourls'
|
||||
},
|
||||
{
|
||||
label: 'xyTom/Url-Shorten-Worker',
|
||||
value: 'cf_worker'
|
||||
}
|
||||
]
|
||||
|
||||
@ -1851,6 +1867,7 @@ const form = reactive<ISettingForm>({
|
||||
c1nToken: '',
|
||||
yourlsDomain: '',
|
||||
yourlsSignature: '',
|
||||
cfWorkerHost: '',
|
||||
deleteLocalFile: false,
|
||||
serverKey: '',
|
||||
aesPassword: '',
|
||||
@ -2017,6 +2034,7 @@ async function initData () {
|
||||
form.c1nToken = settings.c1nToken || ''
|
||||
form.yourlsDomain = settings.yourlsDomain || ''
|
||||
form.yourlsSignature = settings.yourlsSignature || ''
|
||||
form.cfWorkerHost = settings.cfWorkerHost || ''
|
||||
form.deleteLocalFile = settings.deleteLocalFile || false
|
||||
form.serverKey = settings.serverKey || ''
|
||||
form.aesPassword = settings.aesPassword || 'PicList-aesPassword'
|
||||
@ -2380,6 +2398,10 @@ function handleYourlsSignatureChange (val: string) {
|
||||
saveConfig('settings.yourlsSignature', val)
|
||||
}
|
||||
|
||||
function handleCfWorkerHostChange (val: string) {
|
||||
saveConfig('settings.cfWorkerHost', val)
|
||||
}
|
||||
|
||||
function handleAesPasswordChange (val: string) {
|
||||
saveConfig('settings.aesPassword', val || 'PicList-aesPassword')
|
||||
}
|
||||
|
1
src/universal/types/i18n.d.ts
vendored
1
src/universal/types/i18n.d.ts
vendored
@ -245,6 +245,7 @@ interface ILocales {
|
||||
SETTINGS_SHORT_URL_C1N_TOKEN: string
|
||||
SETTINGS_SHORT_URL_YOURLS_DOMAIN: string
|
||||
SETTINGS_SHORT_URL_YOURLS_SIGNATURE: string
|
||||
SETTINGS_SHORT_URL_CF_WORKER_HOST: string
|
||||
SETTINGS_DELETE_LOCAL_FILE_AFTER_UPLOAD: string
|
||||
SETTINGS_SYNC_CONFIG: string
|
||||
SETTINGS_SYNC_CONFIG_TITLE: string
|
||||
|
1
src/universal/types/view.d.ts
vendored
1
src/universal/types/view.d.ts
vendored
@ -28,6 +28,7 @@ interface ISettingForm {
|
||||
shortUrlServer: string,
|
||||
yourlsDomain: string,
|
||||
yourlsSignature: string,
|
||||
cfWorkerHost: string,
|
||||
deleteLocalFile: boolean,
|
||||
serverKey: string,
|
||||
aesPassword: string,
|
||||
|
Loading…
Reference in New Issue
Block a user