From 038bd100b2b72985693b1c810845330d083beef1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 24 Oct 2018 06:34:04 +0900 Subject: [PATCH] Implement federation chart API --- src/server/api/endpoints/charts/federation.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/server/api/endpoints/charts/federation.ts diff --git a/src/server/api/endpoints/charts/federation.ts b/src/server/api/endpoints/charts/federation.ts new file mode 100644 index 0000000000..2292c2e6a8 --- /dev/null +++ b/src/server/api/endpoints/charts/federation.ts @@ -0,0 +1,33 @@ +import $ from 'cafy'; +import getParams from '../../get-params'; +import federationChart from '../../../../chart/federation'; + +export const meta = { + desc: { + 'ja-JP': 'フェデレーションのチャートを取得します。' + }, + + params: { + span: $.str.or(['day', 'hour']).note({ + desc: { + 'ja-JP': '集計のスパン (day または hour)' + } + }), + + limit: $.num.optional.range(1, 100).note({ + default: 30, + desc: { + 'ja-JP': '最大数。例えば 30 を指定したとすると、スパンが"day"の場合は30日分のデータが、スパンが"hour"の場合は30時間分のデータが返ります。' + } + }), + } +}; + +export default (params: any) => new Promise(async (res, rej) => { + const [ps, psErr] = getParams(meta, params); + if (psErr) throw psErr; + + const stats = await federationChart.getChart(ps.span as any, ps.limit); + + res(stats); +});