diff --git a/.gitignore b/.gitignore index ae24b57..907ab15 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ pnpm-debug.log* # jetbrains setting folder .idea/ +photos/ public/IMG/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 79aa04e..99c9e37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ WORKDIR /app COPY . . -RUN mkdir -p /app/public/IMG +RUN mkdir -p /app/dist/client/IMG RUN npm install @@ -13,6 +13,6 @@ ENV HOST=0.0.0.0 ENV PORT=4321 EXPOSE 4321 -ENV PHOTO_DIR_ABSOLUTE_PATH=/app/public/IMG +ENV PHOTO_DIR_ABSOLUTE_PATH=/app/dist/client/IMG CMD ["node", "./dist/server/entry.mjs"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 88bdd75..974045c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,4 +6,4 @@ services: ports: - "4321:4321" volumes: - - ./photos:/app/public/IMG + - ./photos:/app/dist/client/IMG diff --git a/src/pages/IMG/[file].ts b/src/pages/IMG/[file].ts new file mode 100644 index 0000000..f0caeae --- /dev/null +++ b/src/pages/IMG/[file].ts @@ -0,0 +1,24 @@ +import fs from "node:fs"; +import path from "node:path"; +import type { APIRoute } from "astro"; + +export const prerender = false; + +export const GET: APIRoute = ({ params }) => { + const file = params.file; + + const filePath = path.join(process.env.PHOTO_DIR_ABSOLUTE_PATH!, file!); + + if (!fs.existsSync(filePath)) { + return new Response("Image introuvable", { status: 404 }); + } + + const image = fs.readFileSync(filePath); + + return new Response(image, { + headers: { + "Content-Type": "image/jpeg", + "Cache-Control": "public, max-age=31536000", + }, + }); +}; diff --git a/src/pages/index.astro b/src/pages/index.astro index 19795a9..d80b389 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -6,6 +6,7 @@ import Layout from "../components/Layout.astro"; import Image from "../components/Image.astro"; import { initPhotos } from "../misc"; import { PHOTO_DIR_ABSOLUTE_PATH } from "astro:env/server"; +export const prerender = false; const imageFilenames = fs .readdirSync(PHOTO_DIR_ABSOLUTE_PATH) diff --git a/src/pages/photos/[filename].astro b/src/pages/photos/[filename].astro index af8bc5c..5523e19 100644 --- a/src/pages/photos/[filename].astro +++ b/src/pages/photos/[filename].astro @@ -38,8 +38,6 @@ const p = initPhoto( Number(width), Number(height), ); - -console.log(tags); ---