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
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { requireAdminAuth } from '../../utils/access'
|
|
import { createApiError } from '../../utils/api-error'
|
|
import { logException } from '../../utils/logger'
|
|
import {
|
|
listActivityLogs,
|
|
type LogAction,
|
|
type LogSource
|
|
} from '../../utils/db'
|
|
import {
|
|
DEFAULT_LIST_LIMIT,
|
|
MAX_LIST_LIMIT
|
|
} from '../../utils/constants'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
await requireAdminAuth(event)
|
|
|
|
const query = getQuery(event)
|
|
|
|
const limitRaw = Number(query.limit ?? DEFAULT_LIST_LIMIT)
|
|
const limit = Number.isFinite(limitRaw)
|
|
? Math.min(Math.max(1, Math.floor(limitRaw)), MAX_LIST_LIMIT)
|
|
: DEFAULT_LIST_LIMIT
|
|
|
|
const actionRaw = typeof query.action === 'string' ? query.action : ''
|
|
const action = (actionRaw === 'upload' || actionRaw === 'delete')
|
|
? actionRaw as LogAction
|
|
: undefined
|
|
|
|
const sourceRaw = typeof query.source === 'string' ? query.source : ''
|
|
const source = (sourceRaw === 'web' || sourceRaw === 'api' || sourceRaw === 'twikoo')
|
|
? sourceRaw as LogSource
|
|
: undefined
|
|
|
|
const folder = typeof query.folder === 'string' && query.folder.trim()
|
|
? query.folder.trim()
|
|
: undefined
|
|
|
|
const pageRaw = Number(query.page ?? 1)
|
|
const page = Number.isFinite(pageRaw) && pageRaw > 0
|
|
? Math.floor(pageRaw)
|
|
: 1
|
|
|
|
try {
|
|
const result = listActivityLogs({ limit, page, action, source, folder })
|
|
return {
|
|
items: result.items.map(row => ({
|
|
id: row.id,
|
|
action: row.action,
|
|
key: row.key,
|
|
originalName: row.original_name,
|
|
size: row.size,
|
|
contentType: row.content_type,
|
|
source: row.source,
|
|
createdAt: row.created_at
|
|
})),
|
|
total: result.total,
|
|
page: result.page,
|
|
pageSize: result.pageSize,
|
|
totalPages: result.totalPages
|
|
}
|
|
} catch (error) {
|
|
logException('activity logs list failed', error)
|
|
createApiError(event, 'INVALID_REQUEST', '读取操作记录失败', 500)
|
|
}
|
|
})
|