mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
Manage per-user WeatherSource instances via FeedSourceProvider, following the same pattern as LocationService. Wire into FeedEngineService so weather data is included in the feed. Co-authored-by: Ona <no-reply@ona.com>
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { WeatherSource, type WeatherSourceOptions } from "@aris/source-weatherkit"
|
|
|
|
import type { FeedSourceProvider } from "../feed/service.ts"
|
|
|
|
/**
|
|
* Options forwarded to every per-user WeatherSource.
|
|
* Must include either `credentials` or `client` (same requirement as WeatherSourceOptions).
|
|
*/
|
|
export type WeatherServiceOptions = WeatherSourceOptions
|
|
|
|
/**
|
|
* Manages WeatherSource instances per user.
|
|
*/
|
|
export class WeatherService implements FeedSourceProvider {
|
|
private sources = new Map<string, WeatherSource>()
|
|
private readonly options: WeatherServiceOptions
|
|
|
|
constructor(options: WeatherServiceOptions) {
|
|
this.options = options
|
|
}
|
|
|
|
/**
|
|
* Get or create a WeatherSource for a user.
|
|
*/
|
|
feedSourceForUser(userId: string): WeatherSource {
|
|
let source = this.sources.get(userId)
|
|
if (!source) {
|
|
source = new WeatherSource(this.options)
|
|
this.sources.set(userId, source)
|
|
}
|
|
return source
|
|
}
|
|
|
|
/**
|
|
* Remove a user's WeatherSource.
|
|
*/
|
|
removeUser(userId: string): void {
|
|
this.sources.delete(userId)
|
|
}
|
|
}
|