feat(api): handle production gallery path
This commit is contained in:
@@ -4,6 +4,10 @@ import { createHash } from "crypto";
|
|||||||
import exifr from "exifr";
|
import exifr from "exifr";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const galleryDir = import.meta.dev
|
||||||
|
? join(process.cwd(), "public/gallery")
|
||||||
|
: join(process.cwd(), ".output/public/gallery");
|
||||||
|
|
||||||
const exifSchema = z.object({
|
const exifSchema = z.object({
|
||||||
DateTimeOriginal: z.date(),
|
DateTimeOriginal: z.date(),
|
||||||
Make: z.string(),
|
Make: z.string(),
|
||||||
@@ -19,17 +23,15 @@ const exifSchema = z.object({
|
|||||||
|
|
||||||
export default defineCachedEventHandler(
|
export default defineCachedEventHandler(
|
||||||
async () => {
|
async () => {
|
||||||
const publicDir = join(process.cwd(), "public/gallery");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const files = await readdir(publicDir);
|
const files = await readdir(galleryDir);
|
||||||
const imageFiles = files.filter((file) =>
|
const imageFiles = files.filter((file) =>
|
||||||
/\.(jpg|jpeg|png|webp)$/i.test(file),
|
/\.(jpg|jpeg|png|webp)$/i.test(file),
|
||||||
);
|
);
|
||||||
|
|
||||||
const imagesWithExif = await Promise.all(
|
const imagesWithExif = await Promise.all(
|
||||||
imageFiles.map(async (filename) => {
|
imageFiles.map(async (filename) => {
|
||||||
const filePath = join(publicDir, filename);
|
const filePath = join(galleryDir, filename);
|
||||||
const rawExif = await exifr.parse(filePath, {
|
const rawExif = await exifr.parse(filePath, {
|
||||||
tiff: true,
|
tiff: true,
|
||||||
exif: true,
|
exif: true,
|
||||||
@@ -72,9 +74,8 @@ export default defineCachedEventHandler(
|
|||||||
{
|
{
|
||||||
maxAge: 60 * 60 * 24,
|
maxAge: 60 * 60 * 24,
|
||||||
getKey: async () => {
|
getKey: async () => {
|
||||||
const publicDir = join(process.cwd(), "public/gallery");
|
|
||||||
try {
|
try {
|
||||||
const files = await readdir(publicDir);
|
const files = await readdir(galleryDir);
|
||||||
const imageFiles = files.filter((file) =>
|
const imageFiles = files.filter((file) =>
|
||||||
/\.(jpg|jpeg|png|webp)$/i.test(file),
|
/\.(jpg|jpeg|png|webp)$/i.test(file),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user