Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor: standardize telegram route validation + accurate provider-active error (#2521)
Adam Eivy59d9b3143866
diff --git a/server/lib/aiToolkit/routes/providers.js b/server/lib/aiToolkit/routes/providers.jsindex ba2a19e6eb..25d893f30c 100644--- a/server/lib/aiToolkit/routes/providers.js+++ b/server/lib/aiToolkit/routes/providers.js@@ -23,7 +23,7 @@ export function createProvidersRoutes(providerService, options = {}) {router.put('/active', asyncHandler(async (req, res) => {const result = validate(providerActiveSchema, req.body);if (!result.success) {- throw new ServerError('Provider ID required', { status: 400, code: 'VALIDATION_ERROR', context: { details: result.errors } });+ throw new ServerError('Invalid provider data', { status: 400, code: 'VALIDATION_ERROR', context: { details: result.errors } });}const { id } = result.data;diff --git a/server/routes/telegram.js b/server/routes/telegram.jsindex 10496a92fc..c0871d2225 100644--- a/server/routes/telegram.js+++ b/server/routes/telegram.js@@ -44,16 +44,7 @@ router.get('/status', asyncHandler(async (req, res) => {// PUT /api/telegram/methodrouter.put('/method', asyncHandler(async (req, res) => {- const result = telegramMethodSchema.safeParse(req.body);- if (!result.success) {- throw new ServerError('Validation failed', {- status: 400,- code: 'VALIDATION_ERROR',- context: { details: result.error.issues }- });- }-- const { method } = result.data;+ const { method } = validateRequest(telegramMethodSchema, req.body);const settings = await getSettings();// Save method preference. Merge `telegram` against the FRESHEST snapshot inside@@ -99,16 +90,7 @@ router.put('/method', asyncHandler(async (req, res) => {// PUT /api/telegram/config (manual bot only)router.put('/config', asyncHandler(async (req, res) => {- const result = telegramConfigSchema.safeParse(req.body);- if (!result.success) {- throw new ServerError('Validation failed', {- status: 400,- code: 'VALIDATION_ERROR',- context: { details: result.error.issues }- });- }-- const { token, chatId } = result.data;+ const { token, chatId } = validateRequest(telegramConfigSchema, req.body);const settings = await getSettings();// Preserve existing token if a new one wasn't provided@@ -169,16 +151,8 @@ router.delete('/config', asyncHandler(async (req, res) => {// POST /api/telegram/testrouter.post('/test', asyncHandler(async (req, res) => {- const result = telegramTestSchema.safeParse(req.body);- if (!result.success) {- throw new ServerError('Validation failed', {- status: 400,- code: 'VALIDATION_ERROR',- context: { details: result.error.issues }- });- }-- const message = result.data.message || '🧪 Test message from PortOS';+ const { message: rawMessage } = validateRequest(telegramTestSchema, req.body);+ const message = rawMessage || '🧪 Test message from PortOS';const service = await getActiveService();const sendResult = await service.sendMessage(message);