pub-relay (#6341)
* pub-relay * relay actorをApplicationにする * Disable koa-compress * Homeはリレーに送らない * Disable debug * UI * cleanupなど
This commit is contained in:
@@ -2,6 +2,7 @@ import { IRemoteUser } from '../../../../models/entities/user';
|
||||
import accept from '../../../../services/following/requests/accept';
|
||||
import { IFollow } from '../../type';
|
||||
import DbResolver from '../../db-resolver';
|
||||
import { relayAccepted } from '../../../../services/relay';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
|
||||
// ※ activityはこっちから投げたフォローリクエストなので、activity.actorは存在するローカルユーザーである必要がある
|
||||
@@ -17,6 +18,12 @@ export default async (actor: IRemoteUser, activity: IFollow): Promise<string> =>
|
||||
return `skip: follower is not a local user`;
|
||||
}
|
||||
|
||||
// relay
|
||||
const match = activity.id?.match(/follow-relay\/(\w+)/);
|
||||
if (match) {
|
||||
return await relayAccepted(match[1]);
|
||||
}
|
||||
|
||||
await accept(actor, follower);
|
||||
return `ok`;
|
||||
};
|
||||
|
@@ -2,6 +2,7 @@ import { IRemoteUser } from '../../../../models/entities/user';
|
||||
import reject from '../../../../services/following/requests/reject';
|
||||
import { IFollow } from '../../type';
|
||||
import DbResolver from '../../db-resolver';
|
||||
import { relayRejected } from '../../../../services/relay';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
|
||||
// ※ activityはこっちから投げたフォローリクエストなので、activity.actorは存在するローカルユーザーである必要がある
|
||||
@@ -17,6 +18,12 @@ export default async (actor: IRemoteUser, activity: IFollow): Promise<string> =>
|
||||
return `skip: follower is not a local user`;
|
||||
}
|
||||
|
||||
// relay
|
||||
const match = activity.id?.match(/follow-relay\/(\w+)/);
|
||||
if (match) {
|
||||
return await relayRejected(match[1]);
|
||||
}
|
||||
|
||||
await reject(actor, follower);
|
||||
return `ok`;
|
||||
};
|
||||
|
@@ -70,6 +70,7 @@ export class LdSignature {
|
||||
const transformedData = { ...data };
|
||||
delete transformedData['signature'];
|
||||
const cannonidedData = await this.normalize(transformedData);
|
||||
if (this.debug) console.debug(`cannonidedData: ${cannonidedData}`);
|
||||
const documentHash = this.sha256(cannonidedData);
|
||||
const verifyData = `${optionsHash}${documentHash}`;
|
||||
return verifyData;
|
||||
|
14
src/remote/activitypub/renderer/follow-relay.ts
Normal file
14
src/remote/activitypub/renderer/follow-relay.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import config from '../../../config';
|
||||
import { Relay } from '../../../models/entities/relay';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
|
||||
export function renderFollowRelay(relay: Relay, relayActor: ILocalUser) {
|
||||
const follow = {
|
||||
id: `${config.url}/activities/follow-relay/${relay.id}`,
|
||||
type: 'Follow',
|
||||
actor: `${config.url}/users/${relayActor.id}`,
|
||||
object: 'https://www.w3.org/ns/activitystreams#Public'
|
||||
};
|
||||
|
||||
return follow;
|
||||
}
|
@@ -1,7 +1,12 @@
|
||||
import config from '../../../config';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { IActivity } from '../type';
|
||||
import { LdSignature } from '../misc/ld-signature';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
import { UserKeypairs } from '../../../models';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export const renderActivity = (x: any) => {
|
||||
export const renderActivity = (x: any): IActivity | null => {
|
||||
if (x == null) return null;
|
||||
|
||||
if (x !== null && typeof x === 'object' && x.id == null) {
|
||||
@@ -11,8 +16,46 @@ export const renderActivity = (x: any) => {
|
||||
return Object.assign({
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
{ Hashtag: 'as:Hashtag' }
|
||||
'https://w3id.org/security/v1'
|
||||
]
|
||||
}, x);
|
||||
};
|
||||
|
||||
export const attachLdSignature = async (activity: any, user: ILocalUser): Promise<IActivity | null> => {
|
||||
if (activity == null) return null;
|
||||
|
||||
const keypair = await UserKeypairs.findOne({
|
||||
userId: user.id
|
||||
}).then(ensure);
|
||||
|
||||
const obj = {
|
||||
// as non-standards
|
||||
manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
|
||||
sensitive: 'as:sensitive',
|
||||
Hashtag: 'as:Hashtag',
|
||||
quoteUrl: 'as:quoteUrl',
|
||||
// Mastodon
|
||||
toot: 'http://joinmastodon.org/ns#',
|
||||
Emoji: 'toot:Emoji',
|
||||
featured: 'toot:featured',
|
||||
// schema
|
||||
schema: 'http://schema.org#',
|
||||
PropertyValue: 'schema:PropertyValue',
|
||||
value: 'schema:value',
|
||||
// Misskey
|
||||
misskey: `${config.url}/ns#`,
|
||||
'_misskey_content': 'misskey:_misskey_content',
|
||||
'_misskey_quote': 'misskey:_misskey_quote',
|
||||
'_misskey_reaction': 'misskey:_misskey_reaction',
|
||||
'_misskey_votes': 'misskey:_misskey_votes',
|
||||
'_misskey_talk': 'misskey:_misskey_talk',
|
||||
};
|
||||
|
||||
activity['@context'].push(obj);
|
||||
|
||||
const ldSignature = new LdSignature();
|
||||
ldSignature.debug = false;
|
||||
activity = await ldSignature.signRsaSignature2017(activity, keypair.privateKey, `${config.url}/users/${user.id}#main-key`);
|
||||
|
||||
return activity;
|
||||
};
|
||||
|
@@ -13,6 +13,7 @@ import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export async function renderPerson(user: ILocalUser) {
|
||||
const id = `${config.url}/users/${user.id}`;
|
||||
const isSystem = !!user.username.match(/\./);
|
||||
|
||||
const [avatar, banner, profile] = await Promise.all([
|
||||
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
|
||||
@@ -52,7 +53,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||
const keypair = await UserKeypairs.findOne(user.id).then(ensure);
|
||||
|
||||
return {
|
||||
type: user.isBot ? 'Service' : 'Person',
|
||||
type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person',
|
||||
id,
|
||||
inbox: `${id}/inbox`,
|
||||
outbox: `${id}/outbox`,
|
||||
|
Reference in New Issue
Block a user