fix: sandboxes now linked to specific users
This commit is contained in:
parent
e7dd3238df
commit
2994a4d291
@ -110,12 +110,17 @@ export default {
|
|||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
const { type, name, userId, visibility } = initSchema.parse(body)
|
const { type, name, userId, visibility } = initSchema.parse(body)
|
||||||
|
|
||||||
const allSandboxes = await db.select().from(sandbox).all()
|
const userSandboxes = await db
|
||||||
if (allSandboxes.length >= 8) {
|
.select()
|
||||||
return new Response("You reached the maximum # of sandboxes.", {
|
.from(sandbox)
|
||||||
status: 400,
|
.where(eq(sandbox.userId, userId))
|
||||||
})
|
.all();
|
||||||
}
|
|
||||||
|
if (userSandboxes.length >= 8) {
|
||||||
|
return new Response("You reached the maximum # of sandboxes.", {
|
||||||
|
status: 400,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const sb = await db
|
const sb = await db
|
||||||
.insert(sandbox)
|
.insert(sandbox)
|
||||||
@ -123,6 +128,12 @@ export default {
|
|||||||
.returning()
|
.returning()
|
||||||
.get()
|
.get()
|
||||||
|
|
||||||
|
// Create a new association record in the users_to_sandboxes table
|
||||||
|
await db
|
||||||
|
.insert(usersToSandboxes)
|
||||||
|
.values({ userId, sandboxId: sb.id, sharedOn: new Date() })
|
||||||
|
.get();
|
||||||
|
|
||||||
const initStorageRequest = new Request(
|
const initStorageRequest = new Request(
|
||||||
`${env.STORAGE_WORKER_URL}/api/init`,
|
`${env.STORAGE_WORKER_URL}/api/init`,
|
||||||
{
|
{
|
||||||
|
@ -31,8 +31,8 @@ export const sandbox = sqliteTable("sandbox", {
|
|||||||
createdAt: integer("createdAt", { mode: "timestamp_ms" }),
|
createdAt: integer("createdAt", { mode: "timestamp_ms" }),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => user.id),
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Sandbox = typeof sandbox.$inferSelect;
|
export type Sandbox = typeof sandbox.$inferSelect;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user