fix: show media from stopped accounts
This commit is contained in:
1 parent
b573b88b08
commit
f34129666e
6 files changed
+84
-6
No files matched your search
@@ -376,6 +376,7 @@ export async function bootstrap(
|
||||
aiUsageRepo,
|
||||
runtimeStateRepo.isBotRunning(),
|
||||
(running) => runtimeStateRepo.setBotRunning(running),
|
||||
accountContentRepo,
|
||||
);
|
||||
|
||||
webServer.setChatService(chatService);
|
||||
|
||||
@@ -25,6 +25,7 @@ import type { RedditAccountRuntimeManager } from '../services/reddit-account-run
|
||||
import type { AiUsageRepository } from '../database/ai-usage-repository.js';
|
||||
import type { CandidateQueueRepository } from '../database/candidate-queue-repository.js';
|
||||
import type { MediaLibraryService } from '../services/media-library.js';
|
||||
import type { AccountContentRepository } from '../database/account-repositories.js';
|
||||
|
||||
/** Bag of everything the route modules might need. */
|
||||
export interface WebContext {
|
||||
@@ -39,6 +40,7 @@ export interface WebContext {
|
||||
messages: MessagesRepository;
|
||||
successful: SuccessfulMessagesRepository;
|
||||
aiUsage?: AiUsageRepository;
|
||||
accountContent?: AccountContentRepository;
|
||||
};
|
||||
|
||||
services: {
|
||||
|
||||
+26
-5
@@ -1,6 +1,7 @@
|
||||
import { Router } from 'express';
|
||||
import type { WebContext } from '../context.js';
|
||||
import { resolveRedditUsername } from '../reddit-identities.js';
|
||||
import type { AccountMediaRecord } from '../../database/account-repositories.js';
|
||||
|
||||
export function createMediaRouter(ctx: WebContext): Router {
|
||||
const router = Router();
|
||||
@@ -12,11 +13,16 @@ export function createMediaRouter(ctx: WebContext): Router {
|
||||
}
|
||||
try {
|
||||
const runtimes = ctx.services.accountRuntimes?.list().filter((runtime) => runtime.state === 'running') ?? [];
|
||||
const items = runtimes.length > 0
|
||||
? (await Promise.all(runtimes.map((snapshot) =>
|
||||
ctx.services.accountRuntimes!.get(snapshot.accountId)!.resources.mediaService.getMediaItems(),
|
||||
))).flat()
|
||||
: await ctx.services.media.getMediaItems();
|
||||
const accounts = ctx.services.redditAccounts?.list() ?? [];
|
||||
const items = ctx.repos?.accountContent && accounts.length > 0
|
||||
? accounts.flatMap((account) =>
|
||||
ctx.repos.accountContent!.listMedia(account.accountId).map(toMediaRecord),
|
||||
)
|
||||
: runtimes.length > 0
|
||||
? (await Promise.all(runtimes.map((snapshot) =>
|
||||
ctx.services.accountRuntimes!.get(snapshot.accountId)!.resources.mediaService.getMediaItems(),
|
||||
))).flat()
|
||||
: await ctx.services.media.getMediaItems();
|
||||
|
||||
// Build a roomId → current chat lookup so we can override stale
|
||||
// stored usernames (e.g. items captured before username enrichment ran)
|
||||
@@ -171,3 +177,18 @@ function isOwnedSender(sender: string, accountId?: string, redditUsername?: stri
|
||||
|
||||
return ownedIdentities.has(normalizedSender);
|
||||
}
|
||||
|
||||
function toMediaRecord(item: AccountMediaRecord) {
|
||||
return {
|
||||
accountId: item.accountId,
|
||||
id: item.mediaId,
|
||||
chatUsername: item.chatUsername,
|
||||
chatRoomId: item.chatRoomId,
|
||||
sender: item.sender,
|
||||
timestamp: item.timestamp,
|
||||
originalUrl: item.originalUrl,
|
||||
fileName: item.fileName,
|
||||
relativePath: item.relativePath,
|
||||
createdAt: item.createdAt,
|
||||
};
|
||||
}
|
||||
@@ -47,6 +47,7 @@ import type { AiUsageRepository } from '../database/ai-usage-repository.js';
|
||||
import type { CandidateQueueRepository } from '../database/candidate-queue-repository.js';
|
||||
import type { MediaLibraryService } from '../services/media-library.js';
|
||||
import { createMediaLibraryRouter } from './routes/media-library.js';
|
||||
import type { AccountContentRepository } from '../database/account-repositories.js';
|
||||
|
||||
export type { BotStats, ActivityItem, LogEntry, RuntimeConfig } from './types.js';
|
||||
|
||||
@@ -83,6 +84,7 @@ export class WebServer {
|
||||
private aiUsageRepo?: AiUsageRepository,
|
||||
initialBotRunning = false,
|
||||
private readonly persistBotRunning: (running: boolean) => void = () => undefined,
|
||||
private readonly accountContentRepo?: AccountContentRepository,
|
||||
) {
|
||||
this.botRunning = initialBotRunning;
|
||||
this.broadcaster = broadcaster ?? new LogBroadcaster();
|
||||
@@ -116,6 +118,7 @@ export class WebServer {
|
||||
messages: this.messagesRepo,
|
||||
successful: this.successfulMessagesRepo,
|
||||
aiUsage: this.aiUsageRepo,
|
||||
accountContent: this.accountContentRepo,
|
||||
},
|
||||
services: this.services,
|
||||
getBotRunning: () => this.botRunning,
|
||||
|
||||
Reference in new issue
Block a user