Use id in uri instead of username
This commit is contained in:
@ -1,25 +1,23 @@
|
||||
import parseAcct from '../../../acct/parse';
|
||||
import User, { IRemoteUser } from '../../../models/user';
|
||||
import config from '../../../config';
|
||||
import follow from '../../../services/following/create';
|
||||
import { IFollow } from '../type';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
||||
const prefix = config.url + '/@';
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
|
||||
if (!id.startsWith(prefix)) {
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { username, host } = parseAcct(id.slice(prefix.length));
|
||||
if (host !== null) {
|
||||
throw new Error();
|
||||
const followee = await User.findOne({ _id: id.split('/').pop() });
|
||||
|
||||
if (followee === null) {
|
||||
throw new Error('followee not found');
|
||||
}
|
||||
|
||||
const followee = await User.findOne({ username, host });
|
||||
if (followee === null) {
|
||||
throw new Error();
|
||||
if (followee.host != null) {
|
||||
throw new Error('フォローしようとしているユーザーはローカルユーザーではありません');
|
||||
}
|
||||
|
||||
await follow(actor, followee, activity);
|
||||
|
@ -1,25 +1,23 @@
|
||||
import parseAcct from '../../../../acct/parse';
|
||||
import User, { IRemoteUser } from '../../../../models/user';
|
||||
import config from '../../../../config';
|
||||
import unfollow from '../../../../services/following/delete';
|
||||
import { IFollow } from '../../type';
|
||||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
||||
const prefix = config.url + '/@';
|
||||
const id = typeof activity == 'string' ? activity : activity.id;
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
|
||||
if (!id.startsWith(prefix)) {
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { username, host } = parseAcct(id.slice(prefix.length));
|
||||
if (host !== null) {
|
||||
throw new Error();
|
||||
const followee = await User.findOne({ _id: id.split('/').pop() });
|
||||
|
||||
if (followee === null) {
|
||||
throw new Error('followee not found');
|
||||
}
|
||||
|
||||
const followee = await User.findOne({ username, host });
|
||||
if (followee === null) {
|
||||
throw new Error();
|
||||
if (followee.host != null) {
|
||||
throw new Error('フォロー解除しようとしているユーザーはローカルユーザーではありません');
|
||||
}
|
||||
|
||||
await unfollow(actor, followee, activity);
|
||||
|
@ -3,6 +3,6 @@ import { IRemoteUser, ILocalUser } from '../../../models/user';
|
||||
|
||||
export default (follower: ILocalUser, followee: IRemoteUser) => ({
|
||||
type: 'Follow',
|
||||
actor: `${config.url}/@${follower.username}`,
|
||||
actor: `${config.url}/users/${follower._id}`,
|
||||
object: followee.uri
|
||||
});
|
||||
|
@ -3,8 +3,8 @@ import { extractPublic } from '../../../crypto_key';
|
||||
import { ILocalUser } from '../../../models/user';
|
||||
|
||||
export default (user: ILocalUser) => ({
|
||||
id: `${config.url}/@${user.username}/publickey`,
|
||||
id: `${config.url}/users/${user._id}/publickey`,
|
||||
type: 'Key',
|
||||
owner: `${config.url}/@${user.username}`,
|
||||
owner: `${config.url}/users/${user._id}`,
|
||||
publicKeyPem: extractPublic(user.keypair)
|
||||
});
|
||||
|
@ -1,10 +1,8 @@
|
||||
import config from '../../../config';
|
||||
import { ILocalUser } from '../../../models/user';
|
||||
|
||||
export default (user: ILocalUser, note) => {
|
||||
return {
|
||||
type: 'Like',
|
||||
actor: `${config.url}/@${user.username}`,
|
||||
object: note.uri ? note.uri : `${config.url}/notes/${note._id}`
|
||||
};
|
||||
};
|
||||
export default (user: ILocalUser, note) => ({
|
||||
type: 'Like',
|
||||
actor: `${config.url}/users/${user._id}`,
|
||||
object: note.uri ? note.uri : `${config.url}/notes/${note._id}`
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ export default async (note: INote) => {
|
||||
_id: note.userId
|
||||
});
|
||||
|
||||
const attributedTo = `${config.url}/@${user.username}`;
|
||||
const attributedTo = `${config.url}/users/${user._id}`;
|
||||
|
||||
return {
|
||||
id: `${config.url}/notes/${note._id}`,
|
||||
|
@ -3,7 +3,7 @@ import renderKey from './key';
|
||||
import config from '../../../config';
|
||||
|
||||
export default user => {
|
||||
const id = `${config.url}/@${user.username}`;
|
||||
const id = `${config.url}/users/${user._id}`;
|
||||
|
||||
return {
|
||||
type: 'Person',
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { toUnicode } from 'punycode';
|
||||
import parseAcct from '../../acct/parse';
|
||||
import config from '../../config';
|
||||
import User, { validateUsername, isValidName, isValidDescription, IUser } from '../../models/user';
|
||||
import webFinger from '../webfinger';
|
||||
@ -10,10 +9,9 @@ import { isCollectionOrOrderedCollection, IObject } from './type';
|
||||
|
||||
export default async (value: string | IObject, verifier?: string): Promise<IUser> => {
|
||||
const id = typeof value == 'string' ? value : value.id;
|
||||
const localPrefix = config.url + '/@';
|
||||
|
||||
if (id.startsWith(localPrefix)) {
|
||||
return await User.findOne(parseAcct(id.substr(localPrefix.length)));
|
||||
if (id.startsWith(config.url + '/')) {
|
||||
return await User.findOne({ _id: id.split('/').pop() });
|
||||
}
|
||||
|
||||
const resolver = new Resolver();
|
||||
|
@ -50,7 +50,7 @@ export default class Resolver {
|
||||
|
||||
//#region resolve local objects
|
||||
// TODO
|
||||
//if (value.startsWith(`${config.url}/@`)) {
|
||||
//if (value.startsWith(`${config.url}/`)) {
|
||||
//#endregion
|
||||
|
||||
const object = await request({
|
||||
|
Reference in New Issue
Block a user