broker direcrtory renewed, imageservice updated, demo data
This commit is contained in:
@@ -30,19 +30,33 @@ export class FileService {
|
||||
return this.subscriptions
|
||||
}
|
||||
async storeProfilePicture(file: Express.Multer.File, userId: string) {
|
||||
const suffix = file.mimetype.includes('png') ? 'png' : 'jpg'
|
||||
await fs.outputFile(`./pictures/profile/${userId}`, file.buffer);
|
||||
// const suffix = file.mimetype.includes('png') ? 'png' : 'jpg'
|
||||
// await fs.outputFile(`./pictures/profile/${userId}`, file.buffer);
|
||||
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`);
|
||||
}
|
||||
hasProfile(userId: string){
|
||||
return fs.existsSync(`./pictures/profile/${userId}`)
|
||||
return fs.existsSync(`./pictures/profile/${userId}.avif`)
|
||||
}
|
||||
|
||||
async storeCompanyLogo(file: Express.Multer.File, userId: string) {
|
||||
const suffix = file.mimetype.includes('png') ? 'png' : 'jpg'
|
||||
await fs.outputFile(`./pictures/logo/${userId}`, file.buffer);
|
||||
// const suffix = file.mimetype.includes('png') ? 'png' : 'jpg'
|
||||
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 fs.outputFile(`./pictures/logo/${userId}`, file.buffer);
|
||||
}
|
||||
hasCompanyLogo(userId: string){
|
||||
return fs.existsSync(`./pictures/logo/${userId}`)
|
||||
return fs.existsSync(`./pictures/logo/${userId}.avif`)
|
||||
}
|
||||
|
||||
async getPropertyImages(listingId: string): Promise<ImageProperty[]> {
|
||||
@@ -103,13 +117,28 @@ export class FileService {
|
||||
//.webp({ quality }) // Verwende Webp
|
||||
.toBuffer();
|
||||
|
||||
if (output.byteLength > maxSize) {
|
||||
quality -= 5; // Justiere Qualität in feineren Schritten
|
||||
}
|
||||
// if (output.byteLength > maxSize) {
|
||||
// quality -= 5; // Justiere Qualität in feineren Schritten
|
||||
// }
|
||||
// } while (output.byteLength > maxSize && quality > 0);
|
||||
await sharp(output).toFile(`${directory}/${imageName}.avif`); // Ersetze Dateierweiterung
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user