Files
webdev-pipeline/convex/storage.ts

37 lines
843 B
TypeScript

import { v } from "convex/values";
import { mutation } from "./_generated/server";
export const generateScreenshotUploadUrl = mutation({
args: {},
returns: v.string(),
handler: async (ctx) => {
return await ctx.storage.generateUploadUrl();
},
});
export const attachScreenshot = mutation({
args: {
auditId: v.id("audits"),
storageId: v.id("_storage"),
viewport: v.union(v.literal("desktop"), v.literal("mobile")),
sourceUrl: v.string(),
capturedAt: v.number(),
width: v.number(),
height: v.number(),
mimeType: v.string(),
},
handler: async (ctx, args) => {
const audit = await ctx.db.get(args.auditId);
if (!audit) {
throw new Error("Audit not found.");
}
return await ctx.db.insert("auditScreenshots", {
...args,
createdAt: Date.now(),
});
},
});