feat(*): send images from website
This commit is contained in:
@@ -10,11 +10,33 @@ export const list = query({
|
||||
userId: v.id('users'),
|
||||
chatId: v.id('chats'),
|
||||
userMessage: v.string(),
|
||||
imagesBase64: v.optional(v.array(v.string())),
|
||||
imagesMediaTypes: v.optional(v.array(v.string())),
|
||||
createdAt: v.number()
|
||||
})
|
||||
),
|
||||
handler: async (ctx) => {
|
||||
return await ctx.db.query('pendingGenerations').collect();
|
||||
const pending = await ctx.db.query('pendingGenerations').collect();
|
||||
|
||||
const result = [];
|
||||
for (const p of pending) {
|
||||
const images = await ctx.db
|
||||
.query('pendingGenerationImages')
|
||||
.withIndex('by_pending_generation_id', (q) => q.eq('pendingGenerationId', p._id))
|
||||
.collect();
|
||||
|
||||
const sortedImages = images.sort((a, b) => a.order - b.order);
|
||||
|
||||
result.push({
|
||||
...p,
|
||||
imagesBase64:
|
||||
sortedImages.length > 0 ? sortedImages.map((img) => img.base64) : p.imagesBase64,
|
||||
imagesMediaTypes:
|
||||
sortedImages.length > 0 ? sortedImages.map((img) => img.mediaType) : p.imagesMediaTypes
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -39,7 +61,35 @@ export const remove = mutation({
|
||||
args: { id: v.id('pendingGenerations') },
|
||||
returns: v.null(),
|
||||
handler: async (ctx, args) => {
|
||||
const images = await ctx.db
|
||||
.query('pendingGenerationImages')
|
||||
.withIndex('by_pending_generation_id', (q) => q.eq('pendingGenerationId', args.id))
|
||||
.collect();
|
||||
for (const img of images) {
|
||||
await ctx.db.delete(img._id);
|
||||
}
|
||||
await ctx.db.delete(args.id);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
export const getImages = query({
|
||||
args: { pendingGenerationId: v.id('pendingGenerations') },
|
||||
returns: v.array(
|
||||
v.object({
|
||||
base64: v.string(),
|
||||
mediaType: v.string()
|
||||
})
|
||||
),
|
||||
handler: async (ctx, args) => {
|
||||
const images = await ctx.db
|
||||
.query('pendingGenerationImages')
|
||||
.withIndex('by_pending_generation_id', (q) =>
|
||||
q.eq('pendingGenerationId', args.pendingGenerationId)
|
||||
)
|
||||
.collect();
|
||||
return images
|
||||
.sort((a, b) => a.order - b.order)
|
||||
.map((img) => ({ base64: img.base64, mediaType: img.mediaType }));
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user