This commit is contained in:
syuilo 2018-04-05 03:21:11 +09:00
parent de79ac7ace
commit 074ea114ab
13 changed files with 60 additions and 68 deletions

View File

@ -10,12 +10,12 @@ import * as debug from 'debug';
import fileType = require('file-type'); import fileType = require('file-type');
import prominence = require('prominence'); import prominence = require('prominence');
import DriveFile, { IMetadata, getGridFSBucket } from '../models/drive-file'; import DriveFile, { IMetadata, getGridFSBucket } from '../../models/drive-file';
import DriveFolder from '../models/drive-folder'; import DriveFolder from '../../models/drive-folder';
import { pack } from '../models/drive-file'; import { pack } from '../../models/drive-file';
import event, { publishDriveStream } from '../publishers/stream'; import event, { publishDriveStream } from '../../publishers/stream';
import getAcct from '../acct/render'; import getAcct from '../../acct/render';
import config from '../config'; import config from '../../config';
const gm = _gm.subClass({ const gm = _gm.subClass({
imageMagick: true imageMagick: true

View File

@ -1,5 +1,5 @@
import * as URL from 'url'; import * as URL from 'url';
import { IDriveFile, validateFileName } from '../models/drive-file'; import { IDriveFile, validateFileName } from '../../models/drive-file';
import create from './add-file'; import create from './add-file';
import * as debug from 'debug'; import * as debug from 'debug';
import * as tmp from 'tmp'; import * as tmp from 'tmp';

View File

@ -1,6 +1,5 @@
import parseAcct from '../../acct/parse';
import Post, { pack, IPost } from '../../models/post'; import Post, { pack, IPost } from '../../models/post';
import User, { isLocalUser, isRemoteUser, IUser } from '../../models/user'; import User, { isLocalUser, IUser } from '../../models/user';
import stream from '../../publishers/stream'; import stream from '../../publishers/stream';
import Following from '../../models/following'; import Following from '../../models/following';
import { createHttp } from '../../queue'; import { createHttp } from '../../queue';
@ -25,14 +24,16 @@ export default async (user: IUser, content: {
repost: IPost; repost: IPost;
media: IDriveFile[]; media: IDriveFile[];
geo: any; geo: any;
poll: any; poll?: any;
viaMobile: boolean; viaMobile: boolean;
tags: string[]; tags?: string[];
cw: string; cw?: string;
visibility: string; visibility?: string;
uri?: string; uri?: string;
app?: IApp; app?: IApp;
}) => new Promise<IPost>(async (res, rej) => { }) => new Promise<IPost>(async (res, rej) => {
if (content.visibility == null) content.visibility = 'public';
const tags = content.tags || []; const tags = content.tags || [];
let tokens = null; let tokens = null;

View File

@ -1,5 +1,5 @@
import * as mongodb from 'mongodb'; import * as mongodb from 'mongodb';
import Watching from '../models/post-watching'; import Watching from '../../models/post-watching';
export default async (me: mongodb.ObjectID, post: object) => { export default async (me: mongodb.ObjectID, post: object) => {
// 自分の投稿はwatchできない // 自分の投稿はwatchできない

View File

@ -1,9 +1,9 @@
import Favorite from '../../models/favorite'; import Favorite from '../../../models/favorite';
import Notification from '../../models/notification'; import Notification from '../../../models/notification';
import PollVote from '../../models/poll-vote'; import PollVote from '../../../models/poll-vote';
import PostReaction from '../../models/post-reaction'; import PostReaction from '../../../models/post-reaction';
import PostWatching from '../../models/post-watching'; import PostWatching from '../../../models/post-watching';
import Post from '../../models/post'; import Post from '../../../models/post';
export default async ({ data }) => Promise.all([ export default async ({ data }) => Promise.all([
Favorite.remove({ postId: data._id }), Favorite.remove({ postId: data._id }),

View File

@ -5,7 +5,6 @@ import parseAcct from '../../../acct/parse';
import User, { IRemoteUser } from '../../../models/user'; import User, { IRemoteUser } from '../../../models/user';
import act from '../../../remote/activitypub/act'; import act from '../../../remote/activitypub/act';
import resolvePerson from '../../../remote/activitypub/resolve-person'; import resolvePerson from '../../../remote/activitypub/resolve-person';
import Resolver from '../../../remote/activitypub/resolver';
// ユーザーのinboxにアクティビティが届いた時の処理 // ユーザーのinboxにアクティビティが届いた時の処理
export default async (job: kue.Job, done): Promise<void> => { export default async (job: kue.Job, done): Promise<void> => {

View File

@ -36,17 +36,17 @@ export default async (actor, activity): Promise<void> => {
switch (object.type) { switch (object.type) {
case 'Image': case 'Image':
createImage(resolver, object); createImage(object);
break; break;
case 'Note': case 'Note':
createNote(resolver, object); createNote(object);
break; break;
} }
/// ///
async function createImage(resolver: Resolver, image) { async function createImage(image) {
if ('attributedTo' in image && actor.account.uri !== image.attributedTo) { if ('attributedTo' in image && actor.account.uri !== image.attributedTo) {
throw new Error('invalid image'); throw new Error('invalid image');
} }
@ -54,7 +54,7 @@ export default async (actor, activity): Promise<void> => {
return await uploadFromUrl(image.url, actor); return await uploadFromUrl(image.url, actor);
} }
async function createNote(resolver: Resolver, note) { async function createNote(note) {
if ( if (
('attributedTo' in note && actor.account.uri !== note.attributedTo) || ('attributedTo' in note && actor.account.uri !== note.attributedTo) ||
typeof note.id !== 'string' typeof note.id !== 'string'
@ -63,20 +63,29 @@ export default async (actor, activity): Promise<void> => {
} }
const media = []; const media = [];
if ('attachment' in note) { if ('attachment' in note) {
note.attachment.forEach(async media => { note.attachment.forEach(async media => {
const created = await createImage(resolver, media); const created = await createImage(media);
media.push(created); media.push(created);
}); });
} }
let reply = null;
if ('inReplyTo' in note) {
const inReplyToPost = await Post.findOne({ uri: note.id || note });
if (inReplyToPost) {
reply = inReplyToPost;
} else {
reply = await createNote(await resolver.resolve(note));
}
}
const { window } = new JSDOM(note.content); const { window } = new JSDOM(note.content);
await createPost(actor, { return await createPost(actor, {
createdAt: new Date(note.published), createdAt: new Date(note.published),
media, media,
reply: undefined, reply,
repost: undefined, repost: undefined,
text: window.document.body.textContent, text: window.document.body.textContent,
viaMobile: false, viaMobile: false,

View File

@ -1,21 +1,28 @@
import create from '../create'; import Resolver from '../resolver';
import deleteObject from '../delete'; import Post from '../../../models/post';
import { createDb } from '../../../queue';
export default async (resolver, actor, activity) => { export default async (actor, activity): Promise<void> => {
if ('actor' in activity && actor.account.uri !== activity.actor) { if ('actor' in activity && actor.account.uri !== activity.actor) {
throw new Error(); throw new Error();
} }
const results = await create(resolver, actor, activity.object); const resolver = new Resolver();
await Promise.all(results.map(async promisedResult => { const object = await resolver.resolve(activity);
const result = await promisedResult;
if (result === null) { switch (object.type) {
return; case 'Note':
deleteNote(object);
break;
} }
await deleteObject(result); async function deleteNote(note) {
})); const post = await Post.findOneAndDelete({ uri: note.id });
return null; createDb({
type: 'deletePostDependents',
id: post._id
}).delay(65536).save();
}
}; };

View File

@ -7,7 +7,7 @@ export default async (actor, activity): Promise<void> => {
switch (activity.object.type) { switch (activity.object.type) {
case 'Follow': case 'Follow':
unfollow(activity.object); unfollow(actor, activity.object);
break; break;
} }

View File

@ -1,10 +0,0 @@
import deletePost from './post';
export default async ({ object }) => {
switch (object.$ref) {
case 'posts':
return deletePost(object);
}
return null;
};

View File

@ -1,13 +0,0 @@
import Post from '../../../models/post';
import queue from '../../../queue';
export default async ({ $id }) => {
const promisedDeletion = Post.findOneAndDelete({ _id: $id });
await new Promise((resolve, reject) => queue.create('db', {
type: 'deletePostDependents',
id: $id
}).delay(65536).save(error => error ? reject(error) : resolve()));
return promisedDeletion;
};

View File

@ -2,7 +2,6 @@ import { JSDOM } from 'jsdom';
import { toUnicode } from 'punycode'; import { toUnicode } from 'punycode';
import User, { validateUsername, isValidName, isValidDescription } from '../../models/user'; import User, { validateUsername, isValidName, isValidDescription } from '../../models/user';
import webFinger from '../webfinger'; import webFinger from '../webfinger';
import create from './create';
import Resolver from './resolver'; import Resolver from './resolver';
import uploadFromUrl from '../../api/drive/upload-from-url'; import uploadFromUrl from '../../api/drive/upload-from-url';

View File

@ -1,7 +1,7 @@
import * as bodyParser from 'body-parser'; import * as bodyParser from 'body-parser';
import * as express from 'express'; import * as express from 'express';
import { parseRequest } from 'http-signature'; import { parseRequest } from 'http-signature';
import queue from '../../queue'; import { createHttp } from '../../queue';
const app = express(); const app = express();
@ -22,7 +22,7 @@ app.post('/@:user/inbox', bodyParser.json({
return res.sendStatus(401); return res.sendStatus(401);
} }
queue.create('http', { createHttp({
type: 'processInbox', type: 'processInbox',
activity: req.body, activity: req.body,
signature, signature,