优化后端代码质量基础
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
import { PROJECT_ROOT } from '../../../config/runtime.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
|
||||
const CLOUDTENTACLES_SESSION_FILE_PATH = path.join(PROJECT_ROOT, 'data', 'cloudtentacles-session.json')
|
||||
|
||||
@@ -58,7 +59,10 @@ export function saveCloudtentaclesSessionState(rawValue: unknown) {
|
||||
export function saveCloudtentaclesSessionStateByKey(sourceKey: unknown, rawValue: unknown) {
|
||||
const key = String(sourceKey || '').trim()
|
||||
if (!key) {
|
||||
throw new Error('saveCloudtentaclesSessionStateByKey: sourceKey is required')
|
||||
throw createHttpError('cloudtentacles sourceKey 不能为空', {
|
||||
statusCode: 400,
|
||||
errorCode: 'cloudtentacles_source_key_required',
|
||||
})
|
||||
}
|
||||
|
||||
const states = loadCloudtentaclesSessionStatesFromFile()
|
||||
@@ -75,7 +79,10 @@ export function saveCloudtentaclesSessionStateByKey(sourceKey: unknown, rawValue
|
||||
export function deleteCloudtentaclesSessionStateByKey(sourceKey: unknown) {
|
||||
const key = String(sourceKey || '').trim()
|
||||
if (!key) {
|
||||
throw new Error('deleteCloudtentaclesSessionStateByKey: sourceKey is required')
|
||||
throw createHttpError('cloudtentacles sourceKey 不能为空', {
|
||||
statusCode: 400,
|
||||
errorCode: 'cloudtentacles_source_key_required',
|
||||
})
|
||||
}
|
||||
|
||||
const states = loadCloudtentaclesSessionStatesFromFile()
|
||||
@@ -99,7 +106,10 @@ export function clearCloudtentaclesSessionState() {
|
||||
export function clearCloudtentaclesSessionStateByKey(sourceKey: unknown) {
|
||||
const key = String(sourceKey || '').trim()
|
||||
if (!key) {
|
||||
throw new Error('clearCloudtentaclesSessionStateByKey: sourceKey is required')
|
||||
throw createHttpError('cloudtentacles sourceKey 不能为空', {
|
||||
statusCode: 400,
|
||||
errorCode: 'cloudtentacles_source_key_required',
|
||||
})
|
||||
}
|
||||
|
||||
const cleared = createDefaultCloudtentaclesSessionState()
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
import { PROJECT_ROOT } from '../../../config/runtime.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
|
||||
const CLOUDTENTACLES_SOURCES_FILE_PATH = path.join(PROJECT_ROOT, 'data', 'cloudtentacles-sources.json')
|
||||
|
||||
@@ -63,7 +64,10 @@ export function saveCloudtentaclesSourcesList(rawValue: unknown) {
|
||||
export function saveCloudtentaclesSourceByKey(sourceKey: unknown, data: JsonObject = {}) {
|
||||
const key = String(sourceKey || '').trim()
|
||||
if (!key) {
|
||||
throw new Error('saveCloudtentaclesSourceByKey: sourceKey is required')
|
||||
throw createHttpError('cloudtentacles sourceKey 不能为空', {
|
||||
statusCode: 400,
|
||||
errorCode: 'cloudtentacles_source_key_required',
|
||||
})
|
||||
}
|
||||
|
||||
const config = loadCloudtentaclesSourcesConfigFromFile()
|
||||
@@ -87,10 +91,16 @@ export function saveCloudtentaclesSourceByKey(sourceKey: unknown, data: JsonObje
|
||||
export function deleteCloudtentaclesSourceByKey(sourceKey: unknown) {
|
||||
const key = String(sourceKey || '').trim()
|
||||
if (!key) {
|
||||
throw new Error('deleteCloudtentaclesSourceByKey: sourceKey is required')
|
||||
throw createHttpError('cloudtentacles sourceKey 不能为空', {
|
||||
statusCode: 400,
|
||||
errorCode: 'cloudtentacles_source_key_required',
|
||||
})
|
||||
}
|
||||
if (key === 'default') {
|
||||
throw new Error('deleteCloudtentaclesSourceByKey: cannot delete the default source')
|
||||
throw createHttpError('不能删除默认 cloudtentacles 账号', {
|
||||
statusCode: 409,
|
||||
errorCode: 'cloudtentacles_default_source_forbidden',
|
||||
})
|
||||
}
|
||||
|
||||
const config = loadCloudtentaclesSourcesConfigFromFile()
|
||||
|
||||
Reference in New Issue
Block a user