diff --git a/services/matrix-nutriphi-bot/src/media/media.service.ts b/services/matrix-nutriphi-bot/src/media/media.service.ts index 322b04e00..32a0819ba 100644 --- a/services/matrix-nutriphi-bot/src/media/media.service.ts +++ b/services/matrix-nutriphi-bot/src/media/media.service.ts @@ -1,19 +1,24 @@ import { Injectable, Logger, OnModuleInit } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { MediaClient, MediaResult } from '@manacore/media-client'; + +export interface MediaResult { + id: string; + hash: string; + url: string; +} @Injectable() export class MediaService implements OnModuleInit { private readonly logger = new Logger(MediaService.name); - private client: MediaClient | null = null; + private mediaUrl: string | null = null; constructor(private configService: ConfigService) {} onModuleInit() { const mediaUrl = this.configService.get('media.url'); if (mediaUrl) { - this.client = new MediaClient(mediaUrl); - this.logger.log(`MediaClient initialized with URL: ${mediaUrl}`); + this.mediaUrl = mediaUrl; + this.logger.log(`MediaService initialized with URL: ${mediaUrl}`); } else { this.logger.warn('MANA_MEDIA_URL not configured, media storage disabled'); } @@ -24,18 +29,27 @@ export class MediaService implements OnModuleInit { * Returns the media record if successful, null if disabled or failed. */ async storeFromMatrix(mxcUrl: string, userId: string): Promise { - if (!this.client) { + if (!this.mediaUrl) { this.logger.debug('Media storage disabled, skipping storage'); return null; } try { - const result = await this.client.importFromMatrix({ - mxcUrl, - app: 'nutriphi', - userId, + const response = await fetch(`${this.mediaUrl}/api/v1/import/matrix`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + mxcUrl, + app: 'nutriphi', + userId, + }), }); + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } + + const result = (await response.json()) as MediaResult; this.logger.log(`Stored media from Matrix: ${result.id} (hash: ${result.hash})`); return result; } catch (error) { @@ -44,40 +58,10 @@ export class MediaService implements OnModuleInit { } } - /** - * Check if a file already exists by hash - */ - async checkExists(hash: string): Promise { - if (!this.client) { - return null; - } - - try { - return await this.client.getByHash(hash); - } catch { - return null; - } - } - - /** - * Get media by ID - */ - async get(id: string): Promise { - if (!this.client) { - return null; - } - - try { - return await this.client.get(id); - } catch { - return null; - } - } - /** * Check if media service is available */ isEnabled(): boolean { - return this.client !== null; + return this.mediaUrl !== null; } }