mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-24 04:13:09 +02:00
upd: fetch counts for notes, followers and following
This commit is contained in:
parent
57c37a8938
commit
2bfe51e39d
1 changed files with 106 additions and 0 deletions
|
@ -291,6 +291,56 @@ export class ApPersonService implements OnModuleInit {
|
||||||
});
|
});
|
||||||
//#endregion
|
//#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
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Start transaction
|
// Start transaction
|
||||||
await this.db.transaction(async transactionalEntityManager => {
|
await this.db.transaction(async transactionalEntityManager => {
|
||||||
|
@ -311,6 +361,9 @@ export class ApPersonService implements OnModuleInit {
|
||||||
host,
|
host,
|
||||||
inbox: person.inbox,
|
inbox: person.inbox,
|
||||||
sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox,
|
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,
|
followersUri: person.followers ? getApId(person.followers) : undefined,
|
||||||
featured: person.featured ? getApId(person.featured) : undefined,
|
featured: person.featured ? getApId(person.featured) : undefined,
|
||||||
uri: person.id,
|
uri: person.id,
|
||||||
|
@ -440,10 +493,63 @@ export class ApPersonService implements OnModuleInit {
|
||||||
throw new Error('unexpected schema of person url: ' + url);
|
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 = {
|
const updates = {
|
||||||
lastFetchedAt: new Date(),
|
lastFetchedAt: new Date(),
|
||||||
inbox: person.inbox,
|
inbox: person.inbox,
|
||||||
sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox,
|
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,
|
followersUri: person.followers ? getApId(person.followers) : undefined,
|
||||||
featured: person.featured,
|
featured: person.featured,
|
||||||
emojis: emojiNames,
|
emojis: emojiNames,
|
||||||
|
|
Loading…
Reference in a new issue