diff options
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/drive-file.ts | 2 | ||||
| -rw-r--r-- | src/models/messaging-message.ts | 3 | ||||
| -rw-r--r-- | src/models/meta.ts | 8 | ||||
| -rw-r--r-- | src/models/note.ts | 144 | ||||
| -rw-r--r-- | src/models/stats.ts | 26 | ||||
| -rw-r--r-- | src/models/user.ts | 5 |
6 files changed, 118 insertions, 70 deletions
diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts index 698ef092a6..215b49b305 100644 --- a/src/models/drive-file.ts +++ b/src/models/drive-file.ts @@ -92,7 +92,7 @@ export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriv // このDriveFileを添付しているNoteをすべて削除 await Promise.all(( - await Note.find({ mediaIds: d._id }) + await Note.find({ fileIds: d._id }) ).map(x => deleteNote(x))); // このDriveFileを添付しているMessagingMessageをすべて削除 diff --git a/src/models/messaging-message.ts b/src/models/messaging-message.ts index f46abd506d..d778164de0 100644 --- a/src/models/messaging-message.ts +++ b/src/models/messaging-message.ts @@ -4,6 +4,7 @@ import { pack as packUser } from './user'; import { pack as packFile } from './drive-file'; import db from '../db/mongodb'; import MessagingHistory, { deleteMessagingHistory } from './messaging-history'; +import { length } from 'stringz'; const MessagingMessage = db.get<IMessagingMessage>('messagingMessages'); export default MessagingMessage; @@ -19,7 +20,7 @@ export interface IMessagingMessage { } export function isValidText(text: string): boolean { - return text.length <= 1000 && text.trim() != ''; + return length(text.trim()) <= 1000 && text.trim() != ''; } /** diff --git a/src/models/meta.ts b/src/models/meta.ts index aef0163dfe..8ca68416f8 100644 --- a/src/models/meta.ts +++ b/src/models/meta.ts @@ -4,12 +4,14 @@ const Meta = db.get<IMeta>('meta'); export default Meta; export type IMeta = { - broadcasts: any[]; - stats: { + broadcasts?: any[]; + stats?: { notesCount: number; originalNotesCount: number; usersCount: number; originalUsersCount: number; }; - disableRegistration: boolean; + disableRegistration?: boolean; + disableLocalTimeline?: boolean; + hidedTags?: string[]; }; diff --git a/src/models/note.ts b/src/models/note.ts index 9d2e23d901..6530d0b324 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -2,11 +2,12 @@ import * as mongo from 'mongodb'; const deepcopy = require('deepcopy'); import rap from '@prezzemolo/rap'; import db from '../db/mongodb'; +import { length } from 'stringz'; import { IUser, pack as packUser } from './user'; import { pack as packApp } from './app'; import PollVote, { deletePollVote } from './poll-vote'; import Reaction, { deleteNoteReaction } from './note-reaction'; -import { pack as packFile } from './drive-file'; +import { pack as packFile, IDriveFile } from './drive-file'; import NoteWatching, { deleteNoteWatching } from './note-watching'; import NoteReaction from './note-reaction'; import Favorite, { deleteFavorite } from './favorite'; @@ -17,24 +18,25 @@ const Note = db.get<INote>('notes'); Note.createIndex('uri', { sparse: true, unique: true }); Note.createIndex('userId'); Note.createIndex('tagsLower'); +Note.createIndex('_files.contentType'); Note.createIndex({ createdAt: -1 }); export default Note; export function isValidText(text: string): boolean { - return text.length <= 1000 && text.trim() != ''; + return length(text.trim()) <= 1000 && text.trim() != ''; } export function isValidCw(text: string): boolean { - return text.length <= 100; + return length(text.trim()) <= 100; } export type INote = { _id: mongo.ObjectID; createdAt: Date; deletedAt: Date; - mediaIds: mongo.ObjectID[]; + fileIds: mongo.ObjectID[]; replyId: mongo.ObjectID; renoteId: mongo.ObjectID; poll: { @@ -92,6 +94,7 @@ export type INote = { inbox?: string; }; _replyIds?: mongo.ObjectID[]; + _files?: IDriveFile[]; }; /** @@ -160,6 +163,66 @@ export async function deleteNote(note: string | mongo.ObjectID | INote) { console.log(`Note: deleted ${n._id}`); } +export const hideNote = async (packedNote: any, meId: mongo.ObjectID) => { + let hide = false; + + // visibility が private かつ投稿者のIDが自分のIDではなかったら非表示 + if (packedNote.visibility == 'private' && (meId == null || !meId.equals(packedNote.userId))) { + hide = true; + } + + // visibility が specified かつ自分が指定されていなかったら非表示 + if (packedNote.visibility == 'specified') { + if (meId == null) { + hide = true; + } else if (meId.equals(packedNote.userId)) { + hide = false; + } else { + // 指定されているかどうか + const specified = packedNote.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId)); + + if (specified) { + hide = false; + } else { + hide = true; + } + } + } + + // visibility が followers かつ自分が投稿者のフォロワーでなかったら非表示 + if (packedNote.visibility == 'followers') { + if (meId == null) { + hide = true; + } else if (meId.equals(packedNote.userId)) { + hide = false; + } else { + // フォロワーかどうか + const following = await Following.findOne({ + followeeId: packedNote.userId, + followerId: meId + }); + + if (following == null) { + hide = true; + } else { + hide = false; + } + } + } + + if (hide) { + packedNote.fileIds = []; + packedNote.files = []; + packedNote.text = null; + packedNote.poll = null; + packedNote.cw = null; + packedNote.tags = []; + packedNote.tagsLower = []; + packedNote.geo = null; + packedNote.isHidden = true; + } +}; + /** * Pack a note for API response * @@ -172,11 +235,13 @@ export const pack = async ( note: string | mongo.ObjectID | INote, me?: string | mongo.ObjectID | IUser, options?: { - detail: boolean + detail?: boolean; + skipHide?: boolean; } ) => { const opts = Object.assign({ - detail: true + detail: true, + skipHide: false }, options); // Me @@ -205,52 +270,6 @@ export const pack = async ( if (!_note) throw `invalid note arg ${note}`; - let hide = false; - - // visibility が private かつ投稿者のIDが自分のIDではなかったら非表示 - if (_note.visibility == 'private' && (meId == null || !meId.equals(_note.userId))) { - hide = true; - } - - // visibility が specified かつ自分が指定されていなかったら非表示 - if (_note.visibility == 'specified') { - if (meId == null) { - hide = true; - } else if (meId.equals(_note.userId)) { - hide = false; - } else { - // 指定されているかどうか - const specified = _note.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId)); - - if (specified) { - hide = false; - } else { - hide = true; - } - } - } - - // visibility が followers かつ自分が投稿者のフォロワーでなかったら非表示 - if (_note.visibility == 'followers') { - if (meId == null) { - hide = true; - } else if (meId.equals(_note.userId)) { - hide = false; - } else { - // フォロワーかどうか - const following = await Following.findOne({ - followeeId: _note.userId, - followerId: meId - }); - - if (following == null) { - hide = true; - } else { - hide = false; - } - } - } - const id = _note._id; // Rename _id to id @@ -271,11 +290,15 @@ export const pack = async ( _note.app = packApp(_note.appId); } - // Populate media - _note.media = hide ? [] : Promise.all(_note.mediaIds.map((fileId: mongo.ObjectID) => + // Populate files + _note.files = Promise.all(_note.fileIds.map((fileId: mongo.ObjectID) => packFile(fileId) )); + // 後方互換性のため + _note.mediaIds = _note.fileIds; + _note.media = _note.files; + // When requested a detailed note data if (opts.detail) { //#region 重いので廃止 @@ -298,7 +321,7 @@ export const pack = async ( } // Poll - if (meId && _note.poll && !hide) { + if (meId && _note.poll) { _note.poll = (async poll => { const vote = await PollVote .findOne({ @@ -343,15 +366,8 @@ export const pack = async ( _note.text = _note.text.replace(/な/g, 'にゃ').replace(/ナ/g, 'ニャ').replace(/ナ/g, 'ニャ'); } - if (hide) { - _note.mediaIds = []; - _note.text = null; - _note.poll = null; - _note.cw = null; - _note.tags = []; - _note.tagsLower = []; - _note.geo = null; - _note.isHidden = true; + if (!opts.skipHide) { + await hideNote(_note, meId); } return _note; diff --git a/src/models/stats.ts b/src/models/stats.ts index d496f2c480..c4c838caeb 100644 --- a/src/models/stats.ts +++ b/src/models/stats.ts @@ -204,4 +204,30 @@ export interface IStats { decSize: number; }; }; + + /** + * ネットワークに関する統計 + */ + network: { + /** + * サーバーへのリクエスト数 + */ + requests: number; + + /** + * 応答時間の合計 + * TIP: (totalTime / requests) でひとつのリクエストに平均でどれくらいの時間がかかったか知れる + */ + totalTime: number; + + /** + * 合計受信データ量 + */ + incomingBytes: number; + + /** + * 合計送信データ量 + */ + outgoingBytes: number; + }; } diff --git a/src/models/user.ts b/src/models/user.ts index 8f3fbbdc8f..64197c91c2 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -102,7 +102,10 @@ export interface ILocalUser extends IUserBase { twoFactorEnabled: boolean; twoFactorTempSecret?: string; clientSettings: any; - settings: any; + settings: { + autoWatch: boolean; + alwaysMarkNsfw?: boolean; + }; hasUnreadNotification: boolean; hasUnreadMessagingMessage: boolean; } |