Vercel/src/admin/actions.ts
2025-02-17 17:54:00 -06:00

48 lines
1.3 KiB
TypeScript

'use server';
import { runAuthenticatedAdminServerAction } from '@/auth';
import { testRedisConnection } from '@/platforms/redis';
import { testOpenAiConnection } from '@/platforms/openai';
import { testDatabaseConnection } from '@/platforms/postgres';
import { testStorageConnection } from '@/platforms/storage';
import { APP_CONFIGURATION } from '@/app/config';
const scanForError = (
shouldCheck: boolean,
promise: () => Promise<any>,
): Promise<string> =>
shouldCheck
? promise()
.then(() => '')
.catch(error => error.message)
: Promise.resolve('');
export const testConnectionsAction = async () =>
runAuthenticatedAdminServerAction(async () => {
const {
hasDatabase,
hasStorageProvider,
hasRedisStorage,
isAiTextGenerationEnabled,
} = APP_CONFIGURATION;
const [
databaseError,
storageError,
redisError,
aiError,
] = await Promise.all([
scanForError(hasDatabase, testDatabaseConnection),
scanForError(hasStorageProvider, testStorageConnection),
scanForError(hasRedisStorage, testRedisConnection),
scanForError(isAiTextGenerationEnabled, testOpenAiConnection),
]);
return {
databaseError,
storageError,
redisError,
aiError,
};
});