fix(nutriphi-bot): remove missing media-client dependency

This commit is contained in:
Till-JS 2026-02-13 23:22:29 +01:00
parent 5118235e0b
commit 92c6dc83ee

View file

@ -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<string>('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<MediaResult | null> {
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<MediaResult | null> {
if (!this.client) {
return null;
}
try {
return await this.client.getByHash(hash);
} catch {
return null;
}
}
/**
* Get media by ID
*/
async get(id: string): Promise<MediaResult | null> {
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;
}
}