This commit is contained in:
syuilo 2018-04-05 03:21:11 +09:00
parent b6b9875205
commit c2c03a1c65
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 prominence = require('prominence');
import DriveFile, { IMetadata, getGridFSBucket } from '../models/drive-file';
import DriveFolder from '../models/drive-folder';
import { pack } from '../models/drive-file';
import event, { publishDriveStream } from '../publishers/stream';
import getAcct from '../acct/render';
import config from '../config';
import DriveFile, { IMetadata, getGridFSBucket } from '../../models/drive-file';
import DriveFolder from '../../models/drive-folder';
import { pack } from '../../models/drive-file';
import event, { publishDriveStream } from '../../publishers/stream';
import getAcct from '../../acct/render';
import config from '../../config';
const gm = _gm.subClass({
imageMagick: true

View File

@ -1,5 +1,5 @@
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 * as debug from 'debug';
import * as tmp from 'tmp';

View File

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

View File

@ -1,5 +1,5 @@
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) => {
// 自分の投稿はwatchできない

View File

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

View File

@ -5,7 +5,6 @@ import parseAcct from '../../../acct/parse';
import User, { IRemoteUser } from '../../../models/user';
import act from '../../../remote/activitypub/act';
import resolvePerson from '../../../remote/activitypub/resolve-person';
import Resolver from '../../../remote/activitypub/resolver';
// ユーザーのinboxにアクティビティが届いた時の処理
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) {
case 'Image':
createImage(resolver, object);
createImage(object);
break;
case 'Note':
createNote(resolver, object);
createNote(object);
break;
}
///
async function createImage(resolver: Resolver, image) {
async function createImage(image) {
if ('attributedTo' in image && actor.account.uri !== image.attributedTo) {
throw new Error('invalid image');
}
@ -54,7 +54,7 @@ export default async (actor, activity): Promise<void> => {
return await uploadFromUrl(image.url, actor);
}
async function createNote(resolver: Resolver, note) {
async function createNote(note) {
if (
('attributedTo' in note && actor.account.uri !== note.attributedTo) ||
typeof note.id !== 'string'
@ -63,20 +63,29 @@ export default async (actor, activity): Promise<void> => {
}
const media = [];
if ('attachment' in note) {
note.attachment.forEach(async media => {
const created = await createImage(resolver, media);
const created = await createImage(media);
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);
await createPost(actor, {
return await createPost(actor, {
createdAt: new Date(note.published),
media,
reply: undefined,
reply,
repost: undefined,
text: window.document.body.textContent,
viaMobile: false,

View File

@ -1,21 +1,28 @@
import create from '../create';
import deleteObject from '../delete';
import Resolver from '../resolver';
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) {
throw new Error();
}
const results = await create(resolver, actor, activity.object);
const resolver = new Resolver();
await Promise.all(results.map(async promisedResult => {
const result = await promisedResult;
if (result === null) {
return;
}
const object = await resolver.resolve(activity);
await deleteObject(result);
}));
switch (object.type) {
case 'Note':
deleteNote(object);
break;
}
return null;
async function deleteNote(note) {
const post = await Post.findOneAndDelete({ uri: note.id });
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) {
case 'Follow':
unfollow(activity.object);
unfollow(actor, activity.object);
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 User, { validateUsername, isValidName, isValidDescription } from '../../models/user';
import webFinger from '../webfinger';
import create from './create';
import Resolver from './resolver';
import uploadFromUrl from '../../api/drive/upload-from-url';

View File

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