kstulgys
kstulgys
CCConvex Community
Created by kstulgys on 9/27/2024 in #support-community
Is runMutation transactional?
I assume runAction is the same?
5 replies
CCConvex Community
Created by kstulgys on 9/17/2024 in #support-community
Whats the best practice/approach for saving and fetching convex images?
"If you have maximum of 5 images, its fine with array" What's the reasoning? "You should prefetch image url on the server, this will generate url for you that will work for 1 hour" - but this will take more time to respond right? because I need to fetch products and then all images for those products with urls
7 replies
CCConvex Community
Created by kstulgys on 8/24/2024 in #support-community
Is this is legit way to upload files? Haven't seen this in any example
Thank you for the insights!
8 replies
CCConvex Community
Created by kstulgys on 8/26/2024 in #support-community
how do I efficiently aggregate data?
thanks
3 replies
CCConvex Community
Created by kstulgys on 8/24/2024 in #support-community
Is this is legit way to upload files? Haven't seen this in any example
Is this suppose to be slower? faster? better? worse?
8 replies
CCConvex Community
Created by kstulgys on 8/24/2024 in #support-community
Is this is legit way to upload files? Haven't seen this in any example
backend image_node.ts
"use node";

import { v } from "convex/values";
import { internalAction } from "./_generated/server";

export const upload = internalAction({
args: {
base64: v.string(),
},
handler: async (ctx, args) => {
const mimeType = args.base64.match(/data:(.*?);base64/)?.[1];
const base64Data = args.base64.split(",")[1];

if (!mimeType || !base64Data) return null;

const buffer = Buffer.from(base64Data, "base64");

const uploadUrl = await ctx.storage.generateUploadUrl();

try {
const result = await fetch(uploadUrl, {
method: "POST",
headers: { "Content-Type": mimeType },
body: buffer,
});

const json = await result.json();
if (!result.ok) return null;

return json.storageId;
} catch (e) {
return null;
}
},
});
"use node";

import { v } from "convex/values";
import { internalAction } from "./_generated/server";

export const upload = internalAction({
args: {
base64: v.string(),
},
handler: async (ctx, args) => {
const mimeType = args.base64.match(/data:(.*?);base64/)?.[1];
const base64Data = args.base64.split(",")[1];

if (!mimeType || !base64Data) return null;

const buffer = Buffer.from(base64Data, "base64");

const uploadUrl = await ctx.storage.generateUploadUrl();

try {
const result = await fetch(uploadUrl, {
method: "POST",
headers: { "Content-Type": mimeType },
body: buffer,
});

const json = await result.json();
if (!result.ok) return null;

return json.storageId;
} catch (e) {
return null;
}
},
});
8 replies
CCConvex Community
Created by kstulgys on 8/24/2024 in #support-community
Is this is legit way to upload files? Haven't seen this in any example
backend image.ts
export const upload = authAction({
args: {
base64: v.string(),
table: v.union(v.literal("accounts"), v.literal("products")),
column: v.string(),
},
handler: async (ctx, args) => {
const rowId = // get row id here or from frontend

const storageId = await ctx.runAction(internal.image_node.upload, {
base64: args.base64,
});

if (!storageId) return;

await ctx.runMutation(internal.image.saveImage, {
storageId,
table: args.table,
column: args.column,
rowId,
});
},
});

export const saveImage = internalMutation({
args: {
storageId: v.id("_storage"),
table: v.union(v.literal("accounts"), v.literal("products")),
column: v.string(),
rowId: v.id("accounts"),
},
handler: async (ctx, args) => {
const entity = await ctx.table(args.table).getX(args.rowId);

const deleteStorageId = () => {
// @ts-expect-error
const previousStorageId = entity[args.column] as Id<"_storage"> | null;
if (!previousStorageId) return;
return ctx.storage.delete(previousStorageId);
};

await Promise.all([entity.patch({ [args.column]: args.storageId }), deleteStorageId()]);
},
});
export const upload = authAction({
args: {
base64: v.string(),
table: v.union(v.literal("accounts"), v.literal("products")),
column: v.string(),
},
handler: async (ctx, args) => {
const rowId = // get row id here or from frontend

const storageId = await ctx.runAction(internal.image_node.upload, {
base64: args.base64,
});

if (!storageId) return;

await ctx.runMutation(internal.image.saveImage, {
storageId,
table: args.table,
column: args.column,
rowId,
});
},
});

export const saveImage = internalMutation({
args: {
storageId: v.id("_storage"),
table: v.union(v.literal("accounts"), v.literal("products")),
column: v.string(),
rowId: v.id("accounts"),
},
handler: async (ctx, args) => {
const entity = await ctx.table(args.table).getX(args.rowId);

const deleteStorageId = () => {
// @ts-expect-error
const previousStorageId = entity[args.column] as Id<"_storage"> | null;
if (!previousStorageId) return;
return ctx.storage.delete(previousStorageId);
};

await Promise.all([entity.patch({ [args.column]: args.storageId }), deleteStorageId()]);
},
});
8 replies
CCConvex Community
Created by kstulgys on 8/21/2024 in #support-community
How do I extend convex auth with my custom auth provider?
Thank you sir, just one correction for those who will see this:
const userId = await ctx.db.runMutation(internal.users.create, userData)
return { userId }
const userId = await ctx.db.runMutation(internal.users.create, userData)
return { userId }
3 replies
CCConvex Community
Created by kstulgys on 1/20/2024 in #support-community
So close to make puppeteer working
nop, I think convex does not suport this, they mentioned on their docs as well
15 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
thank you!
25 replies
CCConvex Community
Created by kstulgys on 8/14/2024 in #support-community
Am I doing this ent query correctly?
I guess this is better, right?
export const get = authQuery({
args: {
orderId: v.id("orders"),
},
handler: async (ctx, args) => {
if (!ctx.user?.currentAccountId) return null;
const order = await ctx.table("orders").getX(args.orderId)
const account = await order.edgeX("account");
if(account._id !== ctx.user.currentAccountId) return null;
return order;
},
});
export const get = authQuery({
args: {
orderId: v.id("orders"),
},
handler: async (ctx, args) => {
if (!ctx.user?.currentAccountId) return null;
const order = await ctx.table("orders").getX(args.orderId)
const account = await order.edgeX("account");
if(account._id !== ctx.user.currentAccountId) return null;
return order;
},
});
3 replies
CCConvex Community
Created by kstulgys on 8/8/2024 in #support-community
What's the best way to manage long running functions in convex actions?
thanks for reply!
10 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
otherwise I would need to run this myself from conole right?
25 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
is there a github action example that runs npx convex deploy when changes are detected in schema.ts?
25 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
I saw preview deployments
25 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
how would you go about qa, staging and prod environment?
25 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
because it's not prod ready, I will likely be messing around with schema a lot, but I want my app to be publicly accessible
25 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
I want to use same convex environment (development) for both: local and deployed
25 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
how do I point to that? I do not want to do a production deployment
25 replies
CCConvex Community
Created by kstulgys on 8/12/2024 in #support-community
I want to deploy my website that uses convex development environment, how do I deal with SITE_URL?
but when I deploy my frontend it will be https://xyz-test.com
25 replies