+
+
+
+
+
+
@@ -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({
});
-
diff --git a/src/client/app/dev/views/new-app.vue b/src/client/app/dev/views/new-app.vue
index bf19e6da5..87b35db25 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 702bc4c9e..a74df67c0 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 5ae230ea5..000000000
--- 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 f8944c083..000000000
--- a/src/client/app/stats/tags/index.tag
+++ /dev/null
@@ -1,209 +0,0 @@
-
- MisskeyStatistics
-
-
-
-
-
-
-
-
-
-
- %i18n:stats.notes-count% { stats.notesCount }
-
-
-
-
-
-
- %i18n:stats.users-count% { stats.usersCount }
-
-
-
-
-
-
-
- Black ... Total Blue ... Notes Red ... Replies Green ... Renotes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/client/app/stats/tags/index.ts b/src/client/app/stats/tags/index.ts
deleted file mode 100644
index f41151949..000000000
--- 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 5ae230ea5..000000000
--- 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 899467097..000000000
--- a/src/client/app/status/tags/index.tag
+++ /dev/null
@@ -1,201 +0,0 @@
-
- MisskeyStatus
- %fa:info-circle%%i18n:status.all-systems-maybe-operational%
-
-
-
-
-
-
-
-
-
-
- CPU { percentage }%
-
-
-
-
-
-
- MEM { percentage }%
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/client/app/status/tags/index.ts b/src/client/app/status/tags/index.ts
deleted file mode 100644
index f41151949..000000000
--- 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 f85253a28..7e2cc3976 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 daa228ec5..084578fc1 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 c11bd55cf..c798ee410 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
(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 2b9efc404..dbbc1f1cd 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 11b9b186c..aef0163df 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 000000000..846acefed
--- /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('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 000000000..7bff475c6
--- /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('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 000000000..a0566b11f
--- /dev/null
+++ b/src/server/api/endpoints/admin/chart.ts
@@ -0,0 +1,101 @@
+import Stats, { IStats } from '../../../../models/stats';
+
+type Omit = Pick>;
+
+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> = [];
+
+ 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 000000000..77608e715
--- /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 8698120cd..9c32ba987 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 000000000..34653cd78
--- /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 000000000..5b826eb1c
--- /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 629bb1910..000000000
--- 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 f1e41cf17..000000000
--- 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 c2d93997a..000a56024 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 66d018618..9cdbec527 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 16ec33bcb..79e5e6ec4 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 da0d3fd82..b090d56ce 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 445d231d6..73532a295 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 521750dc8..d8f0f57b6 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 7f245958b..d444b13a8 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 000000000..7998baca9
--- /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 = Pick>;
+
+async function getTodayStats(): Promise {
+ 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 = {
+ 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 = {
+ 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);
+}