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),
|
zValidator('query', GetChatScreenshotQuerySchema),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const chatId = c.req.valid('param').id;
|
const chatId = c.req.valid('param').id;
|
||||||
const search = c.req.valid('query');
|
|
||||||
const user = c.get('busterUser');
|
const user = c.get('busterUser');
|
||||||
|
|
||||||
const chat = await getChatById(chatId);
|
const chat = await getChatById(chatId);
|
||||||
|
@ -40,16 +39,15 @@ const app = new Hono().get(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const type = 'png' as const;
|
||||||
const screenshotBuffer = await getChatScreenshot({
|
const screenshotBuffer = await getChatScreenshot({
|
||||||
chatId,
|
chatId,
|
||||||
width: search.width,
|
|
||||||
height: search.height,
|
|
||||||
type: search.type,
|
|
||||||
accessToken: c.get('accessToken'),
|
accessToken: c.get('accessToken'),
|
||||||
organizationId: chat.organizationId,
|
organizationId: chat.organizationId,
|
||||||
|
type,
|
||||||
});
|
});
|
||||||
|
|
||||||
return createImageResponse(screenshotBuffer, search.type);
|
return createImageResponse(screenshotBuffer, type);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to generate chat screenshot URL', {
|
console.error('Failed to generate chat screenshot URL', {
|
||||||
chatId,
|
chatId,
|
||||||
|
|
|
@ -43,14 +43,16 @@ const app = new Hono()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const type = 'png' as const;
|
||||||
const screenshotBuffer = await getDashboardScreenshot({
|
const screenshotBuffer = await getDashboardScreenshot({
|
||||||
...search,
|
...search,
|
||||||
dashboardId,
|
dashboardId,
|
||||||
accessToken: c.get('accessToken'),
|
accessToken: c.get('accessToken'),
|
||||||
organizationId: dashboard.organizationId,
|
organizationId: dashboard.organizationId,
|
||||||
|
type,
|
||||||
});
|
});
|
||||||
|
|
||||||
return createImageResponse(screenshotBuffer, search.type);
|
return createImageResponse(screenshotBuffer, type);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to generate chat screenshot URL', {
|
console.error('Failed to generate chat screenshot URL', {
|
||||||
dashboardId,
|
dashboardId,
|
||||||
|
|
|
@ -18,7 +18,7 @@ const app = new Hono()
|
||||||
zValidator('query', GetMetricScreenshotQuerySchema),
|
zValidator('query', GetMetricScreenshotQuerySchema),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const metricId = c.req.valid('param').id;
|
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 user = c.get('busterUser');
|
||||||
|
|
||||||
const metric = await getMetricFileById(metricId);
|
const metric = await getMetricFileById(metricId);
|
||||||
|
@ -42,14 +42,13 @@ const app = new Hono()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const type = 'png' as const;
|
||||||
const screenshotBuffer = await getMetricScreenshot({
|
const screenshotBuffer = await getMetricScreenshot({
|
||||||
metricId,
|
metricId,
|
||||||
width,
|
|
||||||
height,
|
|
||||||
version_number,
|
version_number,
|
||||||
type,
|
|
||||||
accessToken: c.get('accessToken'),
|
accessToken: c.get('accessToken'),
|
||||||
organizationId: metric.organizationId,
|
organizationId: metric.organizationId,
|
||||||
|
type,
|
||||||
});
|
});
|
||||||
|
|
||||||
return createImageResponse(screenshotBuffer, type);
|
return createImageResponse(screenshotBuffer, type);
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import GET from './GET';
|
import GET from './GET';
|
||||||
import PUT from './PUT';
|
import PUT from './PUT';
|
||||||
import SCREENSHOT from './screenshot';
|
|
||||||
import SHARING from './sharing';
|
import SHARING from './sharing';
|
||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono().route('/', GET).route('/', PUT).route('/sharing', SHARING);
|
||||||
.route('/', GET)
|
|
||||||
.route('/', PUT)
|
|
||||||
.route('/sharing', SHARING)
|
|
||||||
.route('/screenshot', SCREENSHOT);
|
|
||||||
|
|
||||||
export default app;
|
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