2021-03-23 08:43:07 +00:00
|
|
|
import config from '@/config';
|
2019-08-18 03:42:58 +00:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2020-05-10 09:42:31 +00:00
|
|
|
import { IActivity } from '../type';
|
|
|
|
import { LdSignature } from '../misc/ld-signature';
|
2021-03-23 08:43:07 +00:00
|
|
|
import { getUserKeypair } from '@/misc/keypair-store';
|
2021-03-24 02:05:37 +00:00
|
|
|
import { User } from '@/models/entities/user';
|
2018-08-25 04:11:54 +00:00
|
|
|
|
2020-05-10 09:42:31 +00:00
|
|
|
export const renderActivity = (x: any): IActivity | null => {
|
2018-11-16 18:25:48 +00:00
|
|
|
if (x == null) return null;
|
|
|
|
|
2018-08-25 04:11:54 +00:00
|
|
|
if (x !== null && typeof x === 'object' && x.id == null) {
|
2019-08-18 03:42:58 +00:00
|
|
|
x.id = `${config.url}/${uuid()}`;
|
2018-08-25 04:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Object.assign({
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
2021-05-19 07:00:08 +00:00
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
{
|
|
|
|
// 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',
|
|
|
|
discoverable: 'toot:discoverable',
|
|
|
|
// 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',
|
|
|
|
'isCat': 'misskey:isCat',
|
|
|
|
// vcard
|
|
|
|
vcard: 'http://www.w3.org/2006/vcard/ns#',
|
|
|
|
}
|
2018-08-25 04:11:54 +00:00
|
|
|
]
|
|
|
|
}, x);
|
|
|
|
};
|
2020-05-10 09:42:31 +00:00
|
|
|
|
2021-03-24 02:05:37 +00:00
|
|
|
export const attachLdSignature = async (activity: any, user: { id: User['id']; host: null; }): Promise<IActivity | null> => {
|
2020-05-10 09:42:31 +00:00
|
|
|
if (activity == null) return null;
|
|
|
|
|
2021-03-22 06:14:54 +00:00
|
|
|
const keypair = await getUserKeypair(user.id);
|
2020-05-10 09:42:31 +00:00
|
|
|
|
|
|
|
const ldSignature = new LdSignature();
|
|
|
|
ldSignature.debug = false;
|
|
|
|
activity = await ldSignature.signRsaSignature2017(activity, keypair.privateKey, `${config.url}/users/${user.id}#main-key`);
|
|
|
|
|
|
|
|
return activity;
|
|
|
|
};
|