feat: add project schema

This commit is contained in:
2024-02-22 20:59:20 +00:00
parent b232410d83
commit d579c1b7c5
27 changed files with 338 additions and 147 deletions
+13 -2
View File
@@ -7,15 +7,26 @@ import { serveHtml } from "./serve-html";
import { serveJs } from "./serve-js";
import { getMimeType } from "~/server/lib/mime";
import { postcss } from "./postcss";
import { project } from "~/server/db/schema/project";
const get = async (req: Request, res: Response) => {
const { slug, ...pathParams } = req.params as any;
const path = pathParams[0];
const fileData = await db.query.file.findFirst({
where: and(eq(file.path, path), isNull(file.deletedAt)),
const projectData = await db.query.project.findFirst({
where: and(eq(project.slug, slug), isNull(project.deletedAt)),
});
if (!projectData) {
return res.status(404).send("Project not found!");
}
const fileData = await db.query.file.findFirst({
where: and(
eq(file.projectId, projectData.id),
eq(file.path, path),
isNull(file.deletedAt)
),
});
if (!fileData) {
return res.status(404).send("File not found!");
}
+10 -6
View File
@@ -1,12 +1,12 @@
import db from "~/server/db";
import { FileSchema, file } from "~/server/db/schema/file";
import { and, eq, isNull } from "drizzle-orm";
const preventHtmlDirectAccess = `<script>if (window === window.parent) {window.location.href = '/';}</script>`;
import { IS_DEV } from "~/server/lib/consts";
export const serveHtml = async (fileData: FileSchema) => {
const layout = await db.query.file.findFirst({
where: and(
eq(file.projectId, fileData.projectId),
eq(file.filename, "_layout.html"),
fileData.parentId
? eq(file.parentId, fileData.parentId)
@@ -22,10 +22,14 @@ export const serveHtml = async (fileData: FileSchema) => {
const bodyOpeningTagIdx = content.indexOf("<body");
const firstScriptTagIdx = content.indexOf("<script", bodyOpeningTagIdx);
const injectScripts = [
'<script src="/js/hook-console.js"></script>',
preventHtmlDirectAccess,
];
const injectScripts = ['<script src="/js/hook-console.js"></script>'];
if (!IS_DEV) {
// prevent direct access
injectScripts.push(
`<script>if (window === window.parent) {window.location.href = '/';}</script>`
);
}
const importMaps = [
{ name: "react", url: "https://esm.sh/[email protected]" },