/* * Copyright (c) 2022. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ import {consumeMessageQueue, handleMessageQueueChannel} from "../modules/message-queue"; import {ImageResizeResponse} from "../components/image/resize-image"; import {getCustomRepository} from "typeorm"; import {UserRepository} from "@chamesu/common/domains/auth/user/repository"; import {QueueMessage} from "../modules/message-queue/type"; function createImageAggregatorHandlers() { return { resizeFailed: async(message: QueueMessage) => { console.log('Resize failed' + message.data.resultMessage); }, resized: async (message: QueueMessage) => { const sizes : ImageResizeResponse[] = message.data.resultSizes; const type : string = message.data.type; switch (type) { case "user-avatar": case "user-cover": const userId : number = message.data.id; const repository = getCustomRepository(UserRepository); const user = await repository.findOne(userId); if(type === 'user-avatar') { for(let i=0; i { try { await handleMessageQueueChannel(channel, handlers, msg); await channel.ack(msg); } catch (e) { console.log(e); await channel.reject(msg, false); } }))); } return { start } }