-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[migrate] replace old Chart Data API with Restored one
- Loading branch information
Showing
3 changed files
with
86 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,93 @@ | ||
// 疫情数据调用封装 | ||
// NOTE: 访问接口地址并不是和系统对应的接口是同一服务 | ||
import { DataObject } from 'dom-renderer'; | ||
import { HTTPClient } from 'koajax'; | ||
|
||
// @credit: https://lab.ahusmart.com/nCoV/api/ 提供了丁香园的疫情数据 | ||
// @credit: https://lab.isaaclin.cn/nCoV/ 同样提供了丁香园的疫情数据 | ||
// @credit: https://github.com/BlankerL/DXY-COVID-19-Data 提供了丁香园的疫情数据 | ||
|
||
const apikey = | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlkeWNwY3l4Z2pqcHV1dmV5aWVnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDg4NDkzMDEsImV4cCI6MjAyNDQyNTMwMX0.EwwLK6PX2l5BgahNnPwzRINS-_ZI2AJCY2jR-SpzJdw'; | ||
|
||
export const epidemic = new HTTPClient({ | ||
baseURI: 'https://lab.ahusmart.com/nCoV/api/', | ||
baseURI: 'https://idycpcyxgjjpuuveyieg.supabase.co/rest/v1/', | ||
responseType: 'json' | ||
}).use(({ request }, next) => { | ||
request.headers = { | ||
...request.headers, | ||
apikey, | ||
Authorization: `Bearer ${apikey}` | ||
}; | ||
return next(); | ||
}); | ||
|
||
interface MapData<T = DataObject> { | ||
results: T[]; | ||
export interface Base { | ||
id: number; | ||
updateTime: Date; | ||
} | ||
|
||
export type StatisticType = 'confirmed' | 'suspected' | 'cured' | 'dead'; | ||
export type StatisticType = | ||
| 'suspected' | ||
| 'confirmed' | ||
| 'serious' | ||
| 'cured' | ||
| 'dead'; | ||
export type StatisticData = Record< | ||
`${StatisticType | 'currentConfirmed'}Count`, | ||
number | ||
>; | ||
export type IncreasingData = Record< | ||
`${StatisticType | 'currentConfirmed' | `yesterday${'Confirmed' | 'Suspected'}Count`}Incr`, | ||
number | ||
>; | ||
|
||
export type AreaType = 'hbFeiHb' | 'quanguo' | 'foreign'; | ||
|
||
export type StatisticData = Record<`${StatisticType}Count`, number>; | ||
export interface Overall | ||
extends Base, | ||
StatisticData, | ||
Partial<IncreasingData>, | ||
Partial<Record<`${'mid' | 'high'}DangerCount`, number>>, | ||
Partial< | ||
Record< | ||
| 'dailyPics' | ||
| 'summary' | ||
| `${'count' | 'general' | 'abroad'}Remark` | ||
| `remark${1 | 2 | 3 | 4 | 5}` | ||
| `note${1 | 2 | 3}`, | ||
string | ||
> | ||
>, | ||
Record<`${'foreign' | 'global'}Statistics`, null>, | ||
Record<`${AreaType}TrendChart`, null>, | ||
Record<`importantForeignTrendChart${'' | 'Global'}`, null> { | ||
dailyPic: string; | ||
marquee?: any[]; | ||
foreignTrendChartGlobal?: any; | ||
globalOtherTrendChartData?: string; | ||
} | ||
|
||
export interface City extends StatisticData { | ||
export interface City extends Base, StatisticData { | ||
cityName: string; | ||
} | ||
|
||
export interface Province extends StatisticData { | ||
export interface Province extends Base, StatisticData { | ||
provinceShortName: string; | ||
cities?: City[]; | ||
updateTime: number; | ||
} | ||
|
||
export async function getOverall() { | ||
const { | ||
body: { results } | ||
} = await epidemic.get<MapData>('overall?latest=0'); | ||
const { body } = await epidemic.get<Overall[]>('Overall', { Range: '0-9' }); | ||
|
||
return results; | ||
return body; | ||
} | ||
|
||
export async function getHistory() { | ||
const { | ||
body: { results } | ||
} = await epidemic.get<MapData<Province>>('area?latest=0'); | ||
const { body } = await epidemic.get<Province[]>('Area', { Range: '0-9' }); | ||
|
||
return results; | ||
return body; | ||
} | ||
|
||
export async function getCurrent() { | ||
const { | ||
body: { results } | ||
} = await epidemic.get<MapData<Province>>('area'); | ||
const { body } = await epidemic.get<Province[]>('Area', { Range: '0-9' }); | ||
|
||
return results; | ||
return body; | ||
} |
a4356e9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for wuhan2020 ready!
✅ Preview
https://wuhan2020-4w5q42jqm-techquery.vercel.app
Built with commit a4356e9.
This pull request is being automatically deployed with vercel-action