diff --git a/CHANGELOG.md b/CHANGELOG.md index 161f738bc..4101bc9d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,19 @@ - +ChangeLog +========= +主に notable な changes を書いていきます + +2367 +---- +Statsのユーザー数グラフに「アカウントが作成された**回数**」(その日時点での「アカウント数」**ではなく**)グラフも併記するようにした + +2364 +---- +デザインの微調整 + +2361 +---- +Statsを実装するなど + +2357 +---- +Statusを実装するなど diff --git a/docs/setup.en.md b/docs/setup.en.md index 9348db667..3e4893534 100644 --- a/docs/setup.en.md +++ b/docs/setup.en.md @@ -25,6 +25,8 @@ Note that Misskey uses following subdomains: * **api**.*{primary domain}* * **auth**.*{primary domain}* * **about**.*{primary domain}* +* **stats**.*{primary domain}* +* **status**.*{primary domain}* * **dev**.*{primary domain}* * **file**.*{secondary domain}* diff --git a/docs/setup.ja.md b/docs/setup.ja.md index fe67e3547..4f48a0808 100644 --- a/docs/setup.ja.md +++ b/docs/setup.ja.md @@ -26,6 +26,8 @@ Misskeyは以下のサブドメインを使います: * **api**.*{primary domain}* * **auth**.*{primary domain}* * **about**.*{primary domain}* +* **stats**.*{primary domain}* +* **status**.*{primary domain}* * **dev**.*{primary domain}* * **file**.*{secondary domain}* diff --git a/locales/en.yml b/locales/en.yml index a01392809..55a588f99 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -426,3 +426,11 @@ mobile: all: "All" known: "You know" load-more: "More" + +stats: + posts-count: "Number of all posts" + users-count: "Number of all users" + +status: + all-systems-maybe-operational: "All systems maybe operational" + what-is-this-site: "" diff --git a/locales/ja.yml b/locales/ja.yml index d55e690e9..e5b2beaed 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -427,3 +427,11 @@ mobile: all: "すべて" known: "知り合い" load-more: "もっと" + +stats: + posts-count: "投稿の数" + users-count: "アカウントの数" + +status: + all-systems-maybe-operational: "すべてのシステムがたぶん正常に作動しています" + what-is-this-site: "" diff --git a/package.json b/package.json index fd623916a..23f71f5d3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "misskey", "author": "syuilo ", - "version": "0.0.2344", + "version": "0.0.2367", "license": "MIT", "description": "A miniblog-based SNS", "bugs": "https://github.com/syuilo/misskey/issues", @@ -23,7 +23,7 @@ "devDependencies": { "@types/bcryptjs": "2.4.0", "@types/body-parser": "1.16.4", - "@types/chai": "4.0.2", + "@types/chai": "4.0.3", "@types/chai-http": "3.0.2", "@types/chalk": "0.4.31", "@types/compression": "0.0.33", @@ -91,7 +91,7 @@ "uglify-es": "3.0.27", "uglify-es-webpack-plugin": "0.10.0", "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", - "webpack": "3.5.3" + "webpack": "3.5.4" }, "dependencies": { "accesses": "2.5.0", @@ -133,7 +133,7 @@ "pug": "2.0.0-rc.3", "ratelimiter": "3.0.3", "recaptcha-promise": "0.1.3", - "reconnecting-websocket": "3.0.7", + "reconnecting-websocket": "3.1.1", "redis": "2.8.0", "request": "2.81.0", "rimraf": "2.6.1", diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index bb2501c98..5bbc480a8 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -69,6 +69,9 @@ const endpoints: Endpoint[] = [ { name: 'meta' }, + { + name: 'stats' + }, { name: 'username/available' }, @@ -109,6 +112,12 @@ const endpoints: Endpoint[] = [ withCredential: true, secure: true }, + { + name: 'aggregation/posts', + }, + { + name: 'aggregation/users', + }, { name: 'aggregation/users/activity', }, diff --git a/src/api/endpoints/aggregation/posts.ts b/src/api/endpoints/aggregation/posts.ts new file mode 100644 index 000000000..48ee22512 --- /dev/null +++ b/src/api/endpoints/aggregation/posts.ts @@ -0,0 +1,90 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import Post from '../../models/post'; + +/** + * Aggregate posts + * + * @param {any} params + * @return {Promise} + */ +module.exports = params => new Promise(async (res, rej) => { + // Get 'limit' parameter + const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$; + if (limitErr) return rej('invalid limit param'); + + const datas = await Post + .aggregate([ + { $project: { + repost_id: '$repost_id', + reply_to_id: '$reply_to_id', + created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST + }}, + { $project: { + date: { + year: { $year: '$created_at' }, + month: { $month: '$created_at' }, + day: { $dayOfMonth: '$created_at' } + }, + type: { + $cond: { + if: { $ne: ['$repost_id', null] }, + then: 'repost', + else: { + $cond: { + if: { $ne: ['$reply_to_id', null] }, + then: 'reply', + else: 'post' + } + } + } + }} + }, + { $group: { _id: { + date: '$date', + type: '$type' + }, count: { $sum: 1 } } }, + { $group: { + _id: '$_id.date', + data: { $addToSet: { + type: '$_id.type', + count: '$count' + }} + } } + ]); + + datas.forEach(data => { + data.date = data._id; + delete data._id; + + data.posts = (data.data.filter(x => x.type == 'post')[0] || { count: 0 }).count; + data.reposts = (data.data.filter(x => x.type == 'repost')[0] || { count: 0 }).count; + data.replies = (data.data.filter(x => x.type == 'reply')[0] || { count: 0 }).count; + + delete data.data; + }); + + const graph = []; + + for (let i = 0; i < limit; i++) { + const day = new Date(new Date().setDate(new Date().getDate() - i)); + + const data = datas.filter(d => + d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() + )[0]; + + if (data) { + graph.push(data); + } else { + graph.push({ + posts: 0, + reposts: 0, + replies: 0 + }); + } + } + + res(graph); +}); diff --git a/src/api/endpoints/aggregation/users.ts b/src/api/endpoints/aggregation/users.ts new file mode 100644 index 000000000..9eb2d035e --- /dev/null +++ b/src/api/endpoints/aggregation/users.ts @@ -0,0 +1,58 @@ +/** + * Module dependencies + */ +import $ from 'cafy'; +import User from '../../models/user'; + +/** + * Aggregate users + * + * @param {any} params + * @return {Promise} + */ +module.exports = params => new Promise(async (res, rej) => { + // Get 'limit' parameter + const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$; + if (limitErr) return rej('invalid limit param'); + + const users = await User + .find({}, { + _id: false, + created_at: true, + deleted_at: true + }, { + sort: { created_at: -1 } + }); + + const graph = []; + + for (let i = 0; i < limit; i++) { + let dayStart = new Date(new Date().setDate(new Date().getDate() - i)); + dayStart = new Date(dayStart.setMilliseconds(0)); + dayStart = new Date(dayStart.setSeconds(0)); + dayStart = new Date(dayStart.setMinutes(0)); + dayStart = new Date(dayStart.setHours(0)); + + let dayEnd = new Date(new Date().setDate(new Date().getDate() - i)); + dayEnd = new Date(dayEnd.setMilliseconds(999)); + dayEnd = new Date(dayEnd.setSeconds(59)); + dayEnd = new Date(dayEnd.setMinutes(59)); + dayEnd = new Date(dayEnd.setHours(23)); + // day = day.getTime(); + + const total = users.filter(u => + u.created_at < dayEnd && (u.deleted_at == null || u.deleted_at > dayEnd) + ).length; + + const created = users.filter(u => + u.created_at < dayEnd && u.created_at > dayStart + ).length; + + graph.push({ + total: total, + created: created + }); + } + + res(graph); +}); diff --git a/src/api/endpoints/stats.ts b/src/api/endpoints/stats.ts new file mode 100644 index 000000000..a6084cd17 --- /dev/null +++ b/src/api/endpoints/stats.ts @@ -0,0 +1,48 @@ +/** + * Module dependencies + */ +import Post from '../models/post'; +import User from '../models/user'; + +/** + * @swagger + * /stats: + * post: + * summary: Show the misskey's statistics + * responses: + * 200: + * description: Success + * schema: + * type: object + * properties: + * posts_count: + * description: count of all posts of misskey + * type: number + * users_count: + * description: count of all users of misskey + * type: number + * + * default: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + +/** + * Show the misskey's statistics + * + * @param {any} params + * @return {Promise} + */ +module.exports = params => new Promise(async (res, rej) => { + const postsCount = await Post + .count(); + + const usersCount = await User + .count(); + + res({ + posts_count: postsCount, + users_count: usersCount + }); +}); diff --git a/src/config.ts b/src/config.ts index ca940420e..8f4ada5af 100644 --- a/src/config.ts +++ b/src/config.ts @@ -81,6 +81,8 @@ type Mixin = { api_url: string; auth_url: string; about_url: string; + stats_url: string; + status_url: string; dev_url: string; drive_url: string; }; @@ -115,6 +117,8 @@ export default function load() { mixin.auth_url = `${mixin.scheme}://auth.${mixin.host}`; mixin.dev_url = `${mixin.scheme}://dev.${mixin.host}`; mixin.about_url = `${mixin.scheme}://about.${mixin.host}`; + mixin.stats_url = `${mixin.scheme}://stats.${mixin.host}`; + mixin.status_url = `${mixin.scheme}://status.${mixin.host}`; mixin.drive_url = `${mixin.secondary_scheme}://file.${mixin.secondary_host}`; return Object.assign(config, mixin); diff --git a/src/web/app/common/scripts/config.js b/src/web/app/common/scripts/config.js index 16f75d6e1..75a7abba2 100644 --- a/src/web/app/common/scripts/config.js +++ b/src/web/app/common/scripts/config.js @@ -8,6 +8,8 @@ const url = `${scheme}//${host}`; const apiUrl = `${scheme}//api.${host}`; const devUrl = `${scheme}//dev.${host}`; const aboutUrl = `${scheme}//about.${host}`; +const statsUrl = `${scheme}//stats.${host}`; +const statusUrl = `${scheme}//status.${host}`; export default { host, @@ -15,5 +17,7 @@ export default { url, apiUrl, devUrl, - aboutUrl + aboutUrl, + statsUrl, + statusUrl }; diff --git a/src/web/app/desktop/tags/home-widgets/nav.tag b/src/web/app/desktop/tags/home-widgets/nav.tag index 304be8f95..499d66014 100644 --- a/src/web/app/desktop/tags/home-widgets/nav.tag +++ b/src/web/app/desktop/tags/home-widgets/nav.tag @@ -1,4 +1,4 @@ -MisskeyについてステータスWikiリポジトリ開発者Follow us on +Misskeyについて統計ステータスWikiリポジトリ開発者Follow us on + + + + +

%i18n:stats.posts-count% { stats.posts_count }

+ + + +
+ + +

%i18n:stats.users-count% { stats.users_count }

+ + + +
+ + + + Black ... Total
Blue ... Posts
Red ... Replies
Green ... Reposts
+ + + + +
+ + +
+ + + + + + + + + diff --git a/src/web/app/status/script.js b/src/web/app/status/script.js new file mode 100644 index 000000000..06d4d9a7a --- /dev/null +++ b/src/web/app/status/script.js @@ -0,0 +1,23 @@ +/** + * Status + */ + +// Style +import './style.styl'; + +import * as riot from 'riot'; +require('./tags'); +import init from '../init'; + +document.title = 'Misskey System Status'; + +/** + * init + */ +init(me => { + mount(document.createElement('mk-index')); +}); + +function mount(content) { + riot.mount(document.getElementById('app').appendChild(content)); +} diff --git a/src/web/app/status/style.styl b/src/web/app/status/style.styl new file mode 100644 index 000000000..b48d7aeb9 --- /dev/null +++ b/src/web/app/status/style.styl @@ -0,0 +1,9 @@ +@import "../base" + +html + color #456267 + background #fff + +body + margin 0 + padding 0 diff --git a/src/web/app/status/tags/index.js b/src/web/app/status/tags/index.js new file mode 100644 index 000000000..f41151949 --- /dev/null +++ b/src/web/app/status/tags/index.js @@ -0,0 +1 @@ +require('./index.tag'); diff --git a/src/web/app/status/tags/index.tag b/src/web/app/status/tags/index.tag new file mode 100644 index 000000000..6fb6041c3 --- /dev/null +++ b/src/web/app/status/tags/index.tag @@ -0,0 +1,201 @@ + +

MisskeyStatus

+

%i18n:status.all-systems-maybe-operational%

+
+ + +
+ + + +
+ + +

CPU { percentage }%

+ + + +
+ + +

MEM { percentage }%

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/webpack/webpack.config.ts b/webpack/webpack.config.ts index 0154d3b19..5199285d5 100644 --- a/webpack/webpack.config.ts +++ b/webpack/webpack.config.ts @@ -14,10 +14,12 @@ module.exports = langs.map(([lang, locale]) => { // Entries const entry = { - 'desktop': './src/web/app/desktop/script.js', - 'mobile': './src/web/app/mobile/script.js', - 'dev': './src/web/app/dev/script.js', - 'auth': './src/web/app/auth/script.js' + desktop: './src/web/app/desktop/script.js', + mobile: './src/web/app/mobile/script.js', + stats: './src/web/app/stats/script.js', + status: './src/web/app/status/script.js', + dev: './src/web/app/dev/script.js', + auth: './src/web/app/auth/script.js' }; const output = {