diff options
Diffstat (limited to 'src')
49 files changed, 1368 insertions, 659 deletions
diff --git a/src/client/app/common/scripts/get-face.ts b/src/client/app/common/scripts/get-face.ts new file mode 100644 index 0000000000..79cf7a1be4 --- /dev/null +++ b/src/client/app/common/scripts/get-face.ts @@ -0,0 +1,10 @@ +const faces = [ + '(=^・・^=)', + 'v(\'ω\')v', + '🐡( \'-\' 🐡 )フグパンチ!!!!', + '🖕(´・_・`)🖕', + '(。>﹏<。)', + '(Δ・x・Δ)' +]; + +export default () => faces[Math.floor(Math.random() * faces.length)]; diff --git a/src/client/app/common/scripts/get-kao.ts b/src/client/app/common/scripts/get-kao.ts deleted file mode 100644 index ca83153b96..0000000000 --- a/src/client/app/common/scripts/get-kao.ts +++ /dev/null @@ -1,9 +0,0 @@ -const kaos = [ - '(=^・・^=)', - 'v(\'ω\')v', - '🐡( \'-\' 🐡 )フグパンチ!!!!', - '🖕(´・_・`)🖕', - '(。>﹏<。)' -]; - -export default () => kaos[Math.floor(Math.random() * kaos.length)]; diff --git a/src/client/app/common/views/components/games/reversi/reversi.index.vue b/src/client/app/common/views/components/games/reversi/reversi.index.vue index d4d35f6a86..fa88aeaaf4 100644 --- a/src/client/app/common/views/components/games/reversi/reversi.index.vue +++ b/src/client/app/common/views/components/games/reversi/reversi.index.vue @@ -32,6 +32,7 @@ <mk-avatar class="avatar" :user="g.user2"/> <span><b>{{ g.user1 | userName }}</b> vs <b>{{ g.user2 | userName }}</b></span> <span class="state">{{ g.isEnded ? '%i18n:@game-state.ended%' : '%i18n:@game-state.playing%' }}</span> + <mk-time :time="g.createdAt" /> </a> </section> <section v-if="games.length > 0"> @@ -41,6 +42,7 @@ <mk-avatar class="avatar" :user="g.user2"/> <span><b>{{ g.user1 | userName }}</b> vs <b>{{ g.user2 | userName }}</b></span> <span class="state">{{ g.isEnded ? '%i18n:@game-state.ended%' : '%i18n:@game-state.playing%' }}</span> + <mk-time :time="g.createdAt" /> </a> </section> </div> diff --git a/src/client/app/common/views/components/signup.vue b/src/client/app/common/views/components/signup.vue index 45a183e144..1d33702159 100644 --- a/src/client/app/common/views/components/signup.vue +++ b/src/client/app/common/views/components/signup.vue @@ -1,5 +1,10 @@ <template> <form class="mk-signup" @submit.prevent="onSubmit" :autocomplete="Math.random()"> + <ui-input v-if="meta.disableRegistration" v-model="invitationCode" type="text" :autocomplete="Math.random()" spellcheck="false" required> + <span>%i18n:@invitation-code%</span> + <span slot="prefix">%fa:id-card-alt%</span> + <p slot="text" v-html="'%i18n:@invitation-info%'.replace('{}', meta.maintainer.url)"></p> + </ui-input> <ui-input v-model="username" type="text" pattern="^[a-zA-Z0-9_]{1,20}$" :autocomplete="Math.random()" spellcheck="false" required @input="onChangeUsername"> <span>%i18n:@username%</span> <span slot="prefix">@</span> @@ -46,11 +51,13 @@ export default Vue.extend({ username: '', password: '', retypedPassword: '', + invitationCode: '', url, recaptchaSitekey, usernameState: null, passwordStrength: '', - passwordRetypeState: null + passwordRetypeState: null, + meta: null } }, computed: { @@ -61,6 +68,11 @@ export default Vue.extend({ this.usernameState != 'max-range'); } }, + created() { + (this as any).os.getMeta().then(meta => { + this.meta = meta; + }); + }, methods: { onChangeUsername() { if (this.username == '') { @@ -110,6 +122,7 @@ export default Vue.extend({ (this as any).api('signup', { username: this.username, password: this.password, + invitationCode: this.invitationCode, 'g-recaptcha-response': recaptchaSitekey != null ? (window as any).grecaptcha.getResponse() : null }).then(() => { (this as any).api('signin', { diff --git a/src/client/app/common/views/components/visibility-chooser.vue b/src/client/app/common/views/components/visibility-chooser.vue index cc9c75095e..4691604e57 100644 --- a/src/client/app/common/views/components/visibility-chooser.vue +++ b/src/client/app/common/views/components/visibility-chooser.vue @@ -44,7 +44,12 @@ import Vue from 'vue'; import * as anime from 'animejs'; export default Vue.extend({ - props: ['source', 'compact', 'v'], + props: ['source', 'compact'], + data() { + return { + v: this.$store.state.device.visibility || 'public' + } + }, mounted() { this.$nextTick(() => { const popover = this.$refs.popover as any; @@ -92,6 +97,7 @@ export default Vue.extend({ }, methods: { choose(visibility) { + this.$store.commit('device/setVisibility', visibility); this.$emit('chosen', visibility); this.$destroy(); }, diff --git a/src/client/app/desktop/views/components/post-form.vue b/src/client/app/desktop/views/components/post-form.vue index ea51144173..bacaea65ee 100644 --- a/src/client/app/desktop/views/components/post-form.vue +++ b/src/client/app/desktop/views/components/post-form.vue @@ -58,7 +58,7 @@ import Vue from 'vue'; import insertTextAtCursor from 'insert-text-at-cursor'; import * as XDraggable from 'vuedraggable'; -import getKao from '../../../common/scripts/get-kao'; +import getFace from '../../../common/scripts/get-face'; import MkVisibilityChooser from '../../../common/views/components/visibility-chooser.vue'; import parse from '../../../../../mfm/parse'; import { host } from '../../../config'; @@ -99,7 +99,7 @@ export default Vue.extend({ useCw: false, cw: null, geo: null, - visibility: 'public', + visibility: this.$store.state.device.visibility || 'public', visibleUsers: [], autocomplete: null, draghover: false, @@ -326,8 +326,7 @@ export default Vue.extend({ setVisibility() { const w = (this as any).os.new(MkVisibilityChooser, { - source: this.$refs.visibilityButton, - v: this.visibility + source: this.$refs.visibilityButton }); w.$once('chosen', v => { this.visibility = v; @@ -422,7 +421,7 @@ export default Vue.extend({ }, kao() { - this.text += getKao(); + this.text += getFace(); } } }); diff --git a/src/client/app/desktop/views/pages/admin/admin.cpu-memory.vue b/src/client/app/desktop/views/pages/admin/admin.cpu-memory.vue new file mode 100644 index 0000000000..572974e248 --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.cpu-memory.vue @@ -0,0 +1,145 @@ +<template> +<div class="zyknedwtlthezamcjlolyusmipqmjgxz"> + <svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`"> + <defs> + <linearGradient :id="cpuGradientId" x1="0" x2="0" y1="1" y2="0"> + <stop offset="0%" stop-color="hsl(180, 80%, 70%)"></stop> + <stop offset="100%" stop-color="hsl(0, 80%, 70%)"></stop> + </linearGradient> + <mask :id="cpuMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY"> + <polygon + :points="cpuPolygonPoints" + fill="#fff" + fill-opacity="0.5"/> + <polyline + :points="cpuPolylinePoints" + fill="none" + stroke="#fff" + stroke-width="0.3"/> + </mask> + </defs> + <rect + x="0" y="0" + :width="viewBoxX" :height="viewBoxY" + :style="`stroke: none; fill: url(#${ cpuGradientId }); mask: url(#${ cpuMaskId })`"/> + <text x="1" y="5">CPU <tspan>{{ cpuP }}%</tspan></text> + </svg> + <svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`"> + <defs> + <linearGradient :id="memGradientId" x1="0" x2="0" y1="1" y2="0"> + <stop offset="0%" stop-color="hsl(180, 80%, 70%)"></stop> + <stop offset="100%" stop-color="hsl(0, 80%, 70%)"></stop> + </linearGradient> + <mask :id="memMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY"> + <polygon + :points="memPolygonPoints" + fill="#fff" + fill-opacity="0.5"/> + <polyline + :points="memPolylinePoints" + fill="none" + stroke="#fff" + stroke-width="0.3"/> + </mask> + </defs> + <rect + x="0" y="0" + :width="viewBoxX" :height="viewBoxY" + :style="`stroke: none; fill: url(#${ memGradientId }); mask: url(#${ memMaskId })`"/> + <text x="1" y="5">MEM <tspan>{{ memP }}%</tspan></text> + </svg> +</div> +</template> + +<script lang="ts"> +import Vue from 'vue'; +import * as uuid from 'uuid'; + +export default Vue.extend({ + props: ['connection'], + data() { + return { + viewBoxX: 50, + viewBoxY: 20, + stats: [], + cpuGradientId: uuid(), + cpuMaskId: uuid(), + memGradientId: uuid(), + memMaskId: uuid(), + cpuPolylinePoints: '', + memPolylinePoints: '', + cpuPolygonPoints: '', + memPolygonPoints: '', + cpuP: '', + memP: '' + }; + }, + mounted() { + this.connection.on('stats', this.onStats); + this.connection.on('statsLog', this.onStatsLog); + this.connection.send({ + type: 'requestLog', + id: Math.random().toString() + }); + }, + beforeDestroy() { + this.connection.off('stats', this.onStats); + this.connection.off('statsLog', this.onStatsLog); + }, + methods: { + onStats(stats) { + this.stats.push(stats); + if (this.stats.length > 50) this.stats.shift(); + + const cpuPolylinePoints = this.stats.map((s, i) => [this.viewBoxX - ((this.stats.length - 1) - i), (1 - s.cpu_usage) * this.viewBoxY]); + const memPolylinePoints = this.stats.map((s, i) => [this.viewBoxX - ((this.stats.length - 1) - i), (1 - (s.mem.used / s.mem.total)) * this.viewBoxY]); + this.cpuPolylinePoints = cpuPolylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' '); + this.memPolylinePoints = memPolylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' '); + + this.cpuPolygonPoints = `${this.viewBoxX - (this.stats.length - 1)},${this.viewBoxY} ${this.cpuPolylinePoints} ${this.viewBoxX},${this.viewBoxY}`; + this.memPolygonPoints = `${this.viewBoxX - (this.stats.length - 1)},${this.viewBoxY} ${this.memPolylinePoints} ${this.viewBoxX},${this.viewBoxY}`; + + this.cpuP = (stats.cpu_usage * 100).toFixed(0); + this.memP = (stats.mem.used / stats.mem.total * 100).toFixed(0); + }, + onStatsLog(statsLog) { + statsLog.forEach(stats => this.onStats(stats)); + } + } +}); +</script> + +<style lang="stylus" scoped> +root(isDark) + margin-bottom 16px + + > svg + display block + width 50% + float left + + &:first-child + padding-right 5px + + &:last-child + padding-left 5px + + > text + font-size 2px + fill isDark ? rgba(#fff, 0.55) : rgba(#000, 0.55) + + > tspan + opacity 0.5 + + &:after + content "" + display block + clear both + +.zyknedwtlthezamcjlolyusmipqmjgxz[data-darkmode] + root(true) + +.zyknedwtlthezamcjlolyusmipqmjgxz:not([data-darkmode]) + root(false) + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.dashboard.vue b/src/client/app/desktop/views/pages/admin/admin.dashboard.vue index b10e829965..e68d3a749e 100644 --- a/src/client/app/desktop/views/pages/admin/admin.dashboard.vue +++ b/src/client/app/desktop/views/pages/admin/admin.dashboard.vue @@ -1,37 +1,80 @@ <template> -<div> - <h1>%i18n:@dashboard%</h1> - <div v-if="stats"> - <p><b>%i18n:@all-users%</b>: <span>{{ stats.usersCount | number }}</span></p> - <p><b>%i18n:@original-users%</b>: <span>{{ stats.originalUsersCount | number }}</span></p> - <p><b>%i18n:@all-notes%</b>: <span>{{ stats.notesCount | number }}</span></p> - <p><b>%i18n:@original-notes%</b>: <span>{{ stats.originalNotesCount | number }}</span></p> +<div class="obdskegsannmntldydackcpzezagxqfy card"> + <header>%i18n:@dashboard%</header> + <div v-if="stats" class="stats"> + <div><b>%fa:user% {{ stats.originalUsersCount | number }}</b><span>%i18n:@original-users%</span></div> + <div><span>%fa:user% {{ stats.usersCount | number }}</span><span>%i18n:@all-users%</span></div> + <div><b>%fa:pen% {{ stats.originalNotesCount | number }}</b><span>%i18n:@original-notes%</span></div> + <div><span>%fa:pen% {{ stats.notesCount | number }}</span><span>%i18n:@all-notes%</span></div> + </div> + <div class="cpu-memory"> + <x-cpu-memory :connection="connection"/> + </div> + <div> + <button class="ui" @click="invite">%i18n:@invite%</button> + <p v-if="inviteCode">Code: <code>{{ inviteCode }}</code></p> </div> </div> </template> <script lang="ts"> import Vue from "vue"; +import XCpuMemory from "./admin.cpu-memory.vue"; export default Vue.extend({ + components: { + XCpuMemory + }, data() { return { - stats: null + stats: null, + inviteCode: null, + connection: null, + connectionId: null }; }, created() { + this.connection = (this as any).os.streams.serverStatsStream.getConnection(); + this.connectionId = (this as any).os.streams.serverStatsStream.use(); + (this as any).api('stats').then(stats => { this.stats = stats; }); + }, + beforeDestroy() { + (this as any).os.streams.serverStatsStream.dispose(this.connectionId); + }, + methods: { + invite() { + (this as any).api('admin/invite').then(x => { + this.inviteCode = x.code; + }); + } } }); </script> <style lang="stylus" scoped> -h1 - margin 0 0 1em 0 - padding 0 0 8px 0 - font-size 1em - color #555 - border-bottom solid 1px #eee +@import '~const.styl' + +.obdskegsannmntldydackcpzezagxqfy + > .stats + display flex + justify-content center + margin-bottom 16px + padding 16px + border solid 1px #eee + border-radius 8px + + > div + flex 1 + text-align center + + > *:first-child + display block + color $theme-color + + > *:last-child + font-size 70% + </style> diff --git a/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue b/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue new file mode 100644 index 0000000000..3c537d8d6d --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue @@ -0,0 +1,51 @@ +<template> +<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`"> + <polyline + :points="points" + fill="none" + stroke-width="1" + stroke="#555"/> +</svg> +</template> + +<script lang="ts"> +import Vue from 'vue'; + +export default Vue.extend({ + props: { + chart: { + required: true + }, + type: { + type: String, + required: true + } + }, + data() { + return { + viewBoxX: 365, + viewBoxY: 70, + points: null + }; + }, + created() { + const peak = Math.max.apply(null, this.chart.map(d => this.type == 'local' ? d.drive.local.totalSize : d.drive.remote.totalSize)); + + if (peak != 0) { + const data = this.chart.slice().reverse().map(x => ({ + size: this.type == 'local' ? x.drive.local.totalSize : x.drive.remote.totalSize + })); + + this.points = data.map((d, i) => `${i},${(1 - (d.size / peak)) * this.viewBoxY}`).join(' '); + } + } +}); +</script> + +<style lang="stylus" scoped> +svg + display block + padding 10px + width 100% + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.drive-chart.vue b/src/client/app/desktop/views/pages/admin/admin.drive-chart.vue new file mode 100644 index 0000000000..4f94fd2372 --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.drive-chart.vue @@ -0,0 +1,34 @@ +<template> +<div class="card"> + <header>%i18n:@title%</header> + <div class="card"> + <header>%i18n:@local%</header> + <x-chart v-if="chart" :chart="chart" type="local"/> + </div> + <div class="card"> + <header>%i18n:@remote%</header> + <x-chart v-if="chart" :chart="chart" type="remote"/> + </div> +</div> +</template> + +<script lang="ts"> +import Vue from "vue"; +import XChart from "./admin.drive-chart.chart.vue"; + +export default Vue.extend({ + components: { + XChart + }, + props: { + chart: { + required: true + } + } +}); +</script> + +<style lang="stylus" scoped> +@import '~const.styl' + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.notes-chart.chart.vue b/src/client/app/desktop/views/pages/admin/admin.notes-chart.chart.vue new file mode 100644 index 0000000000..83c61c1313 --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.notes-chart.chart.vue @@ -0,0 +1,76 @@ +<template> +<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`"> + <polyline + :points="pointsNote" + fill="none" + stroke-width="1" + stroke="#41ddde"/> + <polyline + :points="pointsReply" + fill="none" + stroke-width="1" + stroke="#f7796c"/> + <polyline + :points="pointsRenote" + fill="none" + stroke-width="1" + stroke="#a1de41"/> + <polyline + :points="pointsTotal" + fill="none" + stroke-width="1" + stroke="#555" + stroke-dasharray="2 2"/> +</svg> +</template> + +<script lang="ts"> +import Vue from 'vue'; + +export default Vue.extend({ + props: { + chart: { + required: true + }, + type: { + type: String, + required: true + } + }, + data() { + return { + viewBoxX: 365, + viewBoxY: 70, + pointsNote: null, + pointsReply: null, + pointsRenote: null, + pointsTotal: null + }; + }, + created() { + const peak = Math.max.apply(null, this.chart.map(d => this.type == 'local' ? d.notes.local.diff : d.notes.remote.diff)); + + if (peak != 0) { + const data = this.chart.slice().reverse().map(x => ({ + normal: this.type == 'local' ? x.notes.local.diffs.normal : x.notes.remote.diffs.normal, + reply: this.type == 'local' ? x.notes.local.diffs.reply : x.notes.remote.diffs.reply, + renote: this.type == 'local' ? x.notes.local.diffs.renote : x.notes.remote.diffs.renote, + total: this.type == 'local' ? x.notes.local.diff : x.notes.remote.diff + })); + + this.pointsNote = data.map((d, i) => `${i},${(1 - (d.normal / peak)) * this.viewBoxY}`).join(' '); + this.pointsReply = data.map((d, i) => `${i},${(1 - (d.reply / peak)) * this.viewBoxY}`).join(' '); + this.pointsRenote = data.map((d, i) => `${i},${(1 - (d.renote / peak)) * this.viewBoxY}`).join(' '); + this.pointsTotal = data.map((d, i) => `${i},${(1 - (d.total / peak)) * this.viewBoxY}`).join(' '); + } + } +}); +</script> + +<style lang="stylus" scoped> +svg + display block + padding 10px + width 100% + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.notes-chart.vue b/src/client/app/desktop/views/pages/admin/admin.notes-chart.vue new file mode 100644 index 0000000000..e4d396d9c6 --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.notes-chart.vue @@ -0,0 +1,34 @@ +<template> +<div class="card"> + <header>%i18n:@title%</header> + <div class="card"> + <header>%i18n:@local%</header> + <x-chart v-if="chart" :chart="chart" type="local"/> + </div> + <div class="card"> + <header>%i18n:@remote%</header> + <x-chart v-if="chart" :chart="chart" type="remote"/> + </div> +</div> +</template> + +<script lang="ts"> +import Vue from "vue"; +import XChart from "./admin.notes-chart.chart.vue"; + +export default Vue.extend({ + components: { + XChart + }, + props: { + chart: { + required: true + } + } +}); +</script> + +<style lang="stylus" scoped> +@import '~const.styl' + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.suspend-user.vue b/src/client/app/desktop/views/pages/admin/admin.suspend-user.vue index 6eb82f0a51..59932f4be7 100644 --- a/src/client/app/desktop/views/pages/admin/admin.suspend-user.vue +++ b/src/client/app/desktop/views/pages/admin/admin.suspend-user.vue @@ -1,5 +1,5 @@ <template> -<div> +<div class="card"> <header>%i18n:@suspend-user%</header> <input v-model="username" type="text" class="ui"/> <button class="ui" @click="suspendUser" :disabled="suspending">%i18n:@suspend%</button> diff --git a/src/client/app/desktop/views/pages/admin/admin.unsuspend-user.vue b/src/client/app/desktop/views/pages/admin/admin.unsuspend-user.vue index 8c6f63ce88..a75c0bd64e 100644 --- a/src/client/app/desktop/views/pages/admin/admin.unsuspend-user.vue +++ b/src/client/app/desktop/views/pages/admin/admin.unsuspend-user.vue @@ -1,5 +1,5 @@ <template> -<div> +<div class="card"> <header>%i18n:@unsuspend-user%</header> <input v-model="username" type="text" class="ui"/> <button class="ui" @click="unsuspendUser" :disabled="unsuspending">%i18n:@unsuspend%</button> diff --git a/src/client/app/desktop/views/pages/admin/admin.unverify-user.vue b/src/client/app/desktop/views/pages/admin/admin.unverify-user.vue new file mode 100644 index 0000000000..72962870d9 --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.unverify-user.vue @@ -0,0 +1,51 @@ +<template> +<div class="card"> + <header>%i18n:@unverify-user%</header> + <input v-model="username" type="text" class="ui"/> + <button class="ui" @click="unverifyUser" :disabled="unverifying">%i18n:@unverify%</button> +</div> +</template> + +<script lang="ts"> +import Vue from "vue"; +import parseAcct from "../../../../../../misc/acct/parse"; + +export default Vue.extend({ + data() { + return { + username: null, + unverifying: false + }; + }, + methods: { + async unverifyUser() { + this.unverifying = true; + + const user = await (this as any).os.api( + "users/show", + parseAcct(this.username) + ); + + await (this as any).os.api("admin/unverify-user", { + userId: user.id + }); + + this.unverifying = false; + + (this as any).os.apis.dialog({ text: "%i18n:@unverified%" }); + } + } +}); +</script> + +<style lang="stylus" scoped> +@import '~const.styl' + +header + margin 10px 0 + + +button + margin 16px 0 + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue b/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue new file mode 100644 index 0000000000..c2ab4a78e3 --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue @@ -0,0 +1,51 @@ +<template> +<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`"> + <polyline + :points="points" + fill="none" + stroke-width="1" + stroke="#555"/> +</svg> +</template> + +<script lang="ts"> +import Vue from 'vue'; + +export default Vue.extend({ + props: { + chart: { + required: true + }, + type: { + type: String, + required: true + } + }, + data() { + return { + viewBoxX: 365, + viewBoxY: 70, + points: null + }; + }, + created() { + const peak = Math.max.apply(null, this.chart.map(d => this.type == 'local' ? d.users.local.diff : d.users.remote.diff)); + + if (peak != 0) { + const data = this.chart.slice().reverse().map(x => ({ + count: this.type == 'local' ? x.users.local.diff : x.users.remote.diff + })); + + this.points = data.map((d, i) => `${i},${(1 - (d.count / peak)) * this.viewBoxY}`).join(' '); + } + } +}); +</script> + +<style lang="stylus" scoped> +svg + display block + padding 10px + width 100% + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.users-chart.vue b/src/client/app/desktop/views/pages/admin/admin.users-chart.vue new file mode 100644 index 0000000000..e620012702 --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.users-chart.vue @@ -0,0 +1,34 @@ +<template> +<div class="card"> + <header>%i18n:@title%</header> + <div class="card"> + <header>%i18n:@local%</header> + <x-chart v-if="chart" :chart="chart" type="local"/> + </div> + <div class="card"> + <header>%i18n:@remote%</header> + <x-chart v-if="chart" :chart="chart" type="remote"/> + </div> +</div> +</template> + +<script lang="ts"> +import Vue from "vue"; +import XChart from "./admin.users-chart.chart.vue"; + +export default Vue.extend({ + components: { + XChart + }, + props: { + chart: { + required: true + } + } +}); +</script> + +<style lang="stylus" scoped> +@import '~const.styl' + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.verify-user.vue b/src/client/app/desktop/views/pages/admin/admin.verify-user.vue new file mode 100644 index 0000000000..3902d4bddd --- /dev/null +++ b/src/client/app/desktop/views/pages/admin/admin.verify-user.vue @@ -0,0 +1,51 @@ +<template> +<div class="card"> + <header>%i18n:@verify-user%</header> + <input v-model="username" type="text" class="ui"/> + <button class="ui" @click="verifyUser" :disabled="verifying">%i18n:@verify%</button> +</div> +</template> + +<script lang="ts"> +import Vue from "vue"; +import parseAcct from "../../../../../../misc/acct/parse"; + +export default Vue.extend({ + data() { + return { + username: null, + verifying: false + }; + }, + methods: { + async verifyUser() { + this.verifying = true; + + const user = await (this as any).os.api( + "users/show", + parseAcct(this.username) + ); + + await (this as any).os.api("admin/verify-user", { + userId: user.id + }); + + this.verifying = false; + + (this as any).os.apis.dialog({ text: "%i18n:@verified%" }); + } + } +}); +</script> + +<style lang="stylus" scoped> +@import '~const.styl' + +header + margin 10px 0 + + +button + margin 16px 0 + +</style> diff --git a/src/client/app/desktop/views/pages/admin/admin.vue b/src/client/app/desktop/views/pages/admin/admin.vue index b581bea465..cbb1890cc3 100644 --- a/src/client/app/desktop/views/pages/admin/admin.vue +++ b/src/client/app/desktop/views/pages/admin/admin.vue @@ -9,12 +9,17 @@ </ul> </nav> <main> - <div v-if="page == 'dashboard'"> + <div v-show="page == 'dashboard'"> <x-dashboard/> + <x-users-chart :chart="chart"/> + <x-notes-chart :chart="chart"/> + <x-drive-chart :chart="chart"/> </div> <div v-if="page == 'users'"> <x-suspend-user/> <x-unsuspend-user/> + <x-verify-user/> + <x-unverify-user/> </div> <div v-if="page == 'drive'"></div> <div v-if="page == 'update'"></div> @@ -27,18 +32,34 @@ import Vue from "vue"; import XDashboard from "./admin.dashboard.vue"; import XSuspendUser from "./admin.suspend-user.vue"; import XUnsuspendUser from "./admin.unsuspend-user.vue"; +import XVerifyUser from "./admin.verify-user.vue"; +import XUnverifyUser from "./admin.unverify-user.vue"; +import XUsersChart from "./admin.users-chart.vue"; +import XNotesChart from "./admin.notes-chart.vue"; +import XDriveChart from "./admin.drive-chart.vue"; export default Vue.extend({ components: { XDashboard, XSuspendUser, - XUnsuspendUser + XUnsuspendUser, + XVerifyUser, + XUnverifyUser, + XUsersChart, + XNotesChart, + XDriveChart }, data() { return { - page: 'dashboard' + page: 'dashboard', + chart: null }; }, + created() { + (this as any).api('admin/chart').then(chart => { + this.chart = chart; + }); + }, methods: { nav(page: string) { this.page = page; @@ -47,7 +68,7 @@ export default Vue.extend({ }); </script> -<style lang="stylus" scoped> +<style lang="stylus"> @import '~const.styl' .mk-admin @@ -90,13 +111,23 @@ export default Vue.extend({ width 100% padding 16px 32px -header - margin 10px 0 + > div + > div + max-width 800px + +.card + padding 32px + background #fff + box-shadow 0 2px 8px rgba(#000, 0.1) + &:not(:last-child) + margin-bottom 16px -button - margin 16px 0 - position absolute - right 0 + > header + margin 0 0 1em 0 + padding 0 0 8px 0 + font-size 1em + color #555 + border-bottom solid 1px #eee </style> diff --git a/src/client/app/dev/views/new-app.vue b/src/client/app/dev/views/new-app.vue index bf19e6da57..87b35db259 100644 --- a/src/client/app/dev/views/new-app.vue +++ b/src/client/app/dev/views/new-app.vue @@ -95,7 +95,7 @@ export default Vue.extend({ callbackUrl: this.cb, permission: this.permission }).then(() => { - location.href = '/apps'; + location.href = '/dev/apps'; }).catch(() => { alert('アプリの作成に失敗しました。再度お試しください。'); }); diff --git a/src/client/app/mobile/views/components/post-form.vue b/src/client/app/mobile/views/components/post-form.vue index 702bc4c9e1..a74df67c0a 100644 --- a/src/client/app/mobile/views/components/post-form.vue +++ b/src/client/app/mobile/views/components/post-form.vue @@ -56,7 +56,7 @@ import Vue from 'vue'; import insertTextAtCursor from 'insert-text-at-cursor'; import * as XDraggable from 'vuedraggable'; import MkVisibilityChooser from '../../../common/views/components/visibility-chooser.vue'; -import getKao from '../../../common/scripts/get-kao'; +import getFace from '../../../common/scripts/get-face'; import parse from '../../../../../mfm/parse'; import { host } from '../../../config'; @@ -94,7 +94,7 @@ export default Vue.extend({ files: [], poll: false, geo: null, - visibility: 'public', + visibility: this.$store.state.device.visibility || 'public', visibleUsers: [], useCw: false, cw: null, @@ -240,8 +240,7 @@ export default Vue.extend({ setVisibility() { const w = (this as any).os.new(MkVisibilityChooser, { source: this.$refs.visibilityButton, - compact: true, - v: this.visibility + compact: true }); w.$once('chosen', v => { this.visibility = v; @@ -314,7 +313,7 @@ export default Vue.extend({ }, kao() { - this.text += getKao(); + this.text += getFace(); } } }); diff --git a/src/client/app/stats/style.styl b/src/client/app/stats/style.styl deleted file mode 100644 index 5ae230ea56..0000000000 --- a/src/client/app/stats/style.styl +++ /dev/null @@ -1,10 +0,0 @@ -@import "../app" -@import "../reset" - -html - color #456267 - background #fff - -body - margin 0 - padding 0 diff --git a/src/client/app/stats/tags/index.tag b/src/client/app/stats/tags/index.tag deleted file mode 100644 index f8944c0832..0000000000 --- a/src/client/app/stats/tags/index.tag +++ /dev/null @@ -1,209 +0,0 @@ -<mk-index> - <h1>Misskey<i>Statistics</i></h1> - <main v-if="!initializing"> - <mk-users stats={ stats }/> - <mk-notes stats={ stats }/> - </main> - <footer><a href={ _URL_ }>{ _HOST_ }</a></footer> - <style lang="stylus" scoped> - :scope - display block - margin 0 auto - padding 0 16px - max-width 700px - - > h1 - margin 0 - padding 24px 0 0 0 - font-size 24px - font-weight normal - - > i - font-style normal - color #f43b16 - - > main - > * - margin 24px 0 - padding-top 24px - border-top solid 1px #eee - - > h2 - margin 0 0 12px 0 - font-size 18px - font-weight normal - - > footer - margin 24px 0 - text-align center - - > a - color #546567 - </style> - <script lang="typescript"> - this.mixin('api'); - - this.initializing = true; - - this.on('mount', () => { - this.$root.$data.os.api('stats').then(stats => { - this.update({ - initializing: false, - stats - }); - }); - }); - </script> -</mk-index> - -<mk-notes> - <h2>%i18n:stats.notes-count% <b>{ stats.notesCount }</b></h2> - <mk-notes-chart v-if="!initializing" data={ data }/> - <style lang="stylus" scoped> - :scope - display block - </style> - <script lang="typescript"> - this.mixin('api'); - - this.initializing = true; - this.stats = this.opts.stats; - - this.on('mount', () => { - this.$root.$data.os.api('aggregation/notes', { - limit: 365 - }).then(data => { - this.update({ - initializing: false, - data - }); - }); - }); - </script> -</mk-notes> - -<mk-users> - <h2>%i18n:stats.users-count% <b>{ stats.usersCount }</b></h2> - <mk-users-chart v-if="!initializing" data={ data }/> - <style lang="stylus" scoped> - :scope - display block - </style> - <script lang="typescript"> - this.mixin('api'); - - this.initializing = true; - this.stats = this.opts.stats; - - this.on('mount', () => { - this.$root.$data.os.api('aggregation/users', { - limit: 365 - }).then(data => { - this.update({ - initializing: false, - data - }); - }); - }); - </script> -</mk-users> - -<mk-notes-chart> - <svg riot-viewBox="0 0 { viewBoxX } { viewBoxY }" preserveAspectRatio="none"> - <title>Black ... Total<br/>Blue ... Notes<br/>Red ... Replies<br/>Green ... Renotes</title> - <polyline - riot-points={ pointsNote } - fill="none" - stroke-width="1" - stroke="#41ddde"/> - <polyline - riot-points={ pointsReply } - fill="none" - stroke-width="1" - stroke="#f7796c"/> - <polyline - riot-points={ pointsRenote } - fill="none" - stroke-width="1" - stroke="#a1de41"/> - <polyline - riot-points={ pointsTotal } - fill="none" - stroke-width="1" - stroke="#555" - stroke-dasharray="2 2"/> - </svg> - <style lang="stylus" scoped> - :scope - display block - - > svg - display block - padding 1px - width 100% - </style> - <script lang="typescript"> - this.viewBoxX = 365; - this.viewBoxY = 80; - - this.data = this.opts.data.reverse(); - this.data.forEach(d => d.total = d.notes + d.replies + d.renotes); - const peak = Math.max.apply(null, this.data.map(d => d.total)); - - this.on('mount', () => { - this.render(); - }); - - this.render = () => { - this.update({ - pointsNote: this.data.map((d, i) => `${i},${(1 - (d.notes / peak)) * this.viewBoxY}`).join(' '), - pointsReply: this.data.map((d, i) => `${i},${(1 - (d.replies / peak)) * this.viewBoxY}`).join(' '), - pointsRenote: this.data.map((d, i) => `${i},${(1 - (d.renotes / peak)) * this.viewBoxY}`).join(' '), - pointsTotal: this.data.map((d, i) => `${i},${(1 - (d.total / peak)) * this.viewBoxY}`).join(' ') - }); - }; - </script> -</mk-notes-chart> - -<mk-users-chart> - <svg riot-viewBox="0 0 { viewBoxX } { viewBoxY }" preserveAspectRatio="none"> - <polyline - riot-points={ createdPoints } - fill="none" - stroke-width="1" - stroke="#1cde84"/> - <polyline - riot-points={ totalPoints } - fill="none" - stroke-width="1" - stroke="#555"/> - </svg> - <style lang="stylus" scoped> - :scope - display block - - > svg - display block - padding 1px - width 100% - </style> - <script lang="typescript"> - this.viewBoxX = 365; - this.viewBoxY = 80; - - this.data = this.opts.data.reverse(); - const totalPeak = Math.max.apply(null, this.data.map(d => d.total)); - const createdPeak = Math.max.apply(null, this.data.map(d => d.created)); - - this.on('mount', () => { - this.render(); - }); - - this.render = () => { - this.update({ - totalPoints: this.data.map((d, i) => `${i},${(1 - (d.total / totalPeak)) * this.viewBoxY}`).join(' '), - createdPoints: this.data.map((d, i) => `${i},${(1 - (d.created / createdPeak)) * this.viewBoxY}`).join(' ') - }); - }; - </script> -</mk-users-chart> diff --git a/src/client/app/stats/tags/index.ts b/src/client/app/stats/tags/index.ts deleted file mode 100644 index f41151949f..0000000000 --- a/src/client/app/stats/tags/index.ts +++ /dev/null @@ -1 +0,0 @@ -require('./index.tag'); diff --git a/src/client/app/status/style.styl b/src/client/app/status/style.styl deleted file mode 100644 index 5ae230ea56..0000000000 --- a/src/client/app/status/style.styl +++ /dev/null @@ -1,10 +0,0 @@ -@import "../app" -@import "../reset" - -html - color #456267 - background #fff - -body - margin 0 - padding 0 diff --git a/src/client/app/status/tags/index.tag b/src/client/app/status/tags/index.tag deleted file mode 100644 index 899467097a..0000000000 --- a/src/client/app/status/tags/index.tag +++ /dev/null @@ -1,201 +0,0 @@ -<mk-index> - <h1>Misskey<i>Status</i></h1> - <p>%fa:info-circle%%i18n:status.all-systems-maybe-operational%</p> - <main> - <mk-cpu-usage connection={ connection }/> - <mk-mem-usage connection={ connection }/> - </main> - <footer><a href={ _URL_ }>{ _HOST_ }</a></footer> - <style lang="stylus" scoped> - :scope - display block - margin 0 auto - padding 0 16px - max-width 700px - - > h1 - margin 0 - padding 24px 0 16px 0 - font-size 24px - font-weight normal - - > [data-fa] - font-style normal - color #f43b16 - - > p - display block - margin 0 - padding 12px 16px - background #eaf4ef - //border solid 1px #99ccb2 - border-radius 4px - - > [data-fa] - margin-right 5px - - > main - > * - margin 24px 0 - - > h2 - margin 0 0 12px 0 - font-size 18px - font-weight normal - - > footer - margin 24px 0 - text-align center - - > a - color #546567 - </style> - <script lang="typescript"> - import Connection from '../../common/scripts/streaming/server-stream'; - - this.mixin('api'); - - this.initializing = true; - this.connection = new Connection(); - - this.on('mount', () => { - this.$root.$data.os.api('meta').then(meta => { - this.update({ - initializing: false, - meta - }); - }); - }); - - this.on('unmount', () => { - this.connection.close(); - }); - - </script> -</mk-index> - -<mk-cpu-usage> - <h2>CPU <b>{ percentage }%</b></h2> - <mk-line-chart ref="chart"/> - <style lang="stylus" scoped> - :scope - display block - </style> - <script lang="typescript"> - this.connection = this.opts.connection; - - this.on('mount', () => { - this.connection.on('stats', this.onStats); - }); - - this.on('unmount', () => { - this.connection.off('stats', this.onStats); - }); - - this.onStats = stats => { - this.$refs.chart.addData(1 - stats.cpu_usage); - - const percentage = (stats.cpu_usage * 100).toFixed(0); - - this.update({ - percentage - }); - }; - </script> -</mk-cpu-usage> - -<mk-mem-usage> - <h2>MEM <b>{ percentage }%</b></h2> - <mk-line-chart ref="chart"/> - <style lang="stylus" scoped> - :scope - display block - </style> - <script lang="typescript"> - this.connection = this.opts.connection; - - this.on('mount', () => { - this.connection.on('stats', this.onStats); - }); - - this.on('unmount', () => { - this.connection.off('stats', this.onStats); - }); - - this.onStats = stats => { - stats.mem.used = stats.mem.total - stats.mem.free; - this.$refs.chart.addData(1 - (stats.mem.used / stats.mem.total)); - - const percentage = (stats.mem.used / stats.mem.total * 100).toFixed(0); - - this.update({ - percentage - }); - }; - </script> -</mk-mem-usage> - -<mk-line-chart> - <svg riot-viewBox="0 0 { viewBoxX } { viewBoxY }" preserveAspectRatio="none"> - <defs> - <linearGradient id={ gradientId } x1="0" x2="0" y1="1" y2="0"> - <stop offset="0%" stop-color="rgba(244, 59, 22, 0)"></stop> - <stop offset="100%" stop-color="#f43b16"></stop> - </linearGradient> - <mask id={ maskId } x="0" y="0" riot-width={ viewBoxX } riot-height={ viewBoxY }> - <polygon - riot-points={ polygonPoints } - fill="#fff" - fill-opacity="0.5"/> - </mask> - </defs> - <line x1="0" y1="0" riot-x2={ viewBoxX } y2="0" stroke="rgba(255, 255, 255, 0.1)" stroke-width="0.25" stroke-dasharray="1"/> - <line x1="0" y1="25%" riot-x2={ viewBoxX } y2="25%" stroke="rgba(255, 255, 255, 0.1)" stroke-width="0.25" stroke-dasharray="1"/> - <line x1="0" y1="50%" riot-x2={ viewBoxX } y2="50%" stroke="rgba(255, 255, 255, 0.1)" stroke-width="0.25" stroke-dasharray="1"/> - <line x1="0" y1="75%" riot-x2={ viewBoxX } y2="75%" stroke="rgba(255, 255, 255, 0.1)" stroke-width="0.25" stroke-dasharray="1"/> - <line x1="0" y1="100%" riot-x2={ viewBoxX } y2="100%" stroke="rgba(255, 255, 255, 0.1)" stroke-width="0.25" stroke-dasharray="1"/> - <rect - x="-1" y="-1" - riot-width={ viewBoxX + 2 } riot-height={ viewBoxY + 2 } - style="stroke: none; fill: url(#{ gradientId }); mask: url(#{ maskId })"/> - <polyline - riot-points={ polylinePoints } - fill="none" - stroke="#f43b16" - stroke-width="0.5"/> - </svg> - <style lang="stylus" scoped> - :scope - display block - padding 16px - border-radius 8px - background #1c2531 - - > svg - display block - padding 1px - width 100% - </style> - <script lang="typescript"> - import uuid from 'uuid'; - - this.viewBoxX = 100; - this.viewBoxY = 30; - this.data = []; - this.gradientId = uuid(); - this.maskId = uuid(); - - this.addData = data => { - this.data.push(data); - if (this.data.length > 100) this.data.shift(); - - const polylinePoints = this.data.map((d, i) => `${this.viewBoxX - ((this.data.length - 1) - i)},${d * this.viewBoxY}`).join(' '); - const polygonPoints = `${this.viewBoxX - (this.data.length - 1)},${ this.viewBoxY } ${ polylinePoints } ${ this.viewBoxX },${ this.viewBoxY }`; - - this.update({ - polylinePoints, - polygonPoints - }); - }; - </script> -</mk-line-chart> diff --git a/src/client/app/status/tags/index.ts b/src/client/app/status/tags/index.ts deleted file mode 100644 index f41151949f..0000000000 --- a/src/client/app/status/tags/index.ts +++ /dev/null @@ -1 +0,0 @@ -require('./index.tag'); diff --git a/src/client/app/store.ts b/src/client/app/store.ts index f85253a281..7e2cc3976b 100644 --- a/src/client/app/store.ts +++ b/src/client/app/store.ts @@ -110,6 +110,10 @@ export default (os: MiOS) => new Vuex.Store({ src: x.src, arg: x.arg }; + }, + + setVisibility(state, visibility) { + state.visibility = visibility; } } }, diff --git a/src/mfm/html-to-mfm.ts b/src/mfm/html-to-mfm.ts index daa228ec51..084578fc18 100644 --- a/src/mfm/html-to-mfm.ts +++ b/src/mfm/html-to-mfm.ts @@ -49,6 +49,9 @@ export default function(html: string): string { text += txt; break; } + // メンション以外 + } else { + text += `[${txt}](${node.attrs.find((x: any) => x.name == 'href').value})`; } if (node.childNodes) { diff --git a/src/mfm/html.ts b/src/mfm/html.ts index c11bd55cf4..c798ee410a 100644 --- a/src/mfm/html.ts +++ b/src/mfm/html.ts @@ -5,6 +5,10 @@ import config from '../config'; import { INote } from '../models/note'; import { TextElement } from './parse'; +function intersperse<T>(sep: T, xs: T[]): T[] { + return [].concat(...xs.map(x => [sep, x])).slice(1); +} + const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: INote['mentionedRemoteUsers']) => void } = { bold({ document }, { bold }) { const b = document.createElement('b'); @@ -80,12 +84,9 @@ const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: }, text({ document }, { content }) { - for (const text of content.split('\n')) { - const node = document.createTextNode(text); - document.body.appendChild(node); - - const br = document.createElement('br'); - document.body.appendChild(br); + const nodes = (content as string).split('\n').map(x => document.createTextNode(x)); + for (const x of intersperse(document.createElement('br'), nodes)) { + document.body.appendChild(x); } }, diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts index 2b9efc404d..dbbc1f1cd5 100644 --- a/src/models/drive-file.ts +++ b/src/models/drive-file.ts @@ -52,6 +52,11 @@ export type IDriveFile = { filename: string; contentType: string; metadata: IMetadata; + + /** + * ファイルサイズ + */ + length: number; }; export function validateFileName(name: string): boolean { diff --git a/src/models/meta.ts b/src/models/meta.ts index 11b9b186ce..aef0163dfe 100644 --- a/src/models/meta.ts +++ b/src/models/meta.ts @@ -11,4 +11,5 @@ export type IMeta = { usersCount: number; originalUsersCount: number; }; + disableRegistration: boolean; }; diff --git a/src/models/registration-tickets.ts b/src/models/registration-tickets.ts new file mode 100644 index 0000000000..846acefedf --- /dev/null +++ b/src/models/registration-tickets.ts @@ -0,0 +1,12 @@ +import * as mongo from 'mongodb'; +import db from '../db/mongodb'; + +const RegistrationTicket = db.get<IRegistrationTicket>('registrationTickets'); +RegistrationTicket.createIndex('code', { unique: true }); +export default RegistrationTicket; + +export interface IRegistrationTicket { + _id: mongo.ObjectID; + createdAt: Date; + code: string; +} diff --git a/src/models/stats.ts b/src/models/stats.ts new file mode 100644 index 0000000000..7bff475c63 --- /dev/null +++ b/src/models/stats.ts @@ -0,0 +1,153 @@ +import * as mongo from 'mongodb'; +import db from '../db/mongodb'; + +const Stats = db.get<IStats>('stats'); +Stats.createIndex({ date: -1 }, { unique: true }); +export default Stats; + +export interface IStats { + _id: mongo.ObjectID; + + date: Date; + + /** + * ユーザーに関する統計 + */ + users: { + local: { + /** + * この日時点での、ローカルのユーザーの総計 + */ + total: number; + + /** + * ローカルのユーザー数の前日比 + */ + diff: number; + }; + + remote: { + /** + * この日時点での、リモートのユーザーの総計 + */ + total: number; + + /** + * リモートのユーザー数の前日比 + */ + diff: number; + }; + }; + + /** + * 投稿に関する統計 + */ + notes: { + local: { + /** + * この日時点での、ローカルの投稿の総計 + */ + total: number; + + /** + * ローカルの投稿数の前日比 + */ + diff: number; + + diffs: { + /** + * ローカルの通常の投稿数の前日比 + */ + normal: number; + + /** + * ローカルのリプライの投稿数の前日比 + */ + reply: number; + + /** + * ローカルのRenoteの投稿数の前日比 + */ + renote: number; + }; + }; + + remote: { + /** + * この日時点での、リモートの投稿の総計 + */ + total: number; + + /** + * リモートの投稿数の前日比 + */ + diff: number; + + diffs: { + /** + * リモートの通常の投稿数の前日比 + */ + normal: number; + + /** + * リモートのリプライの投稿数の前日比 + */ + reply: number; + + /** + * リモートのRenoteの投稿数の前日比 + */ + renote: number; + }; + }; + }; + + /** + * ドライブ(のファイル)に関する統計 + */ + drive: { + local: { + /** + * この日時点での、ローカルのドライブファイル数の総計 + */ + totalCount: number; + + /** + * この日時点での、ローカルのドライブファイルサイズの総計 + */ + totalSize: number; + + /** + * ローカルのドライブファイル数の前日比 + */ + diffCount: number; + + /** + * ローカルのドライブファイルサイズの前日比 + */ + diffSize: number; + }; + + remote: { + /** + * この日時点での、リモートのドライブファイル数の総計 + */ + totalCount: number; + + /** + * この日時点での、リモートのドライブファイルサイズの総計 + */ + totalSize: number; + + /** + * リモートのドライブファイル数の前日比 + */ + diffCount: number; + + /** + * リモートのドライブファイルサイズの前日比 + */ + diffSize: number; + }; + }; +} 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); +}); diff --git a/src/server/api/endpoints/admin/invite.ts b/src/server/api/endpoints/admin/invite.ts new file mode 100644 index 0000000000..77608e715c --- /dev/null +++ b/src/server/api/endpoints/admin/invite.ts @@ -0,0 +1,26 @@ +import rndstr from 'rndstr'; +import RegistrationTicket from '../../../../models/registration-tickets'; + +export const meta = { + desc: { + ja: '招待コードを発行します。' + }, + + requireCredential: true, + requireAdmin: true, + + params: {} +}; + +export default (params: any) => new Promise(async (res, rej) => { + const code = rndstr({ length: 5, chars: '0-9' }); + + await RegistrationTicket.insert({ + createdAt: new Date(), + code: code + }); + + res({ + code: code + }); +}); diff --git a/src/server/api/endpoints/admin/suspend-user.ts b/src/server/api/endpoints/admin/suspend-user.ts index 8698120cdb..9c32ba987d 100644 --- a/src/server/api/endpoints/admin/suspend-user.ts +++ b/src/server/api/endpoints/admin/suspend-user.ts @@ -4,43 +4,43 @@ import getParams from '../../get-params'; import User from '../../../../models/user'; export const meta = { - desc: { - ja: '指定したユーザーを凍結します。', - en: 'Suspend a user.' - }, + desc: { + ja: '指定したユーザーを凍結します。', + en: 'Suspend a user.' + }, - requireCredential: true, - requireAdmin: true, + requireCredential: true, + requireAdmin: true, - params: { - userId: $.type(ID).note({ - desc: { - ja: '対象のユーザーID', - en: 'The user ID which you want to suspend' - } - }), - } + params: { + userId: $.type(ID).note({ + desc: { + ja: '対象のユーザーID', + en: 'The user ID which you want to suspend' + } + }), + } }; export default (params: any) => new Promise(async (res, rej) => { - const [ps, psErr] = getParams(meta, params); - if (psErr) return rej(psErr); + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); - const user = await User.findOne({ - _id: ps.userId - }); + const user = await User.findOne({ + _id: ps.userId + }); - if (user == null) { - return rej('user not found'); - } + if (user == null) { + return rej('user not found'); + } - await User.findOneAndUpdate({ - _id: user._id - }, { - $set: { - isSuspended: true - } - }); + await User.findOneAndUpdate({ + _id: user._id + }, { + $set: { + isSuspended: true + } + }); - res(); + res(); }); diff --git a/src/server/api/endpoints/admin/unverify-user.ts b/src/server/api/endpoints/admin/unverify-user.ts new file mode 100644 index 0000000000..34653cd78a --- /dev/null +++ b/src/server/api/endpoints/admin/unverify-user.ts @@ -0,0 +1,46 @@ +import $ from 'cafy'; +import ID from '../../../../misc/cafy-id'; +import getParams from '../../get-params'; +import User from '../../../../models/user'; + +export const meta = { + desc: { + ja: '指定したユーザーの公式アカウントを解除します。', + en: 'Mark a user as unverified.' + }, + + requireCredential: true, + requireAdmin: true, + + params: { + userId: $.type(ID).note({ + desc: { + ja: '対象のユーザーID', + en: 'The user ID which you want to unverify' + } + }), + } +}; + +export default (params: any) => new Promise(async (res, rej) => { + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); + + const user = await User.findOne({ + _id: ps.userId + }); + + if (user == null) { + return rej('user not found'); + } + + await User.findOneAndUpdate({ + _id: user._id + }, { + $set: { + isVerified: false + } + }); + + res(); +}); diff --git a/src/server/api/endpoints/admin/verify-user.ts b/src/server/api/endpoints/admin/verify-user.ts new file mode 100644 index 0000000000..5b826eb1c3 --- /dev/null +++ b/src/server/api/endpoints/admin/verify-user.ts @@ -0,0 +1,46 @@ +import $ from 'cafy'; +import ID from '../../../../misc/cafy-id'; +import getParams from '../../get-params'; +import User from '../../../../models/user'; + +export const meta = { + desc: { + ja: '指定したユーザーを公式アカウントにします。', + en: 'Mark a user as verified.' + }, + + requireCredential: true, + requireAdmin: true, + + params: { + userId: $.type(ID).note({ + desc: { + ja: '対象のユーザーID', + en: 'The user ID which you want to verify' + } + }), + } +}; + +export default (params: any) => new Promise(async (res, rej) => { + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); + + const user = await User.findOne({ + _id: ps.userId + }); + + if (user == null) { + return rej('user not found'); + } + + await User.findOneAndUpdate({ + _id: user._id + }, { + $set: { + isVerified: true + } + }); + + res(); +}); diff --git a/src/server/api/endpoints/aggregation/posts.ts b/src/server/api/endpoints/aggregation/posts.ts deleted file mode 100644 index 629bb19108..0000000000 --- a/src/server/api/endpoints/aggregation/posts.ts +++ /dev/null @@ -1,84 +0,0 @@ -import $ from 'cafy'; -import Note from '../../../../models/note'; - -/** - * Aggregate notes - */ -export default (params: any) => new Promise(async (res, rej) => { - // Get 'limit' parameter - const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); - if (limitErr) return rej('invalid limit param'); - - const datas = await Note - .aggregate([ - { $project: { - renoteId: '$renoteId', - replyId: '$replyId', - createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST - }}, - { $project: { - date: { - year: { $year: '$createdAt' }, - month: { $month: '$createdAt' }, - day: { $dayOfMonth: '$createdAt' } - }, - type: { - $cond: { - if: { $ne: ['$renoteId', null] }, - then: 'renote', - else: { - $cond: { - if: { $ne: ['$replyId', null] }, - then: 'reply', - else: 'note' - } - } - } - }} - }, - { $group: { _id: { - date: '$date', - type: '$type' - }, count: { $sum: 1 } } }, - { $group: { - _id: '$_id.date', - data: { $addToSet: { - type: '$_id.type', - count: '$count' - }} - } } - ]); - - datas.forEach((data: any) => { - data.date = data._id; - delete data._id; - - data.notes = (data.data.filter((x: any) => x.type == 'note')[0] || { count: 0 }).count; - data.renotes = (data.data.filter((x: any) => x.type == 'renote')[0] || { count: 0 }).count; - data.replies = (data.data.filter((x: any) => 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: any) => - 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({ - notes: 0, - renotes: 0, - replies: 0 - }); - } - } - - res(graph); -}); diff --git a/src/server/api/endpoints/aggregation/users.ts b/src/server/api/endpoints/aggregation/users.ts deleted file mode 100644 index f1e41cf170..0000000000 --- a/src/server/api/endpoints/aggregation/users.ts +++ /dev/null @@ -1,55 +0,0 @@ -import $ from 'cafy'; -import User from '../../../../models/user'; - -/** - * Aggregate users - */ -export default (params: any) => new Promise(async (res, rej) => { - // Get 'limit' parameter - const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); - if (limitErr) return rej('invalid limit param'); - - const users = await User - .find({}, { - sort: { - _id: -1 - }, - fields: { - _id: false, - createdAt: true, - deletedAt: true - } - }); - - 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.createdAt < dayEnd && (u.deletedAt == null || u.deletedAt > dayEnd) - ).length; - - const created = users.filter(u => - u.createdAt < dayEnd && u.createdAt > dayStart - ).length; - - graph.push({ - total: total, - created: created - }); - } - - res(graph); -}); diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index c2d93997a7..000a56024d 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -28,6 +28,7 @@ export default () => new Promise(async (res, rej) => { model: os.cpus()[0].model, cores: os.cpus().length }, - broadcasts: meta.broadcasts + broadcasts: meta.broadcasts, + disableRegistration: meta.disableRegistration }); }); diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 66d018618c..9cdbec5270 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -16,8 +16,7 @@ export const meta = { limit: { duration: ms('1hour'), - max: 300, - minInterval: ms('1second') + max: 300 }, kind: 'note-write', diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts index 16ec33bcbf..79e5e6ec48 100644 --- a/src/server/api/private/signup.ts +++ b/src/server/api/private/signup.ts @@ -6,6 +6,7 @@ import User, { IUser, validateUsername, validatePassword, pack } from '../../../ import generateUserToken from '../common/generate-native-user-token'; import config from '../../../config'; import Meta from '../../../models/meta'; +import RegistrationTicket from '../../../models/registration-tickets'; if (config.recaptcha) { recaptcha.init({ @@ -29,6 +30,29 @@ export default async (ctx: Koa.Context) => { const username = body['username']; const password = body['password']; + const invitationCode = body['invitationCode']; + + const meta = await Meta.findOne({}); + + if (meta && meta.disableRegistration) { + if (invitationCode == null || typeof invitationCode != 'string') { + ctx.status = 400; + return; + } + + const ticket = await RegistrationTicket.findOne({ + code: invitationCode + }); + + if (ticket == null) { + ctx.status = 400; + return; + } + + RegistrationTicket.remove({ + _id: ticket._id + }); + } // Validate username if (!validateUsername(username)) { diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index da0d3fd82f..b090d56cee 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -17,6 +17,7 @@ import { isLocalUser, IUser, IRemoteUser } from '../../models/user'; import delFile from './delete-file'; import config from '../../config'; import { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail'; +import { updateDriveStats } from '../update-chart'; const log = debug('misskey:drive:add-file'); @@ -377,7 +378,8 @@ export default async function( publishDriveStream(user._id, 'file_created', packedFile); }); - // TODO: サムネイル生成 + // 統計を更新 + updateDriveStats(driveFile, true); return driveFile; } diff --git a/src/services/drive/delete-file.ts b/src/services/drive/delete-file.ts index 445d231d66..73532a2953 100644 --- a/src/services/drive/delete-file.ts +++ b/src/services/drive/delete-file.ts @@ -2,6 +2,7 @@ import * as Minio from 'minio'; import DriveFile, { DriveFileChunk, IDriveFile } from '../../models/drive-file'; import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-file-thumbnail'; import config from '../../config'; +import { updateDriveStats } from '../update-chart'; export default async function(file: IDriveFile, isExpired = false) { if (file.metadata.storage == 'minio') { @@ -45,4 +46,7 @@ export default async function(file: IDriveFile, isExpired = false) { await DriveFileThumbnail.remove({ _id: thumbnail._id }); } //#endregion + + // 統計を更新 + updateDriveStats(file, false); } diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 521750dc84..d8f0f57b63 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -23,6 +23,7 @@ import registerHashtag from '../register-hashtag'; import isQuote from '../../misc/is-quote'; import { TextElementMention } from '../../mfm/parse/elements/mention'; import { TextElementHashtag } from '../../mfm/parse/elements/hashtag'; +import { updateNoteStats } from '../update-chart'; type NotificationType = 'reply' | 'renote' | 'quote' | 'mention'; @@ -142,6 +143,9 @@ export default async (user: IUser, data: Option, silent = false) => new Promise< return; } + // 統計を更新 + updateNoteStats(note, true); + // ハッシュタグ登録 tags.map(tag => registerHashtag(user, tag)); diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index 7f245958b0..d444b13a8b 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -6,6 +6,7 @@ import pack from '../../remote/activitypub/renderer'; import { deliver } from '../../queue'; import Following from '../../models/following'; import renderNote from '../../remote/activitypub/renderer/note'; +import { updateNoteStats } from '../update-chart'; /** * 投稿を削除します。 @@ -43,4 +44,7 @@ export default async function(user: IUser, note: INote) { }); } //#endregion + + // 統計を更新 + updateNoteStats(note, false); } diff --git a/src/services/update-chart.ts b/src/services/update-chart.ts new file mode 100644 index 0000000000..7998baca9d --- /dev/null +++ b/src/services/update-chart.ts @@ -0,0 +1,223 @@ +import { INote } from '../models/note'; +import Stats, { IStats } from '../models/stats'; +import { isLocalUser, IUser } from '../models/user'; +import { IDriveFile } from '../models/drive-file'; + +type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; + +async function getTodayStats(): Promise<IStats> { + const now = new Date(); + const y = now.getFullYear(); + const m = now.getMonth(); + const d = now.getDate(); + const today = new Date(y, m, d); + + // 今日の統計 + const todayStats = await Stats.findOne({ + date: today + }); + + // 日付が変わってから、初めてのチャート更新なら + if (todayStats == null) { + // 最も最近の統計を持ってくる + // * 昨日何もチャートを更新するような出来事がなかった場合は、 + // 統計がそもそも作られずドキュメントが存在しないということがあり得るため、 + // 「昨日の」と決め打ちせずに「もっとも最近の」とします + const mostRecentStats = await Stats.findOne({}, { + sort: { + date: -1 + } + }); + + // 統計が存在しなかったら + // * Misskeyインスタンスを建てて初めてのチャート更新時など + if (mostRecentStats == null) { + // 空の統計を作成 + const chart: Omit<IStats, '_id'> = { + date: today, + 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 + } + } + }; + + const stats = await Stats.insert(chart); + + return stats; + } else { + // 今日の統計を初期挿入 + const chart: Omit<IStats, '_id'> = { + date: today, + users: { + local: { + total: mostRecentStats.users.local.total, + diff: 0 + }, + remote: { + total: mostRecentStats.users.remote.total, + diff: 0 + } + }, + notes: { + local: { + total: mostRecentStats.notes.local.total, + diff: 0, + diffs: { + normal: 0, + reply: 0, + renote: 0 + } + }, + remote: { + total: mostRecentStats.notes.remote.total, + diff: 0, + diffs: { + normal: 0, + reply: 0, + renote: 0 + } + } + }, + drive: { + local: { + totalCount: mostRecentStats.drive.local.totalCount, + totalSize: mostRecentStats.drive.local.totalSize, + diffCount: 0, + diffSize: 0 + }, + remote: { + totalCount: mostRecentStats.drive.remote.totalCount, + totalSize: mostRecentStats.drive.remote.totalSize, + diffCount: 0, + diffSize: 0 + } + } + }; + + const stats = await Stats.insert(chart); + + return stats; + } + } else { + return todayStats; + } +} + +async function update(inc: any) { + const stats = await getTodayStats(); + + await Stats.findOneAndUpdate({ + _id: stats._id + }, { + $inc: inc + }); +} + +export async function updateUserStats(user: IUser, isAdditional: boolean) { + const inc = {} as any; + + const amount = isAdditional ? 1 : -1; + + if (isLocalUser(user)) { + inc['users.local.total'] = amount; + inc['users.local.diff'] = amount; + } else { + inc['users.remote.total'] = amount; + inc['users.remote.diff'] = amount; + } + + await update(inc); +} + +export async function updateNoteStats(note: INote, isAdditional: boolean) { + const inc = {} as any; + + const amount = isAdditional ? 1 : -1; + + if (isLocalUser(note._user)) { + inc['notes.local.total'] = amount; + inc['notes.local.diff'] = amount; + + if (note.replyId != null) { + inc['notes.local.diffs.reply'] = amount; + } else if (note.renoteId != null) { + inc['notes.local.diffs.renote'] = amount; + } else { + inc['notes.local.diffs.normal'] = amount; + } + } else { + inc['notes.remote.total'] = amount; + inc['notes.remote.diff'] = amount; + + if (note.replyId != null) { + inc['notes.remote.diffs.reply'] = amount; + } else if (note.renoteId != null) { + inc['notes.remote.diffs.renote'] = amount; + } else { + inc['notes.remote.diffs.normal'] = amount; + } + } + + await update(inc); +} + +export async function updateDriveStats(file: IDriveFile, isAdditional: boolean) { + const inc = {} as any; + + const amount = isAdditional ? 1 : -1; + const size = isAdditional ? file.length : -file.length; + + if (isLocalUser(file.metadata._user)) { + inc['drive.local.totalCount'] = amount; + inc['drive.local.diffCount'] = amount; + inc['drive.local.totalSize'] = size; + inc['drive.local.diffSize'] = size; + } else { + inc['drive.remote.total'] = amount; + inc['drive.remote.diff'] = amount; + inc['drive.remote.totalSize'] = size; + inc['drive.remote.diffSize'] = size; + } + + await update(inc); +} |