forked from FoundKeyGang/FoundKey
Refactor
This commit is contained in:
parent
cdf13d30f2
commit
17f4dd69a3
7 changed files with 21 additions and 39 deletions
|
@ -1,5 +0,0 @@
|
||||||
export default [
|
|
||||||
'https://www.w3.org/ns/activitystreams',
|
|
||||||
'https://w3id.org/security/v1',
|
|
||||||
{ Hashtag: 'as:Hashtag' }
|
|
||||||
];
|
|
7
src/remote/activitypub/renderer/index.ts
Normal file
7
src/remote/activitypub/renderer/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default (x: any) => Object.assign({
|
||||||
|
'@context': [
|
||||||
|
'https://www.w3.org/ns/activitystreams',
|
||||||
|
'https://w3id.org/security/v1',
|
||||||
|
{ Hashtag: 'as:Hashtag' }
|
||||||
|
]
|
||||||
|
}, x);
|
|
@ -2,8 +2,7 @@ import * as Router from 'koa-router';
|
||||||
import { parseRequest } from 'http-signature';
|
import { parseRequest } from 'http-signature';
|
||||||
|
|
||||||
import { createHttp } from '../queue';
|
import { createHttp } from '../queue';
|
||||||
import context from '../remote/activitypub/renderer/context';
|
import pack from '../remote/activitypub/renderer';
|
||||||
import render from '../remote/activitypub/renderer/note';
|
|
||||||
import Note from '../models/note';
|
import Note from '../models/note';
|
||||||
import User, { isLocalUser } from '../models/user';
|
import User, { isLocalUser } from '../models/user';
|
||||||
import renderNote from '../remote/activitypub/renderer/note';
|
import renderNote from '../remote/activitypub/renderer/note';
|
||||||
|
@ -57,10 +56,7 @@ router.get('/notes/:note', async (ctx, next) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rendered = await render(note);
|
ctx.body = pack(await renderNote(note));
|
||||||
rendered['@context'] = context;
|
|
||||||
|
|
||||||
ctx.body = rendered;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// outbot
|
// outbot
|
||||||
|
@ -81,9 +77,8 @@ router.get('/users/:user/outbox', async ctx => {
|
||||||
|
|
||||||
const renderedNotes = await Promise.all(notes.map(note => renderNote(note)));
|
const renderedNotes = await Promise.all(notes.map(note => renderNote(note)));
|
||||||
const rendered = renderOrderedCollection(`${config.url}/users/${userId}/inbox`, user.notesCount, renderedNotes);
|
const rendered = renderOrderedCollection(`${config.url}/users/${userId}/inbox`, user.notesCount, renderedNotes);
|
||||||
rendered['@context'] = context;
|
|
||||||
|
|
||||||
ctx.body = rendered;
|
ctx.body = pack(rendered);
|
||||||
});
|
});
|
||||||
|
|
||||||
// publickey
|
// publickey
|
||||||
|
@ -98,10 +93,7 @@ router.get('/users/:user/publickey', async ctx => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLocalUser(user)) {
|
if (isLocalUser(user)) {
|
||||||
const rendered = renderKey(user);
|
ctx.body = pack(renderKey(user));
|
||||||
rendered['@context'] = context;
|
|
||||||
|
|
||||||
ctx.body = rendered;
|
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
}
|
}
|
||||||
|
@ -118,10 +110,7 @@ router.get('/users/:user', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rendered = renderPerson(user);
|
ctx.body = pack(renderPerson(user));
|
||||||
rendered['@context'] = context;
|
|
||||||
|
|
||||||
ctx.body = rendered;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// follow form
|
// follow form
|
||||||
|
|
|
@ -4,7 +4,7 @@ import FollowingLog from '../../models/following-log';
|
||||||
import FollowedLog from '../../models/followed-log';
|
import FollowedLog from '../../models/followed-log';
|
||||||
import event from '../../publishers/stream';
|
import event from '../../publishers/stream';
|
||||||
import notify from '../../publishers/notify';
|
import notify from '../../publishers/notify';
|
||||||
import context from '../../remote/activitypub/renderer/context';
|
import pack from '../../remote/activitypub/renderer';
|
||||||
import renderFollow from '../../remote/activitypub/renderer/follow';
|
import renderFollow from '../../remote/activitypub/renderer/follow';
|
||||||
import renderAccept from '../../remote/activitypub/renderer/accept';
|
import renderAccept from '../../remote/activitypub/renderer/accept';
|
||||||
import { deliver } from '../../queue';
|
import { deliver } from '../../queue';
|
||||||
|
@ -57,16 +57,12 @@ export default async function(follower: IUser, followee: IUser, activity?) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
||||||
const content = renderFollow(follower, followee);
|
const content = pack(renderFollow(follower, followee));
|
||||||
content['@context'] = context;
|
|
||||||
|
|
||||||
deliver(follower, content, followee.inbox).save();
|
deliver(follower, content, followee.inbox).save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRemoteUser(follower) && isLocalUser(followee)) {
|
if (isRemoteUser(follower) && isLocalUser(followee)) {
|
||||||
const content = renderAccept(activity);
|
const content = pack(renderAccept(activity));
|
||||||
content['@context'] = context;
|
|
||||||
|
|
||||||
deliver(followee, content, follower.inbox).save();
|
deliver(followee, content, follower.inbox).save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Following from '../../models/following';
|
||||||
import FollowingLog from '../../models/following-log';
|
import FollowingLog from '../../models/following-log';
|
||||||
import FollowedLog from '../../models/followed-log';
|
import FollowedLog from '../../models/followed-log';
|
||||||
import event from '../../publishers/stream';
|
import event from '../../publishers/stream';
|
||||||
import context from '../../remote/activitypub/renderer/context';
|
import pack from '../../remote/activitypub/renderer';
|
||||||
import renderFollow from '../../remote/activitypub/renderer/follow';
|
import renderFollow from '../../remote/activitypub/renderer/follow';
|
||||||
import renderUndo from '../../remote/activitypub/renderer/undo';
|
import renderUndo from '../../remote/activitypub/renderer/undo';
|
||||||
import { deliver } from '../../queue';
|
import { deliver } from '../../queue';
|
||||||
|
@ -56,9 +56,7 @@ export default async function(follower: IUser, followee: IUser, activity?) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
if (isLocalUser(follower) && isRemoteUser(followee)) {
|
||||||
const content = renderUndo(renderFollow(follower, followee));
|
const content = pack(renderUndo(renderFollow(follower, followee)));
|
||||||
content['@context'] = context;
|
|
||||||
|
|
||||||
deliver(follower, content, followee.inbox).save();
|
deliver(follower, content, followee.inbox).save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { deliver } from '../../queue';
|
||||||
import renderNote from '../../remote/activitypub/renderer/note';
|
import renderNote from '../../remote/activitypub/renderer/note';
|
||||||
import renderCreate from '../../remote/activitypub/renderer/create';
|
import renderCreate from '../../remote/activitypub/renderer/create';
|
||||||
import renderAnnounce from '../../remote/activitypub/renderer/announce';
|
import renderAnnounce from '../../remote/activitypub/renderer/announce';
|
||||||
import context from '../../remote/activitypub/renderer/context';
|
import packAp from '../../remote/activitypub/renderer';
|
||||||
import { IDriveFile } from '../../models/drive-file';
|
import { IDriveFile } from '../../models/drive-file';
|
||||||
import notify from '../../publishers/notify';
|
import notify from '../../publishers/notify';
|
||||||
import NoteWatching from '../../models/note-watching';
|
import NoteWatching from '../../models/note-watching';
|
||||||
|
@ -132,8 +132,7 @@ export default async (user: IUser, data: {
|
||||||
const content = data.renote && data.text == null
|
const content = data.renote && data.text == null
|
||||||
? renderAnnounce(data.renote.uri ? data.renote.uri : await renderNote(data.renote))
|
? renderAnnounce(data.renote.uri ? data.renote.uri : await renderNote(data.renote))
|
||||||
: renderCreate(await renderNote(note));
|
: renderCreate(await renderNote(note));
|
||||||
content['@context'] = context;
|
return packAp(content);
|
||||||
return content;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送
|
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送
|
||||||
|
|
|
@ -8,7 +8,7 @@ import NoteWatching from '../../../models/note-watching';
|
||||||
import watch from '../watch';
|
import watch from '../watch';
|
||||||
import renderLike from '../../../remote/activitypub/renderer/like';
|
import renderLike from '../../../remote/activitypub/renderer/like';
|
||||||
import { deliver } from '../../../queue';
|
import { deliver } from '../../../queue';
|
||||||
import context from '../../../remote/activitypub/renderer/context';
|
import pack from '../../../remote/activitypub/renderer';
|
||||||
|
|
||||||
export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => {
|
export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => {
|
||||||
// Myself
|
// Myself
|
||||||
|
@ -85,9 +85,7 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
|
||||||
//#region 配信
|
//#region 配信
|
||||||
// リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送
|
// リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送
|
||||||
if (isLocalUser(user) && isRemoteUser(note._user)) {
|
if (isLocalUser(user) && isRemoteUser(note._user)) {
|
||||||
const content = renderLike(user, note);
|
const content = pack(renderLike(user, note));
|
||||||
content['@context'] = context;
|
|
||||||
|
|
||||||
deliver(user, content, note._user.inbox).save();
|
deliver(user, content, note._user.inbox).save();
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
Loading…
Reference in a new issue