broker direcrtory renewed, imageservice updated, demo data

This commit is contained in:
2024-03-25 20:17:49 +01:00
parent 73ab12a694
commit 840d7a63b1
30 changed files with 616 additions and 212 deletions

View File

@@ -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;
}
}

View File

@@ -23,13 +23,22 @@ export class ImageController {
@Post('uploadProfile/:id')
@UseInterceptors(FileInterceptor('file'),)
uploadProfile(@UploadedFile() file: Express.Multer.File,@Param('id') id:string) {
this.fileService.storeProfilePicture(file,id);
async uploadProfile(@UploadedFile() file: Express.Multer.File,@Param('id') id:string) {
await this.fileService.storeProfilePicture(file,id);
}
@Post('uploadCompanyLogo/:id')
@UseInterceptors(FileInterceptor('file'),)
uploadCompanyLogo(@UploadedFile() file: Express.Multer.File,@Param('id') id:string) {
this.fileService.storeCompanyLogo(file,id);
async uploadCompanyLogo(@UploadedFile() file: Express.Multer.File,@Param('id') id:string) {
await this.fileService.storeCompanyLogo(file,id);
}
@Get('profileImages/:userids')
async getProfileImagesForUsers(@Param('userids') userids:string): Promise<any> {
return await this.fileService.getProfileImagesForUsers(userids);
}
@Get('companyLogos/:userids')
async getCompanyLogosForUsers(@Param('userids') userids:string): Promise<any> {
return await this.fileService.getCompanyLogosForUsers(userids);
}
}

View File

@@ -7,22 +7,30 @@ import { UserEntity } from 'src/models/server.model.js';
@Controller('user')
export class UserController {
constructor(private userService:UserService,@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger){}
@Get(':id')
findById(@Param('id') id:string): any {
return this.userService.getUserById(id);
}
constructor(private userService: UserService, @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) {}
@Post()
save(@Body() user: any):Promise<UserEntity>{
this.logger.info(`User persisted: `);
return this.userService.saveUser(user);
}
@Post('search')
find(@Body() criteria: any): any {
return this.userService.findUser(criteria);
}
@Get(':id')
findById(@Param('id') id: string): any {
this.logger.info(`Searching for user with ID: ${id}`);
const user = this.userService.getUserById(id);
this.logger.info(`Found user: ${JSON.stringify(user)}`);
return user;
}
@Post()
save(@Body() user: any): Promise<UserEntity> {
this.logger.info(`Saving user: ${JSON.stringify(user)}`);
const savedUser = this.userService.saveUser(user);
this.logger.info(`User persisted: ${JSON.stringify(savedUser)}`);
return savedUser;
}
@Post('search')
find(@Body() criteria: any): any {
this.logger.info(`Searching for users with criteria: ${JSON.stringify(criteria)}`);
const foundUsers = this.userService.findUser(criteria);
this.logger.info(`Found users: ${JSON.stringify(foundUsers)}`);
return foundUsers;
}
}

View File

@@ -19,7 +19,7 @@ export class UserService {
companyWebsite:{ type: 'string' },
companyLocation:{ type: 'string' },
offeredServices:{ type: 'string' },
areasServed:{ type: 'string' },
areasServed:{ type: 'string[]' },
names:{ type: 'string[]', path:'$.licensedIn.name' },
values:{ type: 'string[]', path:'$.licensedIn.value' }
}, {