summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-08-30 03:56:51 +0900
committerGitHub <noreply@github.com>2018-08-30 03:56:51 +0900
commit4e11da98d90c1c44fce1abaf63c248896feff03a (patch)
treecbe91363f87a3cc29b142433c16e4b16ccf2aa7d /src/services
parentNew translations ja-JP.yml (French) (diff)
parent:art: (diff)
downloadmisskey-4e11da98d90c1c44fce1abaf63c248896feff03a.tar.gz
misskey-4e11da98d90c1c44fce1abaf63c248896feff03a.tar.bz2
misskey-4e11da98d90c1c44fce1abaf63c248896feff03a.zip
Merge branch 'develop' into l10n_develop
Diffstat (limited to 'src/services')
-rw-r--r--src/services/drive/add-file.ts5
-rw-r--r--src/services/following/delete.ts2
-rw-r--r--src/services/following/requests/cancel.ts11
-rw-r--r--src/services/note/create.ts4
-rw-r--r--src/services/note/delete.ts2
-rw-r--r--src/services/update-chart.ts194
6 files changed, 137 insertions, 81 deletions
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts
index b090d56cee..1da0f49a24 100644
--- a/src/services/drive/add-file.ts
+++ b/src/services/drive/add-file.ts
@@ -40,7 +40,7 @@ async function save(path: string, name: string, type: string, hash: string, size
const thumbnailKey = `${config.drive.prefix}/${uuid.v4()}/${name}.thumbnail.jpg`;
const baseUrl = config.drive.baseUrl
- || `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }`;
+ || `${ config.drive.config.useSSL ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }`;
await minio.putObject(config.drive.bucket, key, fs.createReadStream(path), size, {
'Content-Type': type,
@@ -116,7 +116,8 @@ async function deleteOldFile(user: IRemoteUser) {
const oldFile = await DriveFile.findOne({
_id: {
$nin: [user.avatarId, user.bannerId]
- }
+ },
+ 'metadata.userId': user._id
}, {
sort: {
_id: 1
diff --git a/src/services/following/delete.ts b/src/services/following/delete.ts
index 8a9f739bd4..7c285e9eac 100644
--- a/src/services/following/delete.ts
+++ b/src/services/following/delete.ts
@@ -56,7 +56,7 @@ export default async function(follower: IUser, followee: IUser) {
}
if (isLocalUser(follower) && isRemoteUser(followee)) {
- const content = pack(renderUndo(renderFollow(follower, followee)));
+ const content = pack(renderUndo(renderFollow(follower, followee), follower));
deliver(follower, content, followee.inbox);
}
}
diff --git a/src/services/following/requests/cancel.ts b/src/services/following/requests/cancel.ts
index b0b574da58..9655a95f04 100644
--- a/src/services/following/requests/cancel.ts
+++ b/src/services/following/requests/cancel.ts
@@ -8,10 +8,19 @@ import { publishUserStream } from '../../../stream';
export default async function(followee: IUser, follower: IUser) {
if (isRemoteUser(followee)) {
- const content = pack(renderUndo(renderFollow(follower, followee)));
+ const content = pack(renderUndo(renderFollow(follower, followee), follower));
deliver(follower as ILocalUser, content, followee.inbox);
}
+ const request = await FollowRequest.findOne({
+ followeeId: followee._id,
+ followerId: follower._id
+ });
+
+ if (request == null) {
+ throw 'request not found';
+ }
+
await FollowRequest.remove({
followeeId: followee._id,
followerId: follower._id
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index d8f0f57b63..63e3557828 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -239,8 +239,8 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
async function renderActivity(data: Option, note: INote) {
const content = data.renote && data.text == null
- ? renderAnnounce(data.renote.uri ? data.renote.uri : await renderNote(data.renote), note)
- : renderCreate(await renderNote(note));
+ ? renderAnnounce(data.renote.uri ? data.renote.uri : `${config.url}/notes/${data.renote._id}`, note)
+ : renderCreate(await renderNote(note, false), note);
return packAp(content);
}
diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts
index d444b13a8b..d0e2b12b41 100644
--- a/src/services/note/delete.ts
+++ b/src/services/note/delete.ts
@@ -32,7 +32,7 @@ export default async function(user: IUser, note: INote) {
//#region ローカルの投稿なら削除アクティビティを配送
if (isLocalUser(user)) {
- const content = pack(renderDelete(await renderNote(note)));
+ const content = pack(renderDelete(await renderNote(note), user));
const followings = await Following.find({
followeeId: user._id,
diff --git a/src/services/update-chart.ts b/src/services/update-chart.ts
index 6b69adbdc3..1f8da6be9f 100644
--- a/src/services/update-chart.ts
+++ b/src/services/update-chart.ts
@@ -5,50 +5,63 @@ import { IDriveFile } from '../models/drive-file';
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
-async function getTodayStats(): Promise<IStats> {
+async function getCurrentStats(span: 'day' | 'hour'): 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 h = now.getHours();
- // 今日の統計
- const todayStats = await Stats.findOne({
- date: today
+ const current =
+ span == 'day' ? new Date(y, m, d) :
+ span == 'hour' ? new Date(y, m, d, h) :
+ null;
+
+ // 現在(今日または今のHour)の統計
+ const currentStats = await Stats.findOne({
+ span: span,
+ date: current
});
- // 日付が変わってから、初めてのチャート更新なら
- if (todayStats == null) {
+ if (currentStats) {
+ return currentStats;
+ } else {
+ // 集計期間が変わってから、初めてのチャート更新なら
// 最も最近の統計を持ってくる
+ // * 例えば集計期間が「日」である場合で考えると、
// * 昨日何もチャートを更新するような出来事がなかった場合は、
- // 統計がそもそも作られずドキュメントが存在しないということがあり得るため、
- // 「昨日の」と決め打ちせずに「もっとも最近の」とします
- const mostRecentStats = await Stats.findOne({}, {
+ // * 統計がそもそも作られずドキュメントが存在しないということがあり得るため、
+ // * 「昨日の」と決め打ちせずに「もっとも最近の」とします
+ const mostRecentStats = await Stats.findOne({
+ span: span
+ }, {
sort: {
date: -1
}
});
- // 統計が存在しなかったら
- // * Misskeyインスタンスを建てて初めてのチャート更新時など
- if (mostRecentStats == null) {
- // 空の統計を作成
+ if (mostRecentStats) {
+ // 現在の統計を初期挿入
const data: Omit<IStats, '_id'> = {
- date: today,
+ span: span,
+ date: current,
users: {
local: {
- total: 0,
- diff: 0
+ total: mostRecentStats.users.local.total,
+ inc: 0,
+ dec: 0
},
remote: {
- total: 0,
- diff: 0
+ total: mostRecentStats.users.remote.total,
+ inc: 0,
+ dec: 0
}
},
notes: {
local: {
- total: 0,
- diff: 0,
+ total: mostRecentStats.notes.local.total,
+ inc: 0,
+ dec: 0,
diffs: {
normal: 0,
reply: 0,
@@ -56,8 +69,9 @@ async function getTodayStats(): Promise<IStats> {
}
},
remote: {
- total: 0,
- diff: 0,
+ total: mostRecentStats.notes.remote.total,
+ inc: 0,
+ dec: 0,
diffs: {
normal: 0,
reply: 0,
@@ -67,16 +81,20 @@ async function getTodayStats(): Promise<IStats> {
},
drive: {
local: {
- totalCount: 0,
- totalSize: 0,
- diffCount: 0,
- diffSize: 0
+ totalCount: mostRecentStats.drive.local.totalCount,
+ totalSize: mostRecentStats.drive.local.totalSize,
+ incCount: 0,
+ incSize: 0,
+ decCount: 0,
+ decSize: 0
},
remote: {
- totalCount: 0,
- totalSize: 0,
- diffCount: 0,
- diffSize: 0
+ totalCount: mostRecentStats.drive.remote.totalCount,
+ totalSize: mostRecentStats.drive.remote.totalSize,
+ incCount: 0,
+ incSize: 0,
+ decCount: 0,
+ decSize: 0
}
}
};
@@ -85,23 +103,30 @@ async function getTodayStats(): Promise<IStats> {
return stats;
} else {
- // 今日の統計を初期挿入
- const data: Omit<IStats, '_id'> = {
- date: today,
+ // 統計が存在しなかったら
+ // * Misskeyインスタンスを建てて初めてのチャート更新時など
+
+ // 空の統計を作成
+ const emptyStat: Omit<IStats, '_id'> = {
+ span: span,
+ date: current,
users: {
local: {
- total: mostRecentStats.users.local.total,
- diff: 0
+ total: 0,
+ inc: 0,
+ dec: 0
},
remote: {
- total: mostRecentStats.users.remote.total,
- diff: 0
+ total: 0,
+ inc: 0,
+ dec: 0
}
},
notes: {
local: {
- total: mostRecentStats.notes.local.total,
- diff: 0,
+ total: 0,
+ inc: 0,
+ dec: 0,
diffs: {
normal: 0,
reply: 0,
@@ -109,8 +134,9 @@ async function getTodayStats(): Promise<IStats> {
}
},
remote: {
- total: mostRecentStats.notes.remote.total,
- diff: 0,
+ total: 0,
+ inc: 0,
+ dec: 0,
diffs: {
normal: 0,
reply: 0,
@@ -120,80 +146,100 @@ async function getTodayStats(): Promise<IStats> {
},
drive: {
local: {
- totalCount: mostRecentStats.drive.local.totalCount,
- totalSize: mostRecentStats.drive.local.totalSize,
- diffCount: 0,
- diffSize: 0
+ totalCount: 0,
+ totalSize: 0,
+ incCount: 0,
+ incSize: 0,
+ decCount: 0,
+ decSize: 0
},
remote: {
- totalCount: mostRecentStats.drive.remote.totalCount,
- totalSize: mostRecentStats.drive.remote.totalSize,
- diffCount: 0,
- diffSize: 0
+ totalCount: 0,
+ totalSize: 0,
+ incCount: 0,
+ incSize: 0,
+ decCount: 0,
+ decSize: 0
}
}
};
- const stats = await Stats.insert(data);
+ const stats = await Stats.insert(emptyStat);
return stats;
}
- } else {
- return todayStats;
}
}
-async function update(inc: any) {
- const stats = await getTodayStats();
+function update(inc: any) {
+ getCurrentStats('day').then(stats => {
+ Stats.findOneAndUpdate({
+ _id: stats._id
+ }, {
+ $inc: inc
+ });
+ });
- await Stats.findOneAndUpdate({
- _id: stats._id
- }, {
- $inc: inc
+ getCurrentStats('hour').then(stats => {
+ Stats.findOneAndUpdate({
+ _id: stats._id
+ }, {
+ $inc: inc
+ });
});
}
export async function updateUserStats(user: IUser, isAdditional: boolean) {
- const amount = isAdditional ? 1 : -1;
const origin = isLocalUser(user) ? 'local' : 'remote';
const inc = {} as any;
- inc[`users.${origin}.total`] = amount;
- inc[`users.${origin}.diff`] = amount;
+ inc[`users.${origin}.total`] = isAdditional ? 1 : -1;
+ if (isAdditional) {
+ inc[`users.${origin}.inc`] = 1;
+ } else {
+ inc[`users.${origin}.dec`] = 1;
+ }
await update(inc);
}
export async function updateNoteStats(note: INote, isAdditional: boolean) {
- const amount = isAdditional ? 1 : -1;
const origin = isLocalUser(note._user) ? 'local' : 'remote';
const inc = {} as any;
- inc[`notes.${origin}.total`] = amount;
- inc[`notes.${origin}.diff`] = amount;
+ inc[`notes.${origin}.total`] = isAdditional ? 1 : -1;
+
+ if (isAdditional) {
+ inc[`notes.${origin}.inc`] = 1;
+ } else {
+ inc[`notes.${origin}.dec`] = 1;
+ }
if (note.replyId != null) {
- inc[`notes.${origin}.diffs.reply`] = amount;
+ inc[`notes.${origin}.diffs.reply`] = isAdditional ? 1 : -1;
} else if (note.renoteId != null) {
- inc[`notes.${origin}.diffs.renote`] = amount;
+ inc[`notes.${origin}.diffs.renote`] = isAdditional ? 1 : -1;
} else {
- inc[`notes.${origin}.diffs.normal`] = amount;
+ inc[`notes.${origin}.diffs.normal`] = isAdditional ? 1 : -1;
}
await update(inc);
}
export async function updateDriveStats(file: IDriveFile, isAdditional: boolean) {
- const amount = isAdditional ? 1 : -1;
- const size = isAdditional ? file.length : -file.length;
const origin = isLocalUser(file.metadata._user) ? 'local' : 'remote';
const inc = {} as any;
- inc[`drive.${origin}.totalCount`] = amount;
- inc[`drive.${origin}.diffCount`] = amount;
- inc[`drive.${origin}.totalSize`] = size;
- inc[`drive.${origin}.diffSize`] = size;
+ inc[`drive.${origin}.totalCount`] = isAdditional ? 1 : -1;
+ inc[`drive.${origin}.totalSize`] = isAdditional ? file.length : -file.length;
+ if (isAdditional) {
+ inc[`drive.${origin}.incCount`] = 1;
+ inc[`drive.${origin}.incSize`] = file.length;
+ } else {
+ inc[`drive.${origin}.decCount`] = 1;
+ inc[`drive.${origin}.decSize`] = file.length;
+ }
await update(inc);
}