Add Galerie Controller
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
@Injectable()
|
||||
export class GalerieService {
|
||||
private readonly imagesPath = "/bilder";
|
||||
|
||||
constructor(
|
||||
){}
|
||||
|
||||
async getBilder(
|
||||
event: string,
|
||||
jahr: string
|
||||
): Promise<string[]> {
|
||||
const files= await fs.readdir(path.join(this.imagesPath,event, jahr));
|
||||
|
||||
// Nur Bilddateien filtern
|
||||
const imageFiles = files.filter(file =>
|
||||
/\.(jpg|jpeg|png|gif|webp)$/i.test(file)
|
||||
);
|
||||
|
||||
return imageFiles;
|
||||
}
|
||||
|
||||
async getJahre(
|
||||
event: string
|
||||
): Promise<string[]> {
|
||||
const files= await fs.readdir(path.join(this.imagesPath,event));
|
||||
|
||||
// Nur Verzeichnisse filtern (Jahre)
|
||||
const directories: string[] = [];
|
||||
for (const file of files) {
|
||||
const filePath = path.join(this.imagesPath, event, file);
|
||||
const stat = await fs.stat(filePath);
|
||||
if (stat.isDirectory()) {
|
||||
directories.push(file);
|
||||
}
|
||||
}
|
||||
return directories;
|
||||
}
|
||||
|
||||
async getBild(
|
||||
|
||||
|
||||
) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user