1
0
forked from mirror/misskey
This commit is contained in:
syuilo 2018-04-05 18:43:06 +09:00
parent 06347cd71e
commit 7403f38fb4
9 changed files with 50 additions and 27 deletions

View File

@ -18,20 +18,21 @@ import html from '../../text/html';
import { IApp } from '../../models/app';
export default async (user: IUser, content: {
createdAt: Date;
text: string;
reply: IPost;
repost: IPost;
media: IDriveFile[];
geo: any;
createdAt?: Date;
text?: string;
reply?: IPost;
repost?: IPost;
media?: IDriveFile[];
geo?: any;
poll?: any;
viaMobile: boolean;
viaMobile?: boolean;
tags?: string[];
cw?: string;
visibility?: string;
uri?: string;
app?: IApp;
}) => new Promise<IPost>(async (res, rej) => {
if (content.createdAt == null) content.createdAt = new Date();
if (content.visibility == null) content.visibility = 'public';
const tags = content.tags || [];

View File

@ -103,7 +103,7 @@ async function workerMain(opt) {
if (!opt['only-server']) {
// start processor
require('./processor').default();
require('./queue').default();
}
// Send a 'ready' message to parent process

View File

@ -1,8 +1,12 @@
import { createQueue } from 'kue';
import * as debug from 'debug';
import config from '../config';
import db from './processors/db';
import http from './processors/http';
const log = debug('misskey:queue');
const queue = createQueue({
redis: {
port: config.redis.port,
@ -12,6 +16,8 @@ const queue = createQueue({
});
export function createHttp(data) {
log(`HTTP job created: ${JSON.stringify(data)}`);
return queue
.create('http', data)
.attempts(16)
@ -22,7 +28,7 @@ export function createDb(data) {
return queue.create('db', data);
}
export function process() {
export default function() {
queue.process('db', db);
/*

View File

@ -3,5 +3,12 @@ import * as kue from 'kue';
import request from '../../../remote/request';
export default async (job: kue.Job, done): Promise<void> => {
try {
await request(job.data.user, job.data.to, job.data.content);
done();
} catch (e) {
console.warn(`deliver failed: ${e}`);
done(e);
}
};

View File

@ -5,7 +5,15 @@ import reportGitHubFailure from './report-github-failure';
const handlers = {
deliver,
processInbox,
reportGitHubFailure,
reportGitHubFailure
};
export default (job, done) => handlers[job.data.type](job).then(() => done(), done);
export default (job, done) => {
const handler = handlers[job.data.type];
if (handler) {
handler(job).then(() => done(), done);
} else {
console.warn(`Unknown job: ${job.data.type}`);
}
};

View File

@ -1,6 +1,6 @@
import * as request from 'request-promise-native';
import User from '../../models/user';
const createPost = require('../../server/api/endpoints/posts/create');
import User from '../../../models/user';
import createPost from '../../../api/post/create';
export default async ({ data }) => {
const asyncBot = User.findOne({ _id: data.userId });
@ -20,5 +20,5 @@ export default async ({ data }) => {
`**⚠BUILD STILL FAILED⚠**: ?[${data.message}](${data.htmlUrl})` :
`**🚨BUILD FAILED🚨**: →→→?[${data.message}](${data.htmlUrl})←←←`;
createPost({ text }, await asyncBot);
createPost(await asyncBot, { text });
};

View File

@ -59,7 +59,7 @@ export default class Resolver {
throw new Error('invalid response');
}
log(`resolved: ${JSON.stringify(object)}`);
log(`resolved: ${JSON.stringify(object, null, 2)}`);
return object;
}

View File

@ -1,9 +1,15 @@
import { request } from 'https';
import { sign } from 'http-signature';
import { URL } from 'url';
import * as debug from 'debug';
import config from '../config';
const log = debug('misskey:activitypub:deliver');
export default ({ account, username }, url, object) => new Promise((resolve, reject) => {
log(`--> ${url}`);
const { protocol, hostname, port, pathname, search } = new URL(url);
const req = request({
@ -14,6 +20,8 @@ export default ({ account, username }, url, object) => new Promise((resolve, rej
path: pathname + search,
}, res => {
res.on('end', () => {
log(`${url} --> ${res.statusCode}`);
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve();
} else {

View File

@ -4,7 +4,7 @@
import $ from 'cafy';
import User from '../../../../models/user';
import Following from '../../../../models/following';
import queue from '../../../../queue';
import create from '../../../../api/following/create';
/**
* Follow a user
@ -50,15 +50,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Create following
const { _id } = await Following.insert({
createdAt: new Date(),
followerId: follower._id,
followeeId: followee._id
});
queue.create('http', { type: 'follow', following: _id }).save();
create(follower, followee);
// Send response
res();
});