37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
/**
|
|
* Shared lazy-init singletons + multer config used by route modules under
|
|
* src/api/. Extracted from the original routes.ts so techniques/media/domain
|
|
* sub-routers can reuse them without each duplicating connection setup.
|
|
*/
|
|
import multer from 'multer';
|
|
import { lazyRedis } from '../shared/redis/connection';
|
|
import { MediaService } from '../shared/media/media-service';
|
|
import { PersistService, PgSessionAdapter, getPgPool } from '../shared/persistence';
|
|
import { SessionStore } from '../shared/redis/session-store';
|
|
|
|
/** Per-module Redis singleton (label visible in connection metadata). */
|
|
export const getRedis = lazyRedis('routes');
|
|
|
|
/** Multer upload — memory storage, 50MB max. Used by /media/upload + /techniques/analyze-media. */
|
|
export const upload = multer({
|
|
storage: multer.memoryStorage(),
|
|
limits: { fileSize: 50 * 1024 * 1024 },
|
|
});
|
|
|
|
let _mediaService: MediaService | null = null;
|
|
export function getMediaService(): MediaService {
|
|
if (!_mediaService) _mediaService = new MediaService();
|
|
return _mediaService;
|
|
}
|
|
|
|
let _persistService: PersistService | null = null;
|
|
export function getPersistServiceInstance(): PersistService {
|
|
if (!_persistService) {
|
|
const r = getRedis();
|
|
_persistService = new PersistService(
|
|
new SessionStore(r),
|
|
new PgSessionAdapter(getPgPool()),
|
|
);
|
|
}
|
|
return _persistService;
|
|
}
|