change to default functions for resolving collections

This commit is contained in:
Mar0xy 2023-09-22 02:46:41 +02:00
parent 2bfe51e39d
commit 2bcd2eefc1
No known key found for this signature in database
GPG Key ID: 56569BBE47D2C828
1 changed files with 8 additions and 105 deletions

View File

@ -291,55 +291,11 @@ export class ApPersonService implements OnModuleInit {
});
//#endregion
//#region Resolve counts
let followersCount: number | undefined;
if (typeof person.followers === "string") {
try {
this.logger.info(person.followers);
const data = await fetch(person.followers, {
headers: { Accept: "application/json" },
});
const json_data = JSON.parse(await data.text());
followersCount = json_data.totalItems;
} catch {
followersCount = undefined;
}
}
let followingCount: number | undefined;
if (typeof person.following === "string") {
try {
this.logger.info(person.following);
const data = await fetch(person.following, {
headers: { Accept: "application/json" },
});
const json_data = JSON.parse(await data.text());
followingCount = json_data.totalItems;
} catch (e) {
followingCount = undefined;
}
}
let notesCount: number | undefined;
if (typeof person.outbox === "string") {
try {
this.logger.info(person.outbox);
const data = await fetch(person.outbox, {
headers: { Accept: "application/json" },
});
const json_data = JSON.parse(await data.text());
notesCount = json_data.totalItems;
} catch (e) {
notesCount = undefined;
}
}
//#endregion
//#region resolve counts
const _resolver = resolver ?? this.apResolverService.createResolver();
const outboxcollection = await _resolver.resolveCollection(person.outbox);
const followerscollection = await _resolver.resolveCollection(person.followers!);
const followingcollection = await _resolver.resolveCollection(person.following!);
try {
// Start transaction
@ -361,9 +317,9 @@ export class ApPersonService implements OnModuleInit {
host,
inbox: person.inbox,
sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox,
notesCount: notesCount !== undefined ? notesCount : person.outbox && typeof person.outbox !== "string" && isCollectionOrOrderedCollection(person.outbox) ? person.outbox.totalItems : undefined,
followersCount: followersCount !== undefined ? followersCount : person.followers && typeof person.followers !== "string" && isCollectionOrOrderedCollection(person.followers) ? person.followers.totalItems : undefined,
followingCount: followingCount !== undefined ? followingCount : person.following && typeof person.following !== "string" && isCollectionOrOrderedCollection(person.following) ? person.following.totalItems : undefined,
notesCount: outboxcollection.totalItems ?? 0,
followersCount: followerscollection.totalItems ?? 0,
followingCount: followingcollection.totalItems ?? 0,
followersUri: person.followers ? getApId(person.followers) : undefined,
featured: person.featured ? getApId(person.featured) : undefined,
uri: person.id,
@ -493,63 +449,10 @@ export class ApPersonService implements OnModuleInit {
throw new Error('unexpected schema of person url: ' + url);
}
//#region Resolve counts
let followersCount: number | undefined;
if (typeof person.followers === "string") {
try {
this.logger.info(person.followers);
const data = await fetch(person.followers, {
headers: { Accept: "application/json" },
});
const json_data = JSON.parse(await data.text());
followersCount = json_data.totalItems;
} catch {
followersCount = undefined;
}
}
let followingCount: number | undefined;
if (typeof person.following === "string") {
try {
this.logger.info(person.following);
const data = await fetch(person.following, {
headers: { Accept: "application/json" },
});
const json_data = JSON.parse(await data.text());
followingCount = json_data.totalItems;
} catch (e) {
followingCount = undefined;
}
}
let notesCount: number | undefined;
if (typeof person.outbox === "string") {
try {
this.logger.info(person.outbox);
const data = await fetch(person.outbox, {
headers: { Accept: "application/json" },
});
const json_data = JSON.parse(await data.text());
notesCount = json_data.totalItems;
} catch (e) {
notesCount = undefined;
}
}
//#endregion
const updates = {
lastFetchedAt: new Date(),
inbox: person.inbox,
sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox,
notesCount: notesCount !== undefined ? notesCount : person.outbox && typeof person.outbox !== "string" && isCollectionOrOrderedCollection(person.outbox) ? person.outbox.totalItems : undefined,
followersCount: followersCount !== undefined ? followersCount : person.followers && typeof person.followers !== "string" && isCollectionOrOrderedCollection(person.followers) ? person.followers.totalItems : undefined,
followingCount: followingCount !== undefined ? followingCount : person.following && typeof person.following !== "string" && isCollectionOrOrderedCollection(person.following) ? person.following.totalItems : undefined,
followersUri: person.followers ? getApId(person.followers) : undefined,
featured: person.featured,
emojis: emojiNames,