Merge branch 'develop' of codeberg.org:calckey/calckey into develop
This commit is contained in:
commit
964bc9708a
2 changed files with 78 additions and 4 deletions
|
@ -488,8 +488,8 @@ export const UserRepository = db.getRepository(User).extend({
|
||||||
birthday: profile!.birthday,
|
birthday: profile!.birthday,
|
||||||
lang: profile!.lang,
|
lang: profile!.lang,
|
||||||
fields: profile!.fields,
|
fields: profile!.fields,
|
||||||
followersCount: followersCount || 0,
|
followersCount: followersCount || '?',
|
||||||
followingCount: followingCount || 0,
|
followingCount: followingCount || '?',
|
||||||
notesCount: user.notesCount,
|
notesCount: user.notesCount,
|
||||||
pinnedNoteIds: pins.map((pin) => pin.noteId),
|
pinnedNoteIds: pins.map((pin) => pin.noteId),
|
||||||
pinnedNotes: Notes.packMany(
|
pinnedNotes: Notes.packMany(
|
||||||
|
|
|
@ -198,9 +198,36 @@ export async function createPerson(
|
||||||
const url = getOneApHrefNullable(person.url);
|
const url = getOneApHrefNullable(person.url);
|
||||||
|
|
||||||
if (url && !url.startsWith("https://")) {
|
if (url && !url.startsWith("https://")) {
|
||||||
throw new Error(`unexpected shcema of person url: ${url}`);
|
throw new Error(`unexpected schema of person url: ${url}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let followersCount: number | undefined;
|
||||||
|
|
||||||
|
if (typeof person.followers === "string") {
|
||||||
|
try {
|
||||||
|
let data = await fetch(person.followers, { headers: { "Accept": "application/json" } });
|
||||||
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
followersCount = json_data.totalItems;
|
||||||
|
} catch {
|
||||||
|
followersCount = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let followingCount: number | undefined;
|
||||||
|
|
||||||
|
if (typeof person.following === "string") {
|
||||||
|
try {
|
||||||
|
let data = await fetch(person.following, { headers: { "Accept": "application/json" } });
|
||||||
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
followingCount = json_data.totalItems;
|
||||||
|
} catch (e) {
|
||||||
|
followingCount = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create user
|
// Create user
|
||||||
let user: IRemoteUser;
|
let user: IRemoteUser;
|
||||||
try {
|
try {
|
||||||
|
@ -228,6 +255,16 @@ export async function createPerson(
|
||||||
followersUri: person.followers
|
followersUri: person.followers
|
||||||
? getApId(person.followers)
|
? getApId(person.followers)
|
||||||
: undefined,
|
: 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,
|
||||||
featured: person.featured ? getApId(person.featured) : undefined,
|
featured: person.featured ? getApId(person.featured) : undefined,
|
||||||
uri: person.id,
|
uri: person.id,
|
||||||
tags,
|
tags,
|
||||||
|
@ -396,7 +433,34 @@ export async function updatePerson(
|
||||||
const url = getOneApHrefNullable(person.url);
|
const url = getOneApHrefNullable(person.url);
|
||||||
|
|
||||||
if (url && !url.startsWith("https://")) {
|
if (url && !url.startsWith("https://")) {
|
||||||
throw new Error(`unexpected shcema of person url: ${url}`);
|
throw new Error(`unexpected schema of person url: ${url}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let followersCount: number | undefined;
|
||||||
|
|
||||||
|
if (typeof person.followers === "string") {
|
||||||
|
try {
|
||||||
|
let data = await fetch(person.followers, { headers: { "Accept": "application/json" } } );
|
||||||
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
followersCount = json_data.totalItems;
|
||||||
|
} catch {
|
||||||
|
followersCount = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let followingCount: number | undefined;
|
||||||
|
|
||||||
|
if (typeof person.following === "string") {
|
||||||
|
try {
|
||||||
|
let data = await fetch(person.following, { headers: { "Accept": "application/json" } } );
|
||||||
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
followingCount = json_data.totalItems;
|
||||||
|
} catch {
|
||||||
|
followingCount = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updates = {
|
const updates = {
|
||||||
|
@ -406,6 +470,16 @@ export async function updatePerson(
|
||||||
person.sharedInbox ||
|
person.sharedInbox ||
|
||||||
(person.endpoints ? person.endpoints.sharedInbox : undefined),
|
(person.endpoints ? person.endpoints.sharedInbox : undefined),
|
||||||
followersUri: person.followers ? getApId(person.followers) : undefined,
|
followersUri: person.followers ? getApId(person.followers) : 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,
|
||||||
featured: person.featured,
|
featured: person.featured,
|
||||||
emojis: emojiNames,
|
emojis: emojiNames,
|
||||||
name: truncate(person.name, nameLength),
|
name: truncate(person.name, nameLength),
|
||||||
|
|
Loading…
Reference in a new issue