release: v1.4.3
GitHub Release / release (push) Canceled after 0s
ci / ci (22, ubuntu-latest) (push) Canceled after 0s
Publish Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Canceled after 0s
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Canceled after 0s
Publish Docker image / merge (push) Canceled after 0s
GitHub Release / release (push) Canceled after 0s
ci / ci (22, ubuntu-latest) (push) Canceled after 0s
Publish Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Canceled after 0s
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Canceled after 0s
Publish Docker image / merge (push) Canceled after 0s
Add a Telegram channel or group storage backend, with proxied image URLs and an optional API proxy.
This commit is contained in:
1 parent
4ed4692f5e
commit
cc19dc6435
32 files changed
+1527
-143
No files matched your search
@@ -2,13 +2,19 @@ import { requireAdminAuth } from '../../../utils/access'
|
||||
import { createApiError } from '../../../utils/api-error'
|
||||
import {
|
||||
insertStorageBackend,
|
||||
insertTelegramBackend,
|
||||
isStorageEnvConfigured
|
||||
} from '../../../utils/storage-backends'
|
||||
import { validateS3Config } from '../../../utils/storage/s3'
|
||||
import {
|
||||
validateTelegramConfig,
|
||||
validateApiProxyUrl
|
||||
} from '../../../utils/storage/telegram'
|
||||
import { parseQuotaBytes } from '../../../utils/storage-capacity'
|
||||
import type { ServingMode } from '../../../utils/storage/types'
|
||||
|
||||
interface StorageCreateBody {
|
||||
type?: 's3' | 'telegram'
|
||||
name?: string
|
||||
provider?: string
|
||||
config?: {
|
||||
@@ -17,10 +23,13 @@ interface StorageCreateBody {
|
||||
bucket?: string
|
||||
prefix?: string
|
||||
forcePathStyle?: boolean
|
||||
chatId?: string
|
||||
apiProxyUrl?: string
|
||||
}
|
||||
secrets?: {
|
||||
accessKeyId?: string
|
||||
secretAccessKey?: string
|
||||
botToken?: string
|
||||
}
|
||||
servingMode?: ServingMode
|
||||
publicUrl?: string
|
||||
@@ -40,6 +49,50 @@ export default defineEventHandler(async (event) => {
|
||||
(): StorageCreateBody => ({})
|
||||
)
|
||||
|
||||
const backendType = body.type === 'telegram' ? 'telegram' : 's3'
|
||||
|
||||
if (backendType === 'telegram') {
|
||||
const name = body.name?.trim() || 'Telegram 频道'
|
||||
const chatId = body.config?.chatId?.trim() ?? ''
|
||||
const apiProxyUrl = body.config?.apiProxyUrl?.trim() ?? ''
|
||||
const botToken = body.secrets?.botToken?.trim() ?? ''
|
||||
|
||||
if (!chatId || !botToken) {
|
||||
createApiError(event, 'INVALID_REQUEST', 'Bot Token 与 Chat ID 不能为空', 400)
|
||||
}
|
||||
|
||||
const config = {
|
||||
chatId,
|
||||
apiProxyUrl: apiProxyUrl || undefined
|
||||
}
|
||||
const configError = validateTelegramConfig(config)
|
||||
if (configError) {
|
||||
createApiError(event, 'INVALID_REQUEST', configError, 400)
|
||||
}
|
||||
if (apiProxyUrl) {
|
||||
const proxyError = validateApiProxyUrl(apiProxyUrl)
|
||||
if (proxyError) {
|
||||
createApiError(event, 'INVALID_REQUEST', proxyError, 400)
|
||||
}
|
||||
}
|
||||
|
||||
const quotaBytes = parseQuotaBytes(body.quotaBytes)
|
||||
if (!quotaBytes) {
|
||||
createApiError(event, 'INVALID_REQUEST', '请填写有效的存储套餐总量', 400)
|
||||
}
|
||||
|
||||
const id = insertTelegramBackend({
|
||||
name,
|
||||
config,
|
||||
secrets: { botToken },
|
||||
quotaBytes,
|
||||
enabled: body.enabled,
|
||||
isDefault: body.isDefault
|
||||
})
|
||||
|
||||
return { success: true, id }
|
||||
}
|
||||
|
||||
const name = body.name?.trim() || 'S3 兼容存储'
|
||||
const config = {
|
||||
endpoint: body.config?.endpoint?.trim() ?? '',
|
||||
|
||||
Reference in new issue
Block a user