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

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