continue scaffolding and refine the basic foundation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { protectRoute } from '~~/server/utils/auth';
|
||||
import { getPendingGeneration, getActiveGeneration, isGenerationActive } from '~~/server/utils/generation';
|
||||
import type { GenerationStatus } from '~~/server/types/chat';
|
||||
import { getGenerationStatus } from '~~/server/utils/generation';
|
||||
import type { GenerationStatusResponse } from '~~/server/types/chat';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await protectRoute(event);
|
||||
@@ -14,39 +14,30 @@ export default defineEventHandler(async (event) => {
|
||||
});
|
||||
}
|
||||
|
||||
const pendingGeneration = getPendingGeneration(generationId);
|
||||
const isActive = isGenerationActive(generationId);
|
||||
const activeGeneration = getActiveGeneration(generationId);
|
||||
const generation = await getGenerationStatus(generationId);
|
||||
|
||||
if (!pendingGeneration && !activeGeneration) {
|
||||
if (!generation) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Generation not found'
|
||||
});
|
||||
}
|
||||
|
||||
if (pendingGeneration) {
|
||||
const status: GenerationStatus = {
|
||||
generationId,
|
||||
status: 'pending',
|
||||
topicId: pendingGeneration.topicId
|
||||
};
|
||||
return status;
|
||||
// Verify ownership
|
||||
if (generation.userId !== event.context.user.id) {
|
||||
throw createError({
|
||||
statusCode: 403,
|
||||
statusMessage: 'Unauthorized'
|
||||
});
|
||||
}
|
||||
|
||||
if (isActive && activeGeneration) {
|
||||
const status: GenerationStatus = {
|
||||
generationId,
|
||||
status: 'active',
|
||||
content: activeGeneration.content,
|
||||
topicId: activeGeneration.topicId
|
||||
};
|
||||
return status;
|
||||
}
|
||||
|
||||
const status: GenerationStatus = {
|
||||
const status: GenerationStatusResponse = {
|
||||
generationId,
|
||||
status: 'completed'
|
||||
status: generation.status as any,
|
||||
topicId: generation.topicId,
|
||||
content: generation.content,
|
||||
error: generation.error || undefined
|
||||
};
|
||||
|
||||
return status;
|
||||
});
|
||||
Reference in New Issue
Block a user