summaryrefslogtreecommitdiff
path: root/src/common/remote
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-01 21:56:11 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-01 21:56:11 +0900
commitcd2c23e3900e4b1ee5f70fdf5dbb6408320c2751 (patch)
tree0ce195e25a18c0f8a3d4129101c9fec3bafb1039 /src/common/remote
parentoops (diff)
downloadsharkey-cd2c23e3900e4b1ee5f70fdf5dbb6408320c2751.tar.gz
sharkey-cd2c23e3900e4b1ee5f70fdf5dbb6408320c2751.tar.bz2
sharkey-cd2c23e3900e4b1ee5f70fdf5dbb6408320c2751.zip
Refactor
Diffstat (limited to 'src/common/remote')
-rw-r--r--src/common/remote/activitypub/resolver.ts92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/common/remote/activitypub/resolver.ts b/src/common/remote/activitypub/resolver.ts
index 43f0d63cb3..a167fa1339 100644
--- a/src/common/remote/activitypub/resolver.ts
+++ b/src/common/remote/activitypub/resolver.ts
@@ -7,68 +7,68 @@ type IResult = {
object: IObject;
};
-async function resolveUnrequestedOne(this: Resolver, value) {
- if (typeof value !== 'string') {
- return { resolver: this, object: value };
+export default class Resolver {
+ private requesting: Set<string>;
+
+ constructor(iterable?: Iterable<string>) {
+ this.requesting = new Set(iterable);
}
- const resolver = new Resolver(this.requesting);
+ private async resolveUnrequestedOne(value) {
+ if (typeof value !== 'string') {
+ return { resolver: this, object: value };
+ }
- resolver.requesting.add(value);
+ const resolver = new Resolver(this.requesting);
- const object = await request({
- url: value,
- headers: {
- Accept: 'application/activity+json, application/ld+json'
- },
- json: true
- });
+ resolver.requesting.add(value);
- if (object === null || (
- Array.isArray(object['@context']) ?
- !object['@context'].includes('https://www.w3.org/ns/activitystreams') :
- object['@context'] !== 'https://www.w3.org/ns/activitystreams'
- )) {
- throw new Error();
- }
+ const object = await request({
+ url: value,
+ headers: {
+ Accept: 'application/activity+json, application/ld+json'
+ },
+ json: true
+ });
- return { resolver, object };
-}
+ if (object === null || (
+ Array.isArray(object['@context']) ?
+ !object['@context'].includes('https://www.w3.org/ns/activitystreams') :
+ object['@context'] !== 'https://www.w3.org/ns/activitystreams'
+ )) {
+ throw new Error();
+ }
-async function resolveCollection(this: Resolver, value) {
- if (Array.isArray(value)) {
- return value;
+ return { resolver, object };
}
- const resolved = typeof value === 'string' ?
- await resolveUnrequestedOne.call(this, value) :
- value;
-
- switch (resolved.type) {
- case 'Collection':
- return resolved.items;
+ private async resolveCollection(value) {
+ if (Array.isArray(value)) {
+ return value;
+ }
- case 'OrderedCollection':
- return resolved.orderedItems;
+ const resolved = typeof value === 'string' ?
+ await this.resolveUnrequestedOne(value) :
+ value;
- default:
- return [resolved];
- }
-}
+ switch (resolved.type) {
+ case 'Collection':
+ return resolved.items;
-export default class Resolver {
- private requesting: Set<string>;
+ case 'OrderedCollection':
+ return resolved.orderedItems;
- constructor(iterable?: Iterable<string>) {
- this.requesting = new Set(iterable);
+ default:
+ return [resolved];
+ }
}
public async resolve(value): Promise<Array<Promise<IResult>>> {
- const collection = await resolveCollection.call(this, value);
+ const collection = await this.resolveCollection(value);
return collection
.filter(element => !this.requesting.has(element))
- .map(resolveUnrequestedOne.bind(this));
+ .map(this.resolveUnrequestedOne.bind(this));
}
public resolveOne(value) {
@@ -76,11 +76,11 @@ export default class Resolver {
throw new Error();
}
- return resolveUnrequestedOne.call(this, value);
+ return this.resolveUnrequestedOne(value);
}
public async resolveRemoteUserObjects(value) {
- const collection = await resolveCollection.call(this, value);
+ const collection = await this.resolveCollection(value);
return collection.filter(element => !this.requesting.has(element)).map(element => {
if (typeof element === 'string') {
@@ -91,7 +91,7 @@ export default class Resolver {
}
}
- return resolveUnrequestedOne.call(this, element);
+ return this.resolveUnrequestedOne(element);
});
}
}