diff --git a/src/index.ts b/src/index.ts index ed74a1a..ade15d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,11 +81,11 @@ async function main(request: Request) { console.error(err) } - if (data === 'all' && json) { + if (params.data === 'all' && json) { body = JSON.stringify(json) } - if (data === 'simple' && json) { + if (params.data === 'simple' && json) { if (isAccuweather(json) || isForeca(json)) { body = JSON.stringify(toSimpleWeather(json, params)) } @@ -139,6 +139,7 @@ function sanitizeParams(params: Record): QueryParams { async function tryNoCatch(fn: (_: QueryParams) => Promise, args: QueryParams): Promise { try { + console.log(args) return await fn(args) } catch (_) { return undefined diff --git a/src/providers/simple.ts b/src/providers/simple.ts index e291417..49562fe 100644 --- a/src/providers/simple.ts +++ b/src/providers/simple.ts @@ -1,12 +1,11 @@ import type { AccuWeather, Foreca, QueryParams, SimpleWeather } from '../types.ts' import { isAccuweather, isForeca } from '../types.ts' -export default function toSimpleWeather( - json: AccuWeather | Foreca, - params: QueryParams, -): SimpleWeather { +export default function toSimpleWeather(json: AccuWeather | Foreca, params: QueryParams): SimpleWeather { const { provider, unit } = params + console.log(json) + const simple: SimpleWeather = { meta: { ...json.meta }, geo: { ...json.geo }, @@ -23,7 +22,7 @@ export default function toSimpleWeather( daily: [] as SimpleWeather['daily'], } - if (provider === 'foreca' && isForeca(json)) { + if ((provider === 'auto' || provider === 'foreca') && isForeca(json)) { const degrees = unit === 'F' ? 'f' : 'c' simple.now.icon = transformToSimpleIcon(simple.now.icon, 'foreca') @@ -41,7 +40,7 @@ export default function toSimpleWeather( } } - if (provider === 'accuweather' && isAccuweather(json)) { + if ((provider === 'auto' || provider === 'accuweather') && isAccuweather(json)) { simple.now.icon = transformToSimpleIcon(simple.now.icon, 'accuweather') simple.now.temp = json.now.temp simple.now.feels = json.now.feels @@ -60,10 +59,7 @@ export default function toSimpleWeather( return simple } -function transformToSimpleIcon( - id: string, - provider: 'accuweather' | 'foreca', -): string { +function transformToSimpleIcon(id: string, provider: 'accuweather' | 'foreca'): string { for (const [simpleId, providerIds] of Object.entries(SIMPLE_ICONS)) { const list = providerIds[provider] @@ -123,8 +119,7 @@ export const SIMPLE_ICONS = Object.freeze({ }, snow: { accuweather: '20, 21, 22, 23, 24, 25, 26, 43, 44', - foreca: - 'd221, d311, d411, d221, d321, d431, d212, d312, d412, d222, d322, d422, d432, n221, n311, n411, n221, n321, n431, n212, n312, n412, n222, n322, n422, n432', + foreca: 'd221, d311, d411, d221, d321, d431, d212, d312, d412, d222, d322, d422, d432, n221, n311, n411, n221, n321, n431, n212, n312, n412, n222, n322, n422, n432', }, mist: { accuweather: '11',