Feature(custom): add support for cf worker short url service

ISSUES CLOSED: #170
This commit is contained in:
Kuingsmile 2024-03-11 22:04:50 +08:00
parent cafb4d590a
commit 9c6504c218
7 changed files with 44 additions and 0 deletions

View File

@ -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

View File

@ -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: 同步设置

View File

@ -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: 同步設置

View File

@ -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
}

View File

@ -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')
}

View File

@ -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

View File

@ -28,6 +28,7 @@ interface ISettingForm {
shortUrlServer: string,
yourlsDomain: string,
yourlsSignature: string,
cfWorkerHost: string,
deleteLocalFile: boolean,
serverKey: string,
aesPassword: string,