-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from prtcl/spike/project-previews
spike/project previews
- Loading branch information
Showing
33 changed files
with
2,098 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
CONVEX_DEPLOYMENT="" | ||
VITE_CONVEX_URL="" | ||
VITE_CONVEX_URL="" | ||
UPLOAD_TOKEN="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,7 @@ dist | |
|
||
## Panda | ||
styled-system | ||
styled-system-studio | ||
styled-system-studio | ||
|
||
# Generated files | ||
previews |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex dev`. | ||
* @module | ||
*/ | ||
|
@@ -14,6 +13,8 @@ import type { | |
FilterApi, | ||
FunctionReference, | ||
} from "convex/server"; | ||
import type * as features from "../features.js"; | ||
import type * as previews from "../previews.js"; | ||
import type * as projects from "../projects.js"; | ||
|
||
/** | ||
|
@@ -25,6 +26,8 @@ import type * as projects from "../projects.js"; | |
* ``` | ||
*/ | ||
declare const fullApi: ApiFromModules<{ | ||
features: typeof features; | ||
previews: typeof previews; | ||
projects: typeof projects; | ||
}>; | ||
export declare const api: FilterApi< | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex dev`. | ||
* @module | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex dev`. | ||
* @module | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex dev`. | ||
* @module | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
* | ||
* THIS CODE IS AUTOMATICALLY GENERATED. | ||
* | ||
* Generated by [email protected]. | ||
* To regenerate, run `npx convex dev`. | ||
* @module | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { internalMutation, query } from './_generated/server'; | ||
|
||
export const loadFeatureFlags = query({ | ||
args: {}, | ||
handler: async (ctx) => { | ||
return await ctx.db.query('features').collect(); | ||
}, | ||
}); | ||
|
||
export const populateFeatureFlags = internalMutation({ | ||
args: {}, | ||
handler: async (ctx) => { | ||
const initialFlags = ['isProjectPreviewsEnabled']; | ||
const existingFeatures = await ctx.db.query('features').collect(); | ||
const existingKeys = new Set(existingFeatures.map((f) => f.key)); | ||
const res: string[] = []; | ||
|
||
for (const flag of initialFlags) { | ||
if (!existingKeys.has(flag)) { | ||
const insertedId = await ctx.db.insert('features', { | ||
key: flag, | ||
value: false, | ||
}); | ||
res.push(insertedId); | ||
} | ||
} | ||
|
||
return res; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { ConvexError, v } from 'convex/values'; | ||
import { mutation, query } from './_generated/server'; | ||
|
||
export const loadProjectPreview = query({ | ||
args: { | ||
projectId: v.id('projects'), | ||
}, | ||
handler: async (ctx, { projectId }) => { | ||
const project = await ctx.db.get(projectId); | ||
|
||
if (!project) { | ||
throw new ConvexError({ | ||
message: 'Project not found', | ||
code: 404, | ||
}); | ||
} | ||
|
||
const preview = await ctx.db | ||
.query('previews') | ||
.withIndex('project', (q) => q.eq('projectId', project._id)) | ||
.filter((q) => q.eq(q.field('deletedAt'), null)) | ||
.unique(); | ||
|
||
if (!preview) { | ||
throw new ConvexError({ | ||
message: 'Preview not found', | ||
code: 404, | ||
}); | ||
} | ||
|
||
const publicUrl = await ctx.storage.getUrl(preview.storageId); | ||
|
||
if (publicUrl) { | ||
return { | ||
...preview, | ||
publicUrl, | ||
}; | ||
} | ||
|
||
return null; | ||
}, | ||
}); | ||
|
||
export const generateUploadUrl = mutation({ | ||
args: { token: v.string() }, | ||
handler: async (ctx, { token }) => { | ||
if (token !== process.env.UPLOAD_TOKEN) { | ||
throw new Error('Unauthorized'); | ||
} | ||
|
||
const uploadUrl = await ctx.storage.generateUploadUrl(); | ||
|
||
return { uploadUrl }; | ||
}, | ||
}); | ||
|
||
export const createPreview = mutation({ | ||
args: { | ||
projectId: v.id('projects'), | ||
storageId: v.id('_storage'), | ||
token: v.string(), | ||
}, | ||
handler: async (ctx, { projectId, storageId, token }) => { | ||
if (token !== process.env.UPLOAD_TOKEN) { | ||
throw new Error('Unauthorized'); | ||
} | ||
|
||
const existingPreview = await ctx.db | ||
.query('previews') | ||
.withIndex('project', (q) => q.eq('projectId', projectId)) | ||
.filter((q) => q.eq(q.field('deletedAt'), null)) | ||
.unique(); | ||
|
||
if (existingPreview) { | ||
return await ctx.db.patch(existingPreview._id, { storageId }); | ||
} | ||
|
||
return await ctx.db.insert('previews', { | ||
deletedAt: null, | ||
projectId, | ||
storageId, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.