This commit is contained in:
syuilo
2018-06-18 14:28:43 +09:00
parent 80e5645a84
commit e66d7babc5
56 changed files with 115 additions and 112 deletions

View File

@@ -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<void> => {
switch (object.type) {
case 'Follow':
acceptFollow(actor, object);
acceptFollow(actor, object as IFollow);
break;
default:

View File

@@ -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<void> =>
switch (object.type) {
case 'Note':
announceNote(resolver, actor, activity, object);
announceNote(resolver, actor, activity, object as INote);
break;
default:

View File

@@ -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';

View File

@@ -1,6 +1,6 @@
import { IRemoteUser } from '../../../../models/user';
import { createImage } from '../../models/image';
export default async function(actor: IRemoteUser, image): Promise<void> {
export default async function(actor: IRemoteUser, image: any): Promise<void> {
await createImage(image.url, actor);
}

View File

@@ -5,7 +5,7 @@ import { createNote, fetchNote } from '../../models/note';
/**
* 投稿作成アクティビティを捌きます
*/
export default async function(resolver: Resolver, actor: IRemoteUser, note, silent = false): Promise<void> {
export default async function(resolver: Resolver, actor: IRemoteUser, note: any, silent = false): Promise<void> {
const exist = await fetchNote(note);
if (exist == null) {
await createNote(note);

View File

@@ -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<void> => {
export default async (actor: IRemoteUser, activity: IDelete): Promise<void> => {
if ('actor' in activity && actor.uri !== activity.actor) {
throw new Error('invalid actor');
}

View File

@@ -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<void> => {
switch (object.type) {
case 'Follow':
rejectFollow(actor, object);
rejectFollow(actor, object as IFollow);
break;
default:

View File

@@ -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<void> => {
switch (object.type) {
case 'Follow':
unfollow(actor, object);
unfollow(actor, object as IFollow);
break;
}

View File

@@ -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';

View File

@@ -10,7 +10,7 @@ const log = debug('misskey:activitypub');
/**
* Imageを作成します。
*/
export async function createImage(actor: IRemoteUser, value): Promise<IDriveFile> {
export async function createImage(actor: IRemoteUser, value: any): Promise<IDriveFile> {
// 投稿者が凍結されていたらスキップ
if (actor.isSuspended) {
return null;

View File

@@ -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';

View File

@@ -1,4 +1,4 @@
export default object => ({
export default (object: any) => ({
type: 'Accept',
object
});

View File

@@ -1,4 +1,4 @@
export default object => ({
export default (object: any) => ({
type: 'Announce',
object
});

View File

@@ -1,4 +1,4 @@
export default object => ({
export default (object: any) => ({
type: 'Create',
object
});

View File

@@ -1,4 +1,4 @@
export default object => ({
export default (object: any) => ({
type: 'Delete',
object
});

View File

@@ -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}`
});

View File

@@ -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}`
});

View File

@@ -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}`,

View File

@@ -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',

View File

@@ -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<any> {
const promisedFiles: Promise<IDriveFile[]> = note.mediaIds
? DriveFile.find({ _id: { $in: note.mediaIds } })
: Promise.resolve([]);

View File

@@ -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)
};

View File

@@ -1,4 +1,4 @@
export default object => ({
export default (object: any) => ({
type: 'Undo',
object
});

View File

@@ -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<IObject> {
public async resolve(value: any): Promise<IObject> {
if (value == null) {
throw new Error('resolvee is null (or undefined)');
}

View File

@@ -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<IUser> => {
export default async (username: string, _host: string, option?: any): Promise<IUser> => {
const usernameLower = username.toLowerCase();
if (_host == null) {