Skip to content

Commit

Permalink
Add dev and prod cache
Browse files Browse the repository at this point in the history
  • Loading branch information
constantgillet committed May 1, 2024
1 parent d7643e4 commit 4968d92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 0 additions & 2 deletions app/routes/_app.editor.$templateId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export default function Index() {

const infiniteViewer = useRef<InfiniteViewer>(null);

console.log(template);

if (typeof document === "undefined") {
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion app/routes/api.render.$templateId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {

const cacheKey = `render-${variablesValuesHashed}`;

const imageLocation = `${CACHED_FOLDER}${templateId}/${cacheKey}.png`;
const imageLocation = `${CACHED_FOLDER}${templateId}/${
isDraft ? "draft" : "prod"
}/${cacheKey}.png`;

const resFileExists = await fileExists(imageLocation);

Expand Down
5 changes: 5 additions & 0 deletions app/routes/api.update-template-to-prod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { ActionFunctionArgs, json } from "@remix-run/node";
import { withZod } from "@remix-validated-form/with-zod";
import { validationError } from "remix-validated-form";
import { z } from "zod";
import { CACHED_FOLDER } from "~/constants/s3Constants";
import { ensureAuthenticated } from "~/libs/lucia";
import { prisma } from "~/libs/prisma";
import { deleteFolder } from "~/libs/s3";

export const updateTemplateToProdValidator = withZod(
z.object({
Expand Down Expand Up @@ -53,6 +55,9 @@ export async function action({ context, request }: ActionFunctionArgs) {
},
});

const folder = `${CACHED_FOLDER}${templateId}/prod/`;
deleteFolder(folder);

return json({ ok: true });
} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion app/routes/api.update-template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function action({ context, request }: ActionFunctionArgs) {
});

//Template folder cached
const folder = `${CACHED_FOLDER}${templateId}/`;
const folder = `${CACHED_FOLDER}${templateId}/draft/`;

//Delete all the files cached
deleteFolder(folder);
Expand Down

0 comments on commit 4968d92

Please sign in to comment.