From e66d7babc5ae477d7a60628e5599f9c390426c81 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 18 Jun 2018 14:28:43 +0900 Subject: [PATCH] yatta --- src/acct/render.ts | 2 +- src/build/i18n.ts | 2 +- src/models/note.ts | 4 ++-- src/models/user.ts | 2 +- src/parse-opt.ts | 2 +- src/publishers/push-sw.ts | 4 ++-- src/queue/index.ts | 4 ++-- src/queue/processors/http/deliver.ts | 2 +- src/queue/processors/http/index.ts | 4 ++-- src/queue/processors/http/process-inbox.ts | 8 +++---- src/remote/activitypub/kernel/accept/index.ts | 4 ++-- .../activitypub/kernel/announce/index.ts | 4 ++-- .../activitypub/kernel/announce/note.ts | 4 ++-- src/remote/activitypub/kernel/create/image.ts | 2 +- src/remote/activitypub/kernel/create/note.ts | 2 +- src/remote/activitypub/kernel/delete/index.ts | 3 ++- src/remote/activitypub/kernel/reject/index.ts | 4 ++-- src/remote/activitypub/kernel/undo/index.ts | 4 ++-- src/remote/activitypub/misc/get-note-html.ts | 2 +- src/remote/activitypub/models/image.ts | 2 +- src/remote/activitypub/models/note.ts | 24 +++++++++---------- src/remote/activitypub/renderer/accept.ts | 2 +- src/remote/activitypub/renderer/announce.ts | 2 +- src/remote/activitypub/renderer/create.ts | 2 +- src/remote/activitypub/renderer/delete.ts | 2 +- src/remote/activitypub/renderer/document.ts | 7 +++--- src/remote/activitypub/renderer/image.ts | 5 ++-- src/remote/activitypub/renderer/like.ts | 3 ++- src/remote/activitypub/renderer/mention.ts | 4 ++-- src/remote/activitypub/renderer/note.ts | 6 ++--- src/remote/activitypub/renderer/person.ts | 4 ++-- src/remote/activitypub/renderer/undo.ts | 2 +- src/remote/activitypub/resolver.ts | 4 ++-- src/remote/resolve-user.ts | 2 +- src/server/api/endpoints/aggregation/posts.ts | 10 ++++---- .../endpoints/drive/files/upload_from_url.ts | 3 ++- src/server/api/endpoints/drive/folders.ts | 6 ++--- src/services/drive/delete-file.ts | 2 +- src/services/drive/upload-from-url.ts | 2 +- src/services/following/requests/accept-all.ts | 4 ++-- src/services/following/requests/accept.ts | 10 ++++---- src/services/following/requests/cancel.ts | 4 ++-- src/services/following/requests/reject.ts | 4 ++-- src/text/html.ts | 2 +- src/text/parse/elements/bold.ts | 2 +- src/text/parse/elements/code.ts | 2 +- src/text/parse/elements/emoji.ts | 2 +- src/text/parse/elements/hashtag.ts | 2 +- src/text/parse/elements/inline-code.ts | 2 +- src/text/parse/elements/link.ts | 2 +- src/text/parse/elements/mention.ts | 2 +- src/text/parse/elements/quote.ts | 2 +- src/text/parse/elements/search.ts | 2 +- src/text/parse/elements/title.ts | 2 +- src/text/parse/elements/url.ts | 2 +- src/text/parse/index.ts | 24 +++++++++---------- 56 files changed, 115 insertions(+), 112 deletions(-) diff --git a/src/acct/render.ts b/src/acct/render.ts index 191034361..c29bfb476 100644 --- a/src/acct/render.ts +++ b/src/acct/render.ts @@ -1,4 +1,4 @@ -import { IUser } from "../models/user"; +import { IUser } from '../models/user'; export default (user: IUser) => { return user.host === null ? user.username : `${user.username}@${user.host}`; diff --git a/src/build/i18n.ts b/src/build/i18n.ts index f7602dfd1..dc48251c9 100644 --- a/src/build/i18n.ts +++ b/src/build/i18n.ts @@ -48,7 +48,7 @@ export default class Replacer { if (error) { console.warn(`key '${key}' not found in '${path}' of '${this.lang}'`); return key; // Fallback - } else if (typeof text !== "string") { + } else if (typeof text !== 'string') { console.warn(`key '${key}' is not string in '${path}' of '${this.lang}'`); return key; // Fallback } else { diff --git a/src/models/note.ts b/src/models/note.ts index 83cd93353..af6f6f7c0 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -220,7 +220,7 @@ export const pack = async ( hide = false; } else { // 指定されているかどうか - const specified = _note.visibleUserIds.some(id => id.equals(meId)); + const specified = _note.visibleUserIds.some((id: mongo.ObjectID) => id.equals(meId)); if (specified) { hide = false; @@ -272,7 +272,7 @@ export const pack = async ( } // Populate media - _note.media = hide ? [] : Promise.all(_note.mediaIds.map(fileId => + _note.media = hide ? [] : Promise.all(_note.mediaIds.map((fileId: mongo.ObjectID) => packFile(fileId) )); diff --git a/src/models/user.ts b/src/models/user.ts index 942faeeff..0d1be439e 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -1,6 +1,6 @@ import * as mongo from 'mongodb'; const deepcopy = require('deepcopy'); -import sequential = require('promise-sequential'); +const sequential = require('promise-sequential'); import rap from '@prezzemolo/rap'; import db from '../db/mongodb'; import Note, { pack as packNote, deleteNote } from './note'; diff --git a/src/parse-opt.ts b/src/parse-opt.ts index 031b1a6fe..29e5959c3 100644 --- a/src/parse-opt.ts +++ b/src/parse-opt.ts @@ -1,6 +1,6 @@ import * as nopt from 'nopt'; -export default (vector, index) => { +export default (vector: any, index: any) => { const parsed = nopt({ 'only-processor': Boolean, 'only-server': Boolean diff --git a/src/publishers/push-sw.ts b/src/publishers/push-sw.ts index aab91df62..b0b470115 100644 --- a/src/publishers/push-sw.ts +++ b/src/publishers/push-sw.ts @@ -11,7 +11,7 @@ if (config.sw) { config.sw.private_key); } -export default async function(userId: mongo.ObjectID | string, type, body?) { +export default async function(userId: mongo.ObjectID | string, type: string, body?: any) { if (!config.sw) return; if (typeof userId === 'string') { @@ -34,7 +34,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) { push.sendNotification(pushSubscription, JSON.stringify({ type, body - })).catch(err => { + })).catch((err: any) => { //console.log(err.statusCode); //console.log(err.headers); //console.log(err.body); diff --git a/src/queue/index.ts b/src/queue/index.ts index 3f82b30b3..1efd6e54e 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -12,7 +12,7 @@ const queue = createQueue({ } }); -export function createHttp(data) { +export function createHttp(data: any) { return queue .create('http', data) .removeOnComplete(true) @@ -21,7 +21,7 @@ export function createHttp(data) { .backoff({ delay: 16384, type: 'exponential' }); } -export function deliver(user: ILocalUser, content, to) { +export function deliver(user: ILocalUser, content: any, to: any) { createHttp({ title: 'deliver', type: 'deliver', diff --git a/src/queue/processors/http/deliver.ts b/src/queue/processors/http/deliver.ts index 2c4bbe9bf..946d2f65b 100644 --- a/src/queue/processors/http/deliver.ts +++ b/src/queue/processors/http/deliver.ts @@ -2,7 +2,7 @@ import * as kue from 'kue'; import request from '../../../remote/activitypub/request'; -export default async (job: kue.Job, done): Promise => { +export default async (job: kue.Job, done: any): Promise => { try { await request(job.data.user, job.data.to, job.data.content); done(); diff --git a/src/queue/processors/http/index.ts b/src/queue/processors/http/index.ts index 6f8d1dbc2..156be4225 100644 --- a/src/queue/processors/http/index.ts +++ b/src/queue/processors/http/index.ts @@ -1,12 +1,12 @@ import deliver from './deliver'; import processInbox from './process-inbox'; -const handlers = { +const handlers: any = { deliver, processInbox, }; -export default (job, done) => { +export default (job: any, done: any) => { const handler = handlers[job.data.type]; if (handler) { diff --git a/src/queue/processors/http/process-inbox.ts b/src/queue/processors/http/process-inbox.ts index dfafe64a7..0da442aef 100644 --- a/src/queue/processors/http/process-inbox.ts +++ b/src/queue/processors/http/process-inbox.ts @@ -10,7 +10,7 @@ import { resolvePerson } from '../../../remote/activitypub/models/person'; const log = debug('misskey:queue:inbox'); // ユーザーのinboxにアクティビティが届いた時の処理 -export default async (job: kue.Job, done): Promise => { +export default async (job: kue.Job, done: any): Promise => { const signature = job.data.signature; const activity = job.data.activity; @@ -22,7 +22,7 @@ export default async (job: kue.Job, done): Promise => { //#endregion const keyIdLower = signature.keyId.toLowerCase(); - let user; + let user: IRemoteUser; if (keyIdLower.startsWith('acct:')) { const { username, host } = parseAcct(keyIdLower.slice('acct:'.length)); @@ -36,7 +36,7 @@ export default async (job: kue.Job, done): Promise => { // アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する if (user === null) { - user = await resolvePerson(activity.actor); + user = await resolvePerson(activity.actor) as IRemoteUser; } } else { user = await User.findOne({ @@ -46,7 +46,7 @@ export default async (job: kue.Job, done): Promise => { // アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する if (user === null) { - user = await resolvePerson(signature.keyId); + user = await resolvePerson(signature.keyId) as IRemoteUser; } } diff --git a/src/remote/activitypub/kernel/accept/index.ts b/src/remote/activitypub/kernel/accept/index.ts index 2f9d646d1..572a254d9 100644 --- a/src/remote/activitypub/kernel/accept/index.ts +++ b/src/remote/activitypub/kernel/accept/index.ts @@ -3,7 +3,7 @@ import * as debug from 'debug'; import Resolver from '../../resolver'; import { IRemoteUser } from '../../../../models/user'; import acceptFollow from './follow'; -import { IAccept } from '../../type'; +import { IAccept, IFollow } from '../../type'; const log = debug('misskey:activitypub'); @@ -25,7 +25,7 @@ export default async (actor: IRemoteUser, activity: IAccept): Promise => { switch (object.type) { case 'Follow': - acceptFollow(actor, object); + acceptFollow(actor, object as IFollow); break; default: diff --git a/src/remote/activitypub/kernel/announce/index.ts b/src/remote/activitypub/kernel/announce/index.ts index a2cf2d576..612b5dee8 100644 --- a/src/remote/activitypub/kernel/announce/index.ts +++ b/src/remote/activitypub/kernel/announce/index.ts @@ -3,7 +3,7 @@ import * as debug from 'debug'; import Resolver from '../../resolver'; import { IRemoteUser } from '../../../../models/user'; import announceNote from './note'; -import { IAnnounce } from '../../type'; +import { IAnnounce, INote } from '../../type'; const log = debug('misskey:activitypub'); @@ -25,7 +25,7 @@ export default async (actor: IRemoteUser, activity: IAnnounce): Promise => switch (object.type) { case 'Note': - announceNote(resolver, actor, activity, object); + announceNote(resolver, actor, activity, object as INote); break; default: diff --git a/src/remote/activitypub/kernel/announce/note.ts b/src/remote/activitypub/kernel/announce/note.ts index e25856738..7aa6aa570 100644 --- a/src/remote/activitypub/kernel/announce/note.ts +++ b/src/remote/activitypub/kernel/announce/note.ts @@ -2,7 +2,7 @@ import * as debug from 'debug'; import Resolver from '../../resolver'; import post from '../../../../services/note/create'; -import { IRemoteUser } from '../../../../models/user'; +import { IRemoteUser, IUser } from '../../../../models/user'; import { IAnnounce, INote } from '../../type'; import { fetchNote, resolveNote } from '../../models/note'; import { resolvePerson } from '../../models/person'; @@ -36,7 +36,7 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity: //#region Visibility let visibility = 'public'; - let visibleUsers = []; + let visibleUsers: IUser[] = []; if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) { if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) { visibility = 'home'; diff --git a/src/remote/activitypub/kernel/create/image.ts b/src/remote/activitypub/kernel/create/image.ts index 2a5552222..9c19abbcc 100644 --- a/src/remote/activitypub/kernel/create/image.ts +++ b/src/remote/activitypub/kernel/create/image.ts @@ -1,6 +1,6 @@ import { IRemoteUser } from '../../../../models/user'; import { createImage } from '../../models/image'; -export default async function(actor: IRemoteUser, image): Promise { +export default async function(actor: IRemoteUser, image: any): Promise { await createImage(image.url, actor); } diff --git a/src/remote/activitypub/kernel/create/note.ts b/src/remote/activitypub/kernel/create/note.ts index ed9fb6e54..0f874b9fb 100644 --- a/src/remote/activitypub/kernel/create/note.ts +++ b/src/remote/activitypub/kernel/create/note.ts @@ -5,7 +5,7 @@ import { createNote, fetchNote } from '../../models/note'; /** * 投稿作成アクティビティを捌きます */ -export default async function(resolver: Resolver, actor: IRemoteUser, note, silent = false): Promise { +export default async function(resolver: Resolver, actor: IRemoteUser, note: any, silent = false): Promise { const exist = await fetchNote(note); if (exist == null) { await createNote(note); diff --git a/src/remote/activitypub/kernel/delete/index.ts b/src/remote/activitypub/kernel/delete/index.ts index 10b47dc4c..5d7a23584 100644 --- a/src/remote/activitypub/kernel/delete/index.ts +++ b/src/remote/activitypub/kernel/delete/index.ts @@ -2,11 +2,12 @@ import Resolver from '../../resolver'; import deleteNote from './note'; import Note from '../../../../models/note'; import { IRemoteUser } from '../../../../models/user'; +import { IDelete } from '../../type'; /** * 削除アクティビティを捌きます */ -export default async (actor: IRemoteUser, activity): Promise => { +export default async (actor: IRemoteUser, activity: IDelete): Promise => { if ('actor' in activity && actor.uri !== activity.actor) { throw new Error('invalid actor'); } diff --git a/src/remote/activitypub/kernel/reject/index.ts b/src/remote/activitypub/kernel/reject/index.ts index a82c3fd61..d89985c23 100644 --- a/src/remote/activitypub/kernel/reject/index.ts +++ b/src/remote/activitypub/kernel/reject/index.ts @@ -3,7 +3,7 @@ import * as debug from 'debug'; import Resolver from '../../resolver'; import { IRemoteUser } from '../../../../models/user'; import rejectFollow from './follow'; -import { IReject } from '../../type'; +import { IReject, IFollow } from '../../type'; const log = debug('misskey:activitypub'); @@ -25,7 +25,7 @@ export default async (actor: IRemoteUser, activity: IReject): Promise => { switch (object.type) { case 'Follow': - rejectFollow(actor, object); + rejectFollow(actor, object as IFollow); break; default: diff --git a/src/remote/activitypub/kernel/undo/index.ts b/src/remote/activitypub/kernel/undo/index.ts index 71f547aeb..5d9535403 100644 --- a/src/remote/activitypub/kernel/undo/index.ts +++ b/src/remote/activitypub/kernel/undo/index.ts @@ -1,7 +1,7 @@ import * as debug from 'debug'; import { IRemoteUser } from '../../../../models/user'; -import { IUndo } from '../../type'; +import { IUndo, IFollow } from '../../type'; import unfollow from './follow'; import Resolver from '../../resolver'; @@ -29,7 +29,7 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise => { switch (object.type) { case 'Follow': - unfollow(actor, object); + unfollow(actor, object as IFollow); break; } diff --git a/src/remote/activitypub/misc/get-note-html.ts b/src/remote/activitypub/misc/get-note-html.ts index 33dd38168..0ceecdd00 100644 --- a/src/remote/activitypub/misc/get-note-html.ts +++ b/src/remote/activitypub/misc/get-note-html.ts @@ -1,4 +1,4 @@ -import { INote } from "../../../models/note"; +import { INote } from '../../../models/note'; import toHtml from '../../../text/html'; import parse from '../../../text/parse'; import config from '../../../config'; diff --git a/src/remote/activitypub/models/image.ts b/src/remote/activitypub/models/image.ts index 0d5a690c6..fb17a7c9e 100644 --- a/src/remote/activitypub/models/image.ts +++ b/src/remote/activitypub/models/image.ts @@ -10,7 +10,7 @@ const log = debug('misskey:activitypub'); /** * Imageを作成します。 */ -export async function createImage(actor: IRemoteUser, value): Promise { +export async function createImage(actor: IRemoteUser, value: any): Promise { // 投稿者が凍結されていたらスキップ if (actor.isSuspended) { return null; diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 974fce433..b0fe045e6 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import * as parse5 from 'parse5'; +const parse5 = require('parse5'); import * as debug from 'debug'; import config from '../../../config'; @@ -9,30 +9,30 @@ import post from '../../../services/note/create'; import { INote as INoteActivityStreamsObject, IObject } from '../type'; import { resolvePerson, updatePerson } from './person'; import { resolveImage } from './image'; -import { IRemoteUser } from '../../../models/user'; +import { IRemoteUser, IUser } from '../../../models/user'; const log = debug('misskey:activitypub'); function parse(html: string): string { - const dom = parse5.parseFragment(html) as parse5.AST.Default.Document; + const dom = parse5.parseFragment(html); let text = ''; - dom.childNodes.forEach(n => analyze(n)); + dom.childNodes.forEach((n: any) => analyze(n)); return text.trim(); - function getText(node) { + function getText(node: any) { if (node.nodeName == '#text') return node.value; if (node.childNodes) { - return node.childNodes.map(n => getText(n)).join(''); + return node.childNodes.map((n: any) => getText(n)).join(''); } return ''; } - function analyze(node) { + function analyze(node: any) { switch (node.nodeName) { case '#text': text += node.value; @@ -51,7 +51,7 @@ function parse(html: string): string { if (part.length == 2) { //#region ホスト名部分が省略されているので復元する - const href = new URL(node.attrs.find(x => x.name == 'href').value); + const href = new URL(node.attrs.find((x: any) => x.name == 'href').value); const acct = txt + '@' + href.hostname; text += acct; break; @@ -63,20 +63,20 @@ function parse(html: string): string { } if (node.childNodes) { - node.childNodes.forEach(n => analyze(n)); + node.childNodes.forEach((n: any) => analyze(n)); } break; case 'p': text += '\n\n'; if (node.childNodes) { - node.childNodes.forEach(n => analyze(n)); + node.childNodes.forEach((n: any) => analyze(n)); } break; default: if (node.childNodes) { - node.childNodes.forEach(n => analyze(n)); + node.childNodes.forEach((n: any) => analyze(n)); } break; } @@ -135,7 +135,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false //#region Visibility let visibility = 'public'; - let visibleUsers = []; + let visibleUsers: IUser[] = []; if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) { if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) { visibility = 'home'; diff --git a/src/remote/activitypub/renderer/accept.ts b/src/remote/activitypub/renderer/accept.ts index 00c76883a..76326285f 100644 --- a/src/remote/activitypub/renderer/accept.ts +++ b/src/remote/activitypub/renderer/accept.ts @@ -1,4 +1,4 @@ -export default object => ({ +export default (object: any) => ({ type: 'Accept', object }); diff --git a/src/remote/activitypub/renderer/announce.ts b/src/remote/activitypub/renderer/announce.ts index 8e4b3d26a..8c3ff9f11 100644 --- a/src/remote/activitypub/renderer/announce.ts +++ b/src/remote/activitypub/renderer/announce.ts @@ -1,4 +1,4 @@ -export default object => ({ +export default (object: any) => ({ type: 'Announce', object }); diff --git a/src/remote/activitypub/renderer/create.ts b/src/remote/activitypub/renderer/create.ts index de411e195..b8bf98a65 100644 --- a/src/remote/activitypub/renderer/create.ts +++ b/src/remote/activitypub/renderer/create.ts @@ -1,4 +1,4 @@ -export default object => ({ +export default (object: any) => ({ type: 'Create', object }); diff --git a/src/remote/activitypub/renderer/delete.ts b/src/remote/activitypub/renderer/delete.ts index d15cb447e..f468a22e2 100644 --- a/src/remote/activitypub/renderer/delete.ts +++ b/src/remote/activitypub/renderer/delete.ts @@ -1,4 +1,4 @@ -export default object => ({ +export default (object: any) => ({ type: 'Delete', object }); diff --git a/src/remote/activitypub/renderer/document.ts b/src/remote/activitypub/renderer/document.ts index 91a9f7df3..1985c6bc8 100644 --- a/src/remote/activitypub/renderer/document.ts +++ b/src/remote/activitypub/renderer/document.ts @@ -1,7 +1,8 @@ import config from '../../../config'; +import { IDriveFile } from '../../../models/drive-file'; -export default ({ _id, contentType }) => ({ +export default (file: IDriveFile) => ({ type: 'Document', - mediaType: contentType, - url: `${config.drive_url}/${_id}` + mediaType: file.contentType, + url: `${config.drive_url}/${file._id}` }); diff --git a/src/remote/activitypub/renderer/image.ts b/src/remote/activitypub/renderer/image.ts index d671a57e7..cf91ce3a0 100644 --- a/src/remote/activitypub/renderer/image.ts +++ b/src/remote/activitypub/renderer/image.ts @@ -1,6 +1,7 @@ import config from '../../../config'; +import { IDriveFile } from '../../../models/drive-file'; -export default ({ _id }) => ({ +export default (fileId: IDriveFile['_id']) => ({ type: 'Image', - url: `${config.drive_url}/${_id}` + url: `${config.drive_url}/${fileId}` }); diff --git a/src/remote/activitypub/renderer/like.ts b/src/remote/activitypub/renderer/like.ts index 33e1341a2..523cb4f1a 100644 --- a/src/remote/activitypub/renderer/like.ts +++ b/src/remote/activitypub/renderer/like.ts @@ -1,7 +1,8 @@ import config from '../../../config'; import { ILocalUser } from '../../../models/user'; +import { INote } from '../../../models/note'; -export default (user: ILocalUser, note, reaction: string) => ({ +export default (user: ILocalUser, note: INote, reaction: string) => ({ type: 'Like', actor: `${config.url}/users/${user._id}`, object: note.uri ? note.uri : `${config.url}/notes/${note._id}`, diff --git a/src/remote/activitypub/renderer/mention.ts b/src/remote/activitypub/renderer/mention.ts index 95cae52aa..8d12e6d8b 100644 --- a/src/remote/activitypub/renderer/mention.ts +++ b/src/remote/activitypub/renderer/mention.ts @@ -1,5 +1,5 @@ -import { IUser, isRemoteUser } from "../../../models/user"; -import config from "../../../config"; +import { IUser, isRemoteUser } from '../../../models/user'; +import config from '../../../config'; export default (mention: IUser) => ({ type: 'Mention', diff --git a/src/remote/activitypub/renderer/note.ts b/src/remote/activitypub/renderer/note.ts index 556054fa9..b908f8bb1 100644 --- a/src/remote/activitypub/renderer/note.ts +++ b/src/remote/activitypub/renderer/note.ts @@ -2,13 +2,13 @@ import renderDocument from './document'; import renderHashtag from './hashtag'; import renderMention from './mention'; import config from '../../../config'; -import DriveFile from '../../../models/drive-file'; +import DriveFile, { IDriveFile } from '../../../models/drive-file'; import Note, { INote } from '../../../models/note'; import User from '../../../models/user'; import toHtml from '../misc/get-note-html'; -export default async function renderNote(note: INote, dive = true) { - const promisedFiles = note.mediaIds +export default async function renderNote(note: INote, dive = true): Promise { + const promisedFiles: Promise = note.mediaIds ? DriveFile.find({ _id: { $in: note.mediaIds } }) : Promise.resolve([]); diff --git a/src/remote/activitypub/renderer/person.ts b/src/remote/activitypub/renderer/person.ts index b2ac885f4..8825c56c2 100644 --- a/src/remote/activitypub/renderer/person.ts +++ b/src/remote/activitypub/renderer/person.ts @@ -16,8 +16,8 @@ export default (user: ILocalUser) => { preferredUsername: user.username, name: user.name, summary: user.description, - icon: user.avatarId && renderImage({ _id: user.avatarId }), - image: user.bannerId && renderImage({ _id: user.bannerId }), + icon: user.avatarId && renderImage(user.avatarId), + image: user.bannerId && renderImage(user.bannerId), manuallyApprovesFollowers: user.isLocked, publicKey: renderKey(user) }; diff --git a/src/remote/activitypub/renderer/undo.ts b/src/remote/activitypub/renderer/undo.ts index f38e224b6..4498409a5 100644 --- a/src/remote/activitypub/renderer/undo.ts +++ b/src/remote/activitypub/renderer/undo.ts @@ -1,4 +1,4 @@ -export default object => ({ +export default (object: any) => ({ type: 'Undo', object }); diff --git a/src/remote/activitypub/resolver.ts b/src/remote/activitypub/resolver.ts index f405ff10c..0b053ca77 100644 --- a/src/remote/activitypub/resolver.ts +++ b/src/remote/activitypub/resolver.ts @@ -12,7 +12,7 @@ export default class Resolver { this.history = new Set(); } - public async resolveCollection(value) { + public async resolveCollection(value: any) { const collection = typeof value === 'string' ? await this.resolve(value) : value; @@ -33,7 +33,7 @@ export default class Resolver { return collection; } - public async resolve(value): Promise { + public async resolve(value: any): Promise { if (value == null) { throw new Error('resolvee is null (or undefined)'); } diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts index c612a8c94..1e8fc5d75 100644 --- a/src/remote/resolve-user.ts +++ b/src/remote/resolve-user.ts @@ -4,7 +4,7 @@ import webFinger from './webfinger'; import config from '../config'; import { createPerson } from './activitypub/models/person'; -export default async (username, _host, option?): Promise => { +export default async (username: string, _host: string, option?: any): Promise => { const usernameLower = username.toLowerCase(); if (_host == null) { diff --git a/src/server/api/endpoints/aggregation/posts.ts b/src/server/api/endpoints/aggregation/posts.ts index 9ada9cd3f..48e344312 100644 --- a/src/server/api/endpoints/aggregation/posts.ts +++ b/src/server/api/endpoints/aggregation/posts.ts @@ -49,13 +49,13 @@ module.exports = (params: any) => new Promise(async (res, rej) => { } } ]); - datas.forEach(data => { + datas.forEach((data: any) => { data.date = data._id; delete data._id; - data.notes = (data.data.filter(x => x.type == 'note')[0] || { count: 0 }).count; - data.renotes = (data.data.filter(x => x.type == 'renote')[0] || { count: 0 }).count; - data.replies = (data.data.filter(x => x.type == 'reply')[0] || { count: 0 }).count; + 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; }); @@ -65,7 +65,7 @@ module.exports = (params: any) => new Promise(async (res, rej) => { for (let i = 0; i < limit; i++) { const day = new Date(new Date().setDate(new Date().getDate() - i)); - const data = datas.filter(d => + const data = datas.filter((d: any) => d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() )[0]; diff --git a/src/server/api/endpoints/drive/files/upload_from_url.ts b/src/server/api/endpoints/drive/files/upload_from_url.ts index c012f0d3c..cb617d851 100644 --- a/src/server/api/endpoints/drive/files/upload_from_url.ts +++ b/src/server/api/endpoints/drive/files/upload_from_url.ts @@ -4,11 +4,12 @@ import $ from 'cafy'; import ID from '../../../../../cafy-id'; import { pack } from '../../../../../models/drive-file'; import uploadFromUrl from '../../../../../services/drive/upload-from-url'; +import { ILocalUser } from '../../../../../models/user'; /** * Create a file from a URL */ -module.exports = async (params, user): Promise => { +module.exports = async (params: any, user: ILocalUser): Promise => { // Get 'url' parameter // TODO: Validate this url const [url, urlErr] = $.str.get(params.url); diff --git a/src/server/api/endpoints/drive/folders.ts b/src/server/api/endpoints/drive/folders.ts index fac978032..341377895 100644 --- a/src/server/api/endpoints/drive/folders.ts +++ b/src/server/api/endpoints/drive/folders.ts @@ -1,13 +1,11 @@ -/** - * Module dependencies - */ import $ from 'cafy'; import ID from '../../../../cafy-id'; import DriveFolder, { pack } from '../../../../models/drive-folder'; +import { ILocalUser } from '../../../../models/user'; /** * Get drive folders */ -module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { +module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/services/drive/delete-file.ts b/src/services/drive/delete-file.ts index a8ed13bd7..4ac60439b 100644 --- a/src/services/drive/delete-file.ts +++ b/src/services/drive/delete-file.ts @@ -1,4 +1,4 @@ -import DriveFile, { DriveFileChunk, IDriveFile } from "../../models/drive-file"; +import DriveFile, { DriveFileChunk, IDriveFile } from '../../models/drive-file'; import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-file-thumbnail'; export default async function(file: IDriveFile, isExpired = false) { diff --git a/src/services/drive/upload-from-url.ts b/src/services/drive/upload-from-url.ts index f83d57d41..73d9b1123 100644 --- a/src/services/drive/upload-from-url.ts +++ b/src/services/drive/upload-from-url.ts @@ -9,7 +9,7 @@ import { IDriveFile, validateFileName } from '../../models/drive-file'; import create from './add-file'; import config from '../../config'; import { IUser } from '../../models/user'; -import * as mongodb from "mongodb"; +import * as mongodb from 'mongodb'; const log = debug('misskey:drive:upload-from-url'); diff --git a/src/services/following/requests/accept-all.ts b/src/services/following/requests/accept-all.ts index 9708d9e65..45da00498 100644 --- a/src/services/following/requests/accept-all.ts +++ b/src/services/following/requests/accept-all.ts @@ -1,5 +1,5 @@ -import User, { IUser } from "../../../models/user"; -import FollowRequest from "../../../models/follow-request"; +import User, { IUser } from '../../../models/user'; +import FollowRequest from '../../../models/follow-request'; import accept from './accept'; /** diff --git a/src/services/following/requests/accept.ts b/src/services/following/requests/accept.ts index 1b89cdb98..2eaccbbd3 100644 --- a/src/services/following/requests/accept.ts +++ b/src/services/following/requests/accept.ts @@ -1,12 +1,12 @@ -import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from "../../../models/user"; -import FollowRequest from "../../../models/follow-request"; +import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from '../../../models/user'; +import FollowRequest from '../../../models/follow-request'; import pack from '../../../remote/activitypub/renderer'; import renderFollow from '../../../remote/activitypub/renderer/follow'; import renderAccept from '../../../remote/activitypub/renderer/accept'; import { deliver } from '../../../queue'; -import Following from "../../../models/following"; -import FollowingLog from "../../../models/following-log"; -import FollowedLog from "../../../models/followed-log"; +import Following from '../../../models/following'; +import FollowingLog from '../../../models/following-log'; +import FollowedLog from '../../../models/followed-log'; import event from '../../../publishers/stream'; export default async function(followee: IUser, follower: IUser) { diff --git a/src/services/following/requests/cancel.ts b/src/services/following/requests/cancel.ts index 50c95de0e..7e9dc5630 100644 --- a/src/services/following/requests/cancel.ts +++ b/src/services/following/requests/cancel.ts @@ -1,5 +1,5 @@ -import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from "../../../models/user"; -import FollowRequest from "../../../models/follow-request"; +import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from '../../../models/user'; +import FollowRequest from '../../../models/follow-request'; import pack from '../../../remote/activitypub/renderer'; import renderFollow from '../../../remote/activitypub/renderer/follow'; import renderUndo from '../../../remote/activitypub/renderer/undo'; diff --git a/src/services/following/requests/reject.ts b/src/services/following/requests/reject.ts index acd419d0e..affcd2ef5 100644 --- a/src/services/following/requests/reject.ts +++ b/src/services/following/requests/reject.ts @@ -1,5 +1,5 @@ -import User, { IUser, isRemoteUser, ILocalUser } from "../../../models/user"; -import FollowRequest from "../../../models/follow-request"; +import User, { IUser, isRemoteUser, ILocalUser } from '../../../models/user'; +import FollowRequest from '../../../models/follow-request'; import pack from '../../../remote/activitypub/renderer'; import renderFollow from '../../../remote/activitypub/renderer/follow'; import renderReject from '../../../remote/activitypub/renderer/reject'; diff --git a/src/text/html.ts b/src/text/html.ts index 41adb2e7f..64208af88 100644 --- a/src/text/html.ts +++ b/src/text/html.ts @@ -4,7 +4,7 @@ import config from '../config'; import { INote } from '../models/note'; import { TextElement } from './parse'; -const handlers: {[key: string]: (window: any, token: any, mentionedRemoteUsers: INote["mentionedRemoteUsers"]) => void} = { +const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: INote['mentionedRemoteUsers']) => void } = { bold({ document }, { bold }) { const b = document.createElement('b'); b.textContent = bold; diff --git a/src/text/parse/elements/bold.ts b/src/text/parse/elements/bold.ts index 0566ace8b..cf615cd3c 100644 --- a/src/text/parse/elements/bold.ts +++ b/src/text/parse/elements/bold.ts @@ -3,7 +3,7 @@ */ export type TextElementBold = { - type: "bold" + type: 'bold' content: string bold: string }; diff --git a/src/text/parse/elements/code.ts b/src/text/parse/elements/code.ts index de87aa410..f48e94504 100644 --- a/src/text/parse/elements/code.ts +++ b/src/text/parse/elements/code.ts @@ -5,7 +5,7 @@ import genHtml from '../core/syntax-highlighter'; export type TextElementCode = { - type: "code" + type: 'code' content: string code: string html: string diff --git a/src/text/parse/elements/emoji.ts b/src/text/parse/elements/emoji.ts index d0eed8896..83d3effef 100644 --- a/src/text/parse/elements/emoji.ts +++ b/src/text/parse/elements/emoji.ts @@ -3,7 +3,7 @@ */ export type TextElementEmoji = { - type: "emoji" + type: 'emoji' content: string emoji: string }; diff --git a/src/text/parse/elements/hashtag.ts b/src/text/parse/elements/hashtag.ts index cde0c2b22..129041774 100644 --- a/src/text/parse/elements/hashtag.ts +++ b/src/text/parse/elements/hashtag.ts @@ -3,7 +3,7 @@ */ export type TextElementHashtag = { - type: "hashtag" + type: 'hashtag' content: string hashtag: string }; diff --git a/src/text/parse/elements/inline-code.ts b/src/text/parse/elements/inline-code.ts index bcb0bca0a..1dd5affa5 100644 --- a/src/text/parse/elements/inline-code.ts +++ b/src/text/parse/elements/inline-code.ts @@ -5,7 +5,7 @@ import genHtml from '../core/syntax-highlighter'; export type TextElementInlineCode = { - type: "inline-code" + type: 'inline-code' content: string code: string html: string diff --git a/src/text/parse/elements/link.ts b/src/text/parse/elements/link.ts index 7e0d6f5cf..b353aebc5 100644 --- a/src/text/parse/elements/link.ts +++ b/src/text/parse/elements/link.ts @@ -3,7 +3,7 @@ */ export type TextElementLink = { - type: "link" + type: 'link' content: string title: string url: string diff --git a/src/text/parse/elements/mention.ts b/src/text/parse/elements/mention.ts index a4140458d..eda60b530 100644 --- a/src/text/parse/elements/mention.ts +++ b/src/text/parse/elements/mention.ts @@ -4,7 +4,7 @@ import parseAcct from '../../../acct/parse'; export type TextElementMention = { - type: "mention" + type: 'mention' content: string username: string host: string diff --git a/src/text/parse/elements/quote.ts b/src/text/parse/elements/quote.ts index 56de561f3..bef9ad498 100644 --- a/src/text/parse/elements/quote.ts +++ b/src/text/parse/elements/quote.ts @@ -3,7 +3,7 @@ */ export type TextElementQuote = { - type: "quote" + type: 'quote' content: string quote: string }; diff --git a/src/text/parse/elements/search.ts b/src/text/parse/elements/search.ts index 4bd19ee3f..e5d9b9f0c 100644 --- a/src/text/parse/elements/search.ts +++ b/src/text/parse/elements/search.ts @@ -3,7 +3,7 @@ */ export type TextElementSearch = { - type: "search" + type: 'search' content: string query: string }; diff --git a/src/text/parse/elements/title.ts b/src/text/parse/elements/title.ts index 11b3abc61..b89739a7c 100644 --- a/src/text/parse/elements/title.ts +++ b/src/text/parse/elements/title.ts @@ -3,7 +3,7 @@ */ export type TextElementTitle = { - type: "title" + type: 'title' content: string title: string }; diff --git a/src/text/parse/elements/url.ts b/src/text/parse/elements/url.ts index bbc27b4fd..78b9b1f2f 100644 --- a/src/text/parse/elements/url.ts +++ b/src/text/parse/elements/url.ts @@ -3,7 +3,7 @@ */ export type TextElementUrl = { - type: "url" + type: 'url' content: string url: string }; diff --git a/src/text/parse/index.ts b/src/text/parse/index.ts index ccfef4459..2b6a459b1 100644 --- a/src/text/parse/index.ts +++ b/src/text/parse/index.ts @@ -2,17 +2,17 @@ * Misskey Text Analyzer */ -import { TextElementBold } from "./elements/bold"; -import { TextElementCode } from "./elements/code"; -import { TextElementEmoji } from "./elements/emoji"; -import { TextElementHashtag } from "./elements/hashtag"; -import { TextElementInlineCode } from "./elements/inline-code"; -import { TextElementLink } from "./elements/link"; -import { TextElementMention } from "./elements/mention"; -import { TextElementQuote } from "./elements/quote"; -import { TextElementSearch } from "./elements/search"; -import { TextElementTitle } from "./elements/title"; -import { TextElementUrl } from "./elements/url"; +import { TextElementBold } from './elements/bold'; +import { TextElementCode } from './elements/code'; +import { TextElementEmoji } from './elements/emoji'; +import { TextElementHashtag } from './elements/hashtag'; +import { TextElementInlineCode } from './elements/inline-code'; +import { TextElementLink } from './elements/link'; +import { TextElementMention } from './elements/mention'; +import { TextElementQuote } from './elements/quote'; +import { TextElementSearch } from './elements/search'; +import { TextElementTitle } from './elements/title'; +import { TextElementUrl } from './elements/url'; const elements = [ require('./elements/bold'), @@ -28,7 +28,7 @@ const elements = [ require('./elements/search') ].map(element => element.default as TextElementProcessor); -export type TextElement = {type: "text", content: string} +export type TextElement = { type: 'text', content: string } | TextElementBold | TextElementCode | TextElementEmoji