imagePath changed
This commit is contained in:
@@ -20,6 +20,9 @@ export class FileService {
|
||||
fs.ensureDirSync(`./pictures/logo`);
|
||||
fs.ensureDirSync(`./pictures/property`);
|
||||
}
|
||||
// ############
|
||||
// Subscriptions
|
||||
// ############
|
||||
private loadSubscriptions(): void {
|
||||
const filePath = join(__dirname, '../..', 'assets', 'subscriptions.json');
|
||||
const rawData = readFileSync(filePath, 'utf8');
|
||||
@@ -28,36 +31,43 @@ export class FileService {
|
||||
getSubscriptions(): Subscription[] {
|
||||
return this.subscriptions;
|
||||
}
|
||||
async storeProfilePicture(file: Express.Multer.File, userId: string) {
|
||||
// ############
|
||||
// Profile
|
||||
// ############
|
||||
async storeProfilePicture(file: Express.Multer.File, adjustedEmail: string) {
|
||||
let quality = 50;
|
||||
const output = await sharp(file.buffer)
|
||||
.resize({ width: 300 })
|
||||
.avif({ quality }) // Verwende AVIF
|
||||
//.webp({ quality }) // Verwende Webp
|
||||
.toBuffer();
|
||||
await sharp(output).toFile(`./pictures/profile/${userId}.avif`);
|
||||
await sharp(output).toFile(`./pictures/profile/${adjustedEmail}.avif`);
|
||||
}
|
||||
hasProfile(userId: string) {
|
||||
return fs.existsSync(`./pictures/profile/${userId}.avif`);
|
||||
hasProfile(adjustedEmail: string) {
|
||||
return fs.existsSync(`./pictures/profile/${adjustedEmail}.avif`);
|
||||
}
|
||||
|
||||
async storeCompanyLogo(file: Express.Multer.File, userId: string) {
|
||||
// ############
|
||||
// Logo
|
||||
// ############
|
||||
async storeCompanyLogo(file: Express.Multer.File, adjustedEmail: string) {
|
||||
let quality = 50;
|
||||
const output = await sharp(file.buffer)
|
||||
.resize({ width: 300 })
|
||||
.avif({ quality }) // Verwende AVIF
|
||||
//.webp({ quality }) // Verwende Webp
|
||||
.toBuffer();
|
||||
await sharp(output).toFile(`./pictures/logo/${userId}.avif`); // Ersetze Dateierweiterung
|
||||
await sharp(output).toFile(`./pictures/logo/${adjustedEmail}.avif`); // Ersetze Dateierweiterung
|
||||
// await fs.outputFile(`./pictures/logo/${userId}`, file.buffer);
|
||||
}
|
||||
hasCompanyLogo(userId: string) {
|
||||
return fs.existsSync(`./pictures/logo/${userId}.avif`) ? true : false;
|
||||
hasCompanyLogo(adjustedEmail: string) {
|
||||
return fs.existsSync(`./pictures/logo/${adjustedEmail}.avif`) ? true : false;
|
||||
}
|
||||
|
||||
async getPropertyImages(listingId: string): Promise<string[]> {
|
||||
// ############
|
||||
// Property
|
||||
// ############
|
||||
async getPropertyImages(imagePath: string, serial: string): Promise<string[]> {
|
||||
const result: string[] = [];
|
||||
const directory = `./pictures/property/${listingId}`;
|
||||
const directory = `./pictures/property/${imagePath}/${serial}`;
|
||||
if (fs.existsSync(directory)) {
|
||||
const files = await fs.readdir(directory);
|
||||
files.forEach(f => {
|
||||
@@ -68,9 +78,9 @@ export class FileService {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
async hasPropertyImages(listingId: string): Promise<boolean> {
|
||||
async hasPropertyImages(imagePath: string, serial: string): Promise<boolean> {
|
||||
const result: ImageProperty[] = [];
|
||||
const directory = `./pictures/property/${listingId}`;
|
||||
const directory = `./pictures/property/${imagePath}/${serial}`;
|
||||
if (fs.existsSync(directory)) {
|
||||
const files = await fs.readdir(directory);
|
||||
return files.length > 0;
|
||||
@@ -78,15 +88,18 @@ export class FileService {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async storePropertyPicture(file: Express.Multer.File, listingId: string): Promise<string> {
|
||||
async storePropertyPicture(file: Express.Multer.File, imagePath: string, serial: string): Promise<string> {
|
||||
const suffix = file.mimetype.includes('png') ? 'png' : 'jpg';
|
||||
const directory = `./pictures/property/${listingId}`;
|
||||
const directory = `./pictures/property/${imagePath}/${serial}`;
|
||||
fs.ensureDirSync(`${directory}`);
|
||||
const imageName = await this.getNextImageName(directory);
|
||||
//await fs.outputFile(`${directory}/${imageName}`, file.buffer);
|
||||
await this.resizeImageToAVIF(file.buffer, 150 * 1024, imageName, directory);
|
||||
return `${imageName}.avif`;
|
||||
}
|
||||
// ############
|
||||
// utils
|
||||
// ############
|
||||
async getNextImageName(directory) {
|
||||
try {
|
||||
const files = await fs.readdir(directory);
|
||||
@@ -115,22 +128,22 @@ export class FileService {
|
||||
let timeTaken = Date.now() - start;
|
||||
this.logger.info(`Quality: ${quality} - Time: ${timeTaken} milliseconds`);
|
||||
}
|
||||
getProfileImagesForUsers(userids: string) {
|
||||
const ids = userids.split(',');
|
||||
let result = {};
|
||||
for (const id of ids) {
|
||||
result = { ...result, [id]: fs.existsSync(`./pictures/profile/${id}.avif`) };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
getCompanyLogosForUsers(userids: string) {
|
||||
const ids = userids.split(',');
|
||||
let result = {};
|
||||
for (const id of ids) {
|
||||
result = { ...result, [id]: fs.existsSync(`./pictures/logo/${id}.avif`) };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// getProfileImagesForUsers(userids: string) {
|
||||
// const ids = userids.split(',');
|
||||
// let result = {};
|
||||
// for (const id of ids) {
|
||||
// result = { ...result, [id]: fs.existsSync(`./pictures/profile/${id}.avif`) };
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
// getCompanyLogosForUsers(userids: string) {
|
||||
// const ids = userids.split(',');
|
||||
// let result = {};
|
||||
// for (const id of ids) {
|
||||
// result = { ...result, [id]: fs.existsSync(`./pictures/logo/${id}.avif`) };
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
deleteImage(path: string) {
|
||||
fs.unlinkSync(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user