feat: wire convex data foundations
This commit is contained in:
36
convex/storage.ts
Normal file
36
convex/storage.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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(),
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user