fix: now display images in /public + Dockerfile
This commit is contained in:
parent
28cda26023
commit
29f0976f84
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules/
|
||||||
|
pnpm-lock.yaml
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -23,4 +23,4 @@ pnpm-debug.log*
|
|||||||
# jetbrains setting folder
|
# jetbrains setting folder
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
src/assets/IMG/
|
public/IMG/
|
||||||
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
FROM node:lts AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN mkdir -p /app/public/IMG
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
ENV HOST=0.0.0.0
|
||||||
|
ENV PORT=4321
|
||||||
|
EXPOSE 4321
|
||||||
|
|
||||||
|
ENV PHOTO_DIR_ABSOLUTE_PATH=/app/public/IMG
|
||||||
|
|
||||||
|
CMD ["node", "./dist/server/entry.mjs"]
|
||||||
9
docker-compose.yml
Normal file
9
docker-compose.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
my-album:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "4321:4321"
|
||||||
|
volumes:
|
||||||
|
- ./photos:/app/public/IMG
|
||||||
27
src/misc.ts
27
src/misc.ts
@ -1,33 +1,30 @@
|
|||||||
import { Photo } from "./models/photo";
|
import { Photo } from "./models/photo";
|
||||||
|
|
||||||
export function initPhoto(
|
export function initPhoto(
|
||||||
image: any,
|
filename: string,
|
||||||
description: string,
|
description: string,
|
||||||
model: string,
|
model: string,
|
||||||
filename: string,
|
width: number = 0,
|
||||||
|
height: number = 0,
|
||||||
): Photo {
|
): Photo {
|
||||||
return {
|
return {
|
||||||
src: image.default.src,
|
src: `/IMG/${filename}`,
|
||||||
filename: filename,
|
filename: filename,
|
||||||
format: image.default.format,
|
format: filename.split(".").pop()?.toUpperCase() || "JPG",
|
||||||
height: image.default.height,
|
height: height,
|
||||||
width: image.default.width,
|
width: width,
|
||||||
description: description,
|
description: description,
|
||||||
model: model,
|
model: model,
|
||||||
} as Photo;
|
} as Photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initPhotos(images: any): Photo[] {
|
export function initPhotos(filenames: string[]): Photo[] {
|
||||||
return Object.values(images)
|
return filenames
|
||||||
.map((img: any) => {
|
.map((filename: string) => {
|
||||||
const splited = img.default.src.split("/");
|
|
||||||
const filename: string = splited[splited.length - 1].split("?")[0];
|
|
||||||
|
|
||||||
return initPhoto(
|
return initPhoto(
|
||||||
img,
|
|
||||||
"Aucune description disponible",
|
|
||||||
"Aucun model d'appareil photo disponible",
|
|
||||||
filename,
|
filename,
|
||||||
|
"Aucune description disponible",
|
||||||
|
"Aucun modèle d'appareil photo disponible",
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.reverse();
|
.reverse();
|
||||||
|
|||||||
@ -1,10 +1,20 @@
|
|||||||
---
|
---
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
import "../styles/index.css";
|
import "../styles/index.css";
|
||||||
import Layout from "../components/Layout.astro";
|
import Layout from "../components/Layout.astro";
|
||||||
import Image from "../components/Image.astro";
|
import Image from "../components/Image.astro";
|
||||||
import { initPhotos } from "../misc";
|
import { initPhotos } from "../misc";
|
||||||
const imagesObj: any = import.meta.glob("../assets/IMG/*.JPG", { eager: true });
|
import { PHOTO_DIR_ABSOLUTE_PATH } from "astro:env/server";
|
||||||
const images = initPhotos(imagesObj);
|
|
||||||
|
const imageFilenames = fs
|
||||||
|
.readdirSync(PHOTO_DIR_ABSOLUTE_PATH)
|
||||||
|
.filter((file) => {
|
||||||
|
const extension = path.extname(file).toLowerCase();
|
||||||
|
return extension === ".jpg" || extension === ".jpeg";
|
||||||
|
});
|
||||||
|
|
||||||
|
const images = initPhotos(imageFilenames);
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout>
|
||||||
|
|||||||
@ -1,37 +1,45 @@
|
|||||||
---
|
---
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
import "../../styles/detail.css";
|
import "../../styles/detail.css";
|
||||||
|
import fs from "fs";
|
||||||
import ExifReader from "exifreader";
|
import ExifReader from "exifreader";
|
||||||
import Layout from "../../components/Layout.astro";
|
import Layout from "../../components/Layout.astro";
|
||||||
import { Photo } from "../../models/photo";
|
|
||||||
const { filename } = Astro.params;
|
|
||||||
import { PHOTO_DIR_ABSOLUTE_PATH } from "astro:env/server";
|
import { PHOTO_DIR_ABSOLUTE_PATH } from "astro:env/server";
|
||||||
import { initPhoto } from "../../misc";
|
import { initPhoto } from "../../misc";
|
||||||
|
|
||||||
const relativePath = `../../assets/IMG/${filename}`;
|
const { filename } = Astro.params;
|
||||||
const allImages: any = import.meta.glob("../../assets/IMG/*.JPG", {
|
|
||||||
eager: true,
|
|
||||||
});
|
|
||||||
const imageImport = allImages[relativePath];
|
|
||||||
let p: Photo = new Photo();
|
|
||||||
|
|
||||||
if (imageImport && filename) {
|
if (!filename) {
|
||||||
const absolutePath = `${PHOTO_DIR_ABSOLUTE_PATH}/${filename}`;
|
|
||||||
const tags = await ExifReader.load(absolutePath);
|
|
||||||
|
|
||||||
p = initPhoto(
|
|
||||||
imageImport,
|
|
||||||
(p.description = tags.title
|
|
||||||
? tags.title.description
|
|
||||||
: "Aucune description disponible"),
|
|
||||||
(p.model = tags.Model
|
|
||||||
? tags.Model.description
|
|
||||||
: "Aucun model d'appareil photo disponible"),
|
|
||||||
filename,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return Astro.redirect("/");
|
return Astro.redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const absolutePath = `${PHOTO_DIR_ABSOLUTE_PATH}/${filename}`;
|
||||||
|
|
||||||
|
if (!fs.existsSync(absolutePath)) {
|
||||||
|
return Astro.redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
const tags = await ExifReader.load(absolutePath);
|
||||||
|
|
||||||
|
const description = tags.title
|
||||||
|
? tags.title.description
|
||||||
|
: "Aucune description disponible";
|
||||||
|
const model = tags.Model
|
||||||
|
? tags.Model.description
|
||||||
|
: "Aucun modèle d'appareil photo disponible";
|
||||||
|
|
||||||
|
const width = tags["Image Width"] ? tags["Image Width"].value : 0;
|
||||||
|
const height = tags["Image Height"] ? tags["Image Height"].value : 0;
|
||||||
|
|
||||||
|
const p = initPhoto(
|
||||||
|
filename,
|
||||||
|
description,
|
||||||
|
model,
|
||||||
|
Number(width),
|
||||||
|
Number(height),
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(tags);
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user