|
|
import { Injectable, Logger, NotFoundException } from '@nestjs/common'; |
|
|
import { ClipboardService } from '../clipboard/clipboard.service'; |
|
|
|
|
|
@Injectable() |
|
|
export class AdminService { |
|
|
private readonly logger = new Logger(AdminService.name); |
|
|
|
|
|
constructor(private readonly clipboardService: ClipboardService) { } |
|
|
|
|
|
async listClipboards() { |
|
|
return this.clipboardService.listClipboards(); |
|
|
} |
|
|
|
|
|
async getClipboard(roomCode: string) { |
|
|
const clipboard = await this.clipboardService.getClipboard(roomCode); |
|
|
const ttl = await this.clipboardService.getClipboardTTL(roomCode); |
|
|
|
|
|
if (!clipboard) { |
|
|
throw new NotFoundException(`Clipboard ${roomCode} not found`); |
|
|
} |
|
|
|
|
|
return { ...clipboard, ttl }; |
|
|
} |
|
|
|
|
|
async setPassword(roomCode: string, password?: string | null) { |
|
|
const clipboard = await this.clipboardService.updateClipboardPassword(roomCode, password); |
|
|
if (!clipboard) { |
|
|
throw new NotFoundException(`Clipboard ${roomCode} not found`); |
|
|
} |
|
|
|
|
|
this.logger.log(`Updated password for clipboard ${roomCode}`); |
|
|
return clipboard; |
|
|
} |
|
|
|
|
|
async setTTL(roomCode: string, ttlSeconds: number | null) { |
|
|
const updated = await this.clipboardService.setClipboardExpiration(roomCode, ttlSeconds); |
|
|
if (!updated) { |
|
|
throw new NotFoundException(`Clipboard ${roomCode} not found`); |
|
|
} |
|
|
|
|
|
this.logger.log(`Updated TTL for clipboard ${roomCode} -> ${ttlSeconds ?? 'none'}`); |
|
|
return { success: true, ttl: ttlSeconds }; |
|
|
} |
|
|
|
|
|
async deleteClipboard(roomCode: string) { |
|
|
const success = await this.clipboardService.deleteClipboard(roomCode); |
|
|
if (!success) { |
|
|
throw new NotFoundException(`Clipboard ${roomCode} not found`); |
|
|
} |
|
|
|
|
|
this.logger.log(`Deleted clipboard ${roomCode}`); |
|
|
return { success }; |
|
|
} |
|
|
} |
|
|
|