diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-08-19 00:55:07 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-19 00:55:07 +0900 |
| commit | 0e45d0d47fca2f9cf2caf87a25442d3090bea2fb (patch) | |
| tree | 4591218074ce73b4f5d3be7582d76a170dc1b672 /src/server/api/endpoints/admin/chart.ts | |
| parent | New translations ja.yml (Japanese (Kansai-ben)) (diff) | |
| parent | Merge pull request #2330 from syuilo/patch (diff) | |
| download | misskey-0e45d0d47fca2f9cf2caf87a25442d3090bea2fb.tar.gz misskey-0e45d0d47fca2f9cf2caf87a25442d3090bea2fb.tar.bz2 misskey-0e45d0d47fca2f9cf2caf87a25442d3090bea2fb.zip | |
Merge branch 'master' into l10n_master
Diffstat (limited to 'src/server/api/endpoints/admin/chart.ts')
| -rw-r--r-- | src/server/api/endpoints/admin/chart.ts | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/server/api/endpoints/admin/chart.ts b/src/server/api/endpoints/admin/chart.ts new file mode 100644 index 0000000000..a0566b11f5 --- /dev/null +++ b/src/server/api/endpoints/admin/chart.ts @@ -0,0 +1,101 @@ +import Stats, { IStats } from '../../../../models/stats'; + +type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; + +export const meta = { + requireCredential: true, + requireAdmin: true +}; + +export default (params: any) => new Promise(async (res, rej) => { + const now = new Date(); + const y = now.getFullYear(); + const m = now.getMonth(); + const d = now.getDate(); + + const stats = await Stats.find({ + date: { + $gt: new Date(y - 1, m, d) + } + }, { + sort: { + date: -1 + }, + fields: { + _id: 0 + } + }); + + const chart: Array<Omit<IStats, '_id'>> = []; + + for (let i = 364; i >= 0; i--) { + const day = new Date(y, m, d - i); + + const stat = stats.find(s => s.date.getTime() == day.getTime()); + + if (stat) { + chart.unshift(stat); + } else { // 隙間埋め + const mostRecent = stats.find(s => s.date.getTime() < day.getTime()); + if (mostRecent) { + chart.unshift(Object.assign({}, mostRecent, { + date: day + })); + } else { + chart.unshift({ + date: day, + users: { + local: { + total: 0, + diff: 0 + }, + remote: { + total: 0, + diff: 0 + } + }, + notes: { + local: { + total: 0, + diff: 0, + diffs: { + normal: 0, + reply: 0, + renote: 0 + } + }, + remote: { + total: 0, + diff: 0, + diffs: { + normal: 0, + reply: 0, + renote: 0 + } + } + }, + drive: { + local: { + totalCount: 0, + totalSize: 0, + diffCount: 0, + diffSize: 0 + }, + remote: { + totalCount: 0, + totalSize: 0, + diffCount: 0, + diffSize: 0 + } + } + }); + } + } + } + + chart.forEach(x => { + delete x.date; + }); + + res(chart); +}); |