mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-11-01 15:45:58 +09:00
wip
This commit is contained in:
parent
06347cd71e
commit
7403f38fb4
@ -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 || [];
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
/*
|
||||
|
@ -3,5 +3,12 @@ import * as kue from 'kue';
|
||||
import request from '../../../remote/request';
|
||||
|
||||
export default async (job: kue.Job, done): Promise<void> => {
|
||||
await request(job.data.user, job.data.to, job.data.content);
|
||||
try {
|
||||
await request(job.data.user, job.data.to, job.data.content);
|
||||
done();
|
||||
} catch (e) {
|
||||
console.warn(`deliver failed: ${e}`);
|
||||
|
||||
done(e);
|
||||
}
|
||||
};
|
||||
|
@ -3,9 +3,17 @@ import processInbox from './process-inbox';
|
||||
import reportGitHubFailure from './report-github-failure';
|
||||
|
||||
const handlers = {
|
||||
deliver,
|
||||
processInbox,
|
||||
reportGitHubFailure,
|
||||
deliver,
|
||||
processInbox,
|
||||
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}`);
|
||||
}
|
||||
};
|
||||
|
@ -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 });
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user