mirror of https://github.com/buster-so/buster.git
standard for generate is png, standard for screenshot is png
This commit is contained in:
parent
dbc85f9a42
commit
a01ee7fa70
|
@ -16,7 +16,6 @@ const app = new Hono().get(
|
|||
zValidator('query', GetChatScreenshotQuerySchema),
|
||||
async (c) => {
|
||||
const chatId = c.req.valid('param').id;
|
||||
const search = c.req.valid('query');
|
||||
const user = c.get('busterUser');
|
||||
|
||||
const chat = await getChatById(chatId);
|
||||
|
@ -40,16 +39,15 @@ const app = new Hono().get(
|
|||
}
|
||||
|
||||
try {
|
||||
const type = 'png' as const;
|
||||
const screenshotBuffer = await getChatScreenshot({
|
||||
chatId,
|
||||
width: search.width,
|
||||
height: search.height,
|
||||
type: search.type,
|
||||
accessToken: c.get('accessToken'),
|
||||
organizationId: chat.organizationId,
|
||||
type,
|
||||
});
|
||||
|
||||
return createImageResponse(screenshotBuffer, search.type);
|
||||
return createImageResponse(screenshotBuffer, type);
|
||||
} catch (error) {
|
||||
console.error('Failed to generate chat screenshot URL', {
|
||||
chatId,
|
||||
|
|
|
@ -43,14 +43,16 @@ const app = new Hono()
|
|||
}
|
||||
|
||||
try {
|
||||
const type = 'png' as const;
|
||||
const screenshotBuffer = await getDashboardScreenshot({
|
||||
...search,
|
||||
dashboardId,
|
||||
accessToken: c.get('accessToken'),
|
||||
organizationId: dashboard.organizationId,
|
||||
type,
|
||||
});
|
||||
|
||||
return createImageResponse(screenshotBuffer, search.type);
|
||||
return createImageResponse(screenshotBuffer, type);
|
||||
} catch (error) {
|
||||
console.error('Failed to generate chat screenshot URL', {
|
||||
dashboardId,
|
||||
|
|
|
@ -18,7 +18,7 @@ const app = new Hono()
|
|||
zValidator('query', GetMetricScreenshotQuerySchema),
|
||||
async (c) => {
|
||||
const metricId = c.req.valid('param').id;
|
||||
const { version_number, width, height, type } = c.req.valid('query');
|
||||
const { version_number } = c.req.valid('query');
|
||||
const user = c.get('busterUser');
|
||||
|
||||
const metric = await getMetricFileById(metricId);
|
||||
|
@ -42,14 +42,13 @@ const app = new Hono()
|
|||
}
|
||||
|
||||
try {
|
||||
const type = 'png' as const;
|
||||
const screenshotBuffer = await getMetricScreenshot({
|
||||
metricId,
|
||||
width,
|
||||
height,
|
||||
version_number,
|
||||
type,
|
||||
accessToken: c.get('accessToken'),
|
||||
organizationId: metric.organizationId,
|
||||
type,
|
||||
});
|
||||
|
||||
return createImageResponse(screenshotBuffer, type);
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
import { Hono } from 'hono';
|
||||
import GET from './GET';
|
||||
import PUT from './PUT';
|
||||
import SCREENSHOT from './screenshot';
|
||||
import SHARING from './sharing';
|
||||
|
||||
const app = new Hono()
|
||||
.route('/', GET)
|
||||
.route('/', PUT)
|
||||
.route('/sharing', SHARING)
|
||||
.route('/screenshot', SCREENSHOT);
|
||||
const app = new Hono().route('/', GET).route('/', PUT).route('/sharing', SHARING);
|
||||
|
||||
export default app;
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
import { checkPermission } from '@buster/access-controls';
|
||||
import { getAssetScreenshotBucketKey, getReportFileById } from '@buster/database/queries';
|
||||
import { getAssetScreenshotSignedUrl } from '@buster/search';
|
||||
import {
|
||||
GetReportScreenshotParamsSchema,
|
||||
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', GetReportScreenshotParamsSchema), async (c) => {
|
||||
const reportId = c.req.valid('param').id;
|
||||
const user = c.get('busterUser');
|
||||
|
||||
const report = await getReportFileById({ reportId, userId: user.id });
|
||||
|
||||
if (!report) {
|
||||
throw new HTTPException(404, { message: 'Report not found' });
|
||||
}
|
||||
|
||||
const existingKey = await getAssetScreenshotBucketKey({
|
||||
assetType: 'report_file',
|
||||
assetId: reportId,
|
||||
});
|
||||
|
||||
if (!existingKey) {
|
||||
const result: GetScreenshotResponse = {
|
||||
success: false,
|
||||
error: 'Screenshot not found',
|
||||
};
|
||||
return c.json(result);
|
||||
}
|
||||
|
||||
const permission = await checkPermission({
|
||||
userId: user.id,
|
||||
assetId: reportId,
|
||||
assetType: 'report_file',
|
||||
requiredRole: 'can_view',
|
||||
workspaceSharing: report.workspace_sharing,
|
||||
organizationId: report.organization_id,
|
||||
});
|
||||
|
||||
if (!permission.hasAccess) {
|
||||
throw new HTTPException(403, {
|
||||
message: 'You do not have permission to view this report',
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const signedUrl = await getAssetScreenshotSignedUrl({
|
||||
key: existingKey,
|
||||
organizationId: report.organization_id,
|
||||
});
|
||||
|
||||
const result: GetScreenshotResponse = {
|
||||
success: true,
|
||||
url: signedUrl,
|
||||
};
|
||||
return c.json(result);
|
||||
} catch (error) {
|
||||
console.error('Failed to generate report screenshot URL', {
|
||||
reportId,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
const response: GetScreenshotResponse = {
|
||||
success: false,
|
||||
error: 'Failed to generate screenshot URL',
|
||||
};
|
||||
return c.json(response);
|
||||
});
|
||||
|
||||
export default app;
|
|
@ -1,6 +0,0 @@
|
|||
import { Hono } from 'hono';
|
||||
import GET from './GET';
|
||||
|
||||
const app = new Hono().route('/', GET);
|
||||
|
||||
export default app;
|
Loading…
Reference in New Issue