mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
Add ability to replace a FeedSourceProvider at runtime and propagate the new source to all active (and pending) user sessions, invalidating their feed caches. Co-authored-by: Ona <no-reply@ona.com>
27 lines
747 B
TypeScript
27 lines
747 B
TypeScript
import { LocationSource } from "@aelis/source-location"
|
|
|
|
import type { Database } from "../db/index.ts"
|
|
import type { FeedSourceProvider } from "../session/feed-source-provider.ts"
|
|
|
|
import { SourceDisabledError } from "../sources/errors.ts"
|
|
import { sources } from "../sources/user-sources.ts"
|
|
|
|
export class LocationSourceProvider implements FeedSourceProvider {
|
|
readonly sourceId = "aelis.location"
|
|
private readonly db: Database
|
|
|
|
constructor(db: Database) {
|
|
this.db = db
|
|
}
|
|
|
|
async feedSourceForUser(userId: string): Promise<LocationSource> {
|
|
const row = await sources(this.db, userId).find("aelis.location")
|
|
|
|
if (!row || !row.enabled) {
|
|
throw new SourceDisabledError("aelis.location", userId)
|
|
}
|
|
|
|
return new LocationSource()
|
|
}
|
|
}
|