static get for chats

This commit is contained in:
Nate Kelley 2025-10-06 13:29:46 -06:00
parent a6814ac889
commit aed85a32b2
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
8 changed files with 103 additions and 2 deletions

View File

@ -15,7 +15,6 @@ const app = new Hono().put(
zValidator('json', PutChatScreenshotRequestSchema),
zValidator('param', PutChatScreenshotParamsSchema),
async (c) => {
console.log('PUT chat screenshot');
const assetId = c.req.valid('param').id;
const { image } = c.req.valid('json');
const user = c.get('busterUser');

View File

@ -0,0 +1,34 @@
import type { Chat } from '@buster/database/queries';
import { getAssetScreenshotSignedUrl } from '@buster/search';
import type { GetScreenshotResponse } from '@buster/server-shared/screenshots';
import type { Context } from 'hono';
export const getChatStaticScreenshotHandler = async ({
chat,
context,
}: {
chat: Pick<Chat, 'organizationId' | 'id'> & { screenshotBucketKey: string };
context: Context;
}) => {
try {
const signedUrl = await getAssetScreenshotSignedUrl({
key: chat.screenshotBucketKey,
organizationId: chat.organizationId,
});
const result: GetScreenshotResponse = {
success: true,
url: signedUrl,
};
return context.json(result);
} catch (error) {
console.error('Failed to get chat screenshot URL', {
chatId: chat.id,
error,
});
const result: GetScreenshotResponse = {
success: false,
error: 'Failed to get screenshot URL',
};
return context.json(result);
}
};

View File

@ -1,7 +1,8 @@
import { Hono } from 'hono';
import GET from './GET';
import PUT from './PUT';
import STATIC from './static.GET';
const app = new Hono().route('/', GET).route('/', PUT);
const app = new Hono().route('/', GET).route('/', PUT).route('/static', STATIC);
export default app;

View File

@ -0,0 +1,67 @@
import { checkPermission } from '@buster/access-controls';
import { getChatById } from '@buster/database/queries';
import { getAssetScreenshotSignedUrl } from '@buster/search';
import {
GetChatScreenshotParamsSchema,
type GetScreenshotResponse,
} from '@buster/server-shared/screenshots';
import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { HTTPException } from 'hono/http-exception';
const app = new Hono().get('/', zValidator('param', GetChatScreenshotParamsSchema), async (c) => {
const { id } = c.req.valid('param');
const user = c.get('busterUser');
const chat = await getChatById(id);
if (!chat) {
throw new HTTPException(404, { message: 'Chat not found' });
}
if (!chat.screenshotBucketKey) {
const result: GetScreenshotResponse = {
success: false,
error: 'Screenshot not found',
};
return c.json(result);
}
const permission = await checkPermission({
userId: user.id,
assetId: id,
assetType: 'chat',
requiredRole: 'can_view',
workspaceSharing: chat.workspaceSharing,
organizationId: chat.organizationId,
});
if (!permission.hasAccess) {
throw new HTTPException(403, {
message: 'You do not have permission to view this chat',
});
}
try {
const signedUrl = await getAssetScreenshotSignedUrl({
key: chat.screenshotBucketKey,
organizationId: chat.organizationId,
});
const result: GetScreenshotResponse = {
success: true,
url: signedUrl,
};
return c.json(result);
} catch (error) {
console.error('Failed to generate chat screenshot URL', {
chatId: id,
error,
});
const result: GetScreenshotResponse = {
success: false,
error: 'Failed to generate screenshot URL',
};
return c.json(result);
}
});
export default app;

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB