forked from FoundKeyGang/FoundKey
Remove resolveRemoteUserObjects method of remote/activitypub/resolver
The value of the value returned by resolveRemoteUserObjects method of remote/activitypub/resolver was inconsistent.
This commit is contained in:
parent
f5a948acac
commit
c22cb37759
5 changed files with 28 additions and 46 deletions
|
@ -3,4 +3,5 @@ import act from '../../remote/activitypub/act';
|
||||||
import Resolver from '../../remote/activitypub/resolver';
|
import Resolver from '../../remote/activitypub/resolver';
|
||||||
|
|
||||||
export default ({ data }) => User.findOne({ _id: data.actor })
|
export default ({ data }) => User.findOne({ _id: data.actor })
|
||||||
.then(actor => act(new Resolver(), actor, data.outbox));
|
.then(actor => act(new Resolver(), actor, data.outbox))
|
||||||
|
.then(Promise.all);
|
||||||
|
|
|
@ -35,5 +35,5 @@ export default async ({ data }) => {
|
||||||
throw 'signature verification failed';
|
throw 'signature verification failed';
|
||||||
}
|
}
|
||||||
|
|
||||||
await act(new Resolver(), user, data.inbox, true);
|
await Promise.all(await act(new Resolver(), user, data.inbox, true));
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,27 +4,29 @@ import undo from './undo';
|
||||||
import createObject from '../create';
|
import createObject from '../create';
|
||||||
import Resolver from '../resolver';
|
import Resolver from '../resolver';
|
||||||
|
|
||||||
export default (resolver: Resolver, actor, value, distribute?: boolean) => {
|
export default async (parentResolver: Resolver, actor, value, distribute?: boolean) => {
|
||||||
return resolver.resolve(value).then(resolved => Promise.all(resolved.map(async promisedResult => {
|
const collection = await parentResolver.resolveCollection(value);
|
||||||
const result = await promisedResult;
|
|
||||||
const created = await (await createObject(result.resolver, actor, [result.object], distribute))[0];
|
return collection.object.map(async element => {
|
||||||
|
const { resolver, object } = await collection.resolver.resolveOne(element);
|
||||||
|
const created = await (await createObject(resolver, actor, [object], distribute))[0];
|
||||||
|
|
||||||
if (created !== null) {
|
if (created !== null) {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (result.object.type) {
|
switch (object.type) {
|
||||||
case 'Create':
|
case 'Create':
|
||||||
return create(result.resolver, actor, result.object, distribute);
|
return create(resolver, actor, object, distribute);
|
||||||
|
|
||||||
case 'Follow':
|
case 'Follow':
|
||||||
return follow(result.resolver, actor, result.object, distribute);
|
return follow(resolver, actor, object, distribute);
|
||||||
|
|
||||||
case 'Undo':
|
case 'Undo':
|
||||||
return undo(result.resolver, actor, result.object);
|
return undo(resolver, actor, object);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
})));
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,9 +93,19 @@ class Creator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async create(parentResolver, value): Promise<Array<Promise<IRemoteUserObject>>> {
|
public async create(parentResolver, value): Promise<Array<Promise<IRemoteUserObject>>> {
|
||||||
const results = await parentResolver.resolveRemoteUserObjects(value);
|
const collection = await parentResolver.resolveCollection(value);
|
||||||
|
|
||||||
|
return collection.object.map(async element => {
|
||||||
|
if (typeof element === 'string') {
|
||||||
|
const object = RemoteUserObject.findOne({ uri: element });
|
||||||
|
|
||||||
|
if (object !== null) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { resolver, object } = await collection.resolver.resolveOne(element);
|
||||||
|
|
||||||
return results.map(promisedResult => promisedResult.then(({ resolver, object }) => {
|
|
||||||
switch (object.type) {
|
switch (object.type) {
|
||||||
case 'Image':
|
case 'Image':
|
||||||
return this.createImage(object);
|
return this.createImage(object);
|
||||||
|
@ -105,7 +115,7 @@ class Creator {
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
import RemoteUserObject from '../../models/remote-user-object';
|
|
||||||
import { IObject } from './type';
|
|
||||||
const request = require('request-promise-native');
|
const request = require('request-promise-native');
|
||||||
|
|
||||||
type IResult = {
|
|
||||||
resolver: Resolver;
|
|
||||||
object: IObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default class Resolver {
|
export default class Resolver {
|
||||||
private requesting: Set<string>;
|
private requesting: Set<string>;
|
||||||
|
|
||||||
|
@ -42,7 +35,7 @@ export default class Resolver {
|
||||||
return { resolver, object };
|
return { resolver, object };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async resolveCollection(value) {
|
public async resolveCollection(value) {
|
||||||
const resolved = typeof value === 'string' ?
|
const resolved = typeof value === 'string' ?
|
||||||
await this.resolveUnrequestedOne(value) :
|
await this.resolveUnrequestedOne(value) :
|
||||||
{ resolver: this, object: value };
|
{ resolver: this, object: value };
|
||||||
|
@ -66,14 +59,6 @@ export default class Resolver {
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resolve(value): Promise<Array<Promise<IResult>>> {
|
|
||||||
const { resolver, object } = await this.resolveCollection(value);
|
|
||||||
|
|
||||||
return object
|
|
||||||
.filter(element => !resolver.requesting.has(element))
|
|
||||||
.map(resolver.resolveUnrequestedOne.bind(resolver));
|
|
||||||
}
|
|
||||||
|
|
||||||
public resolveOne(value) {
|
public resolveOne(value) {
|
||||||
if (this.requesting.has(value)) {
|
if (this.requesting.has(value)) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
|
@ -81,20 +66,4 @@ export default class Resolver {
|
||||||
|
|
||||||
return this.resolveUnrequestedOne(value);
|
return this.resolveUnrequestedOne(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resolveRemoteUserObjects(value) {
|
|
||||||
const { resolver, object } = await this.resolveCollection(value);
|
|
||||||
|
|
||||||
return object.filter(element => !resolver.requesting.has(element)).map(element => {
|
|
||||||
if (typeof element === 'string') {
|
|
||||||
const object = RemoteUserObject.findOne({ uri: element });
|
|
||||||
|
|
||||||
if (object !== null) {
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolver.resolveUnrequestedOne(element);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue