forked from FoundKeyGang/FoundKey
server: use extractDbHost instead of toPuny, translate comments
Also swapped logical or for nullish coalescing operator in some places.
This commit is contained in:
parent
ef53ec276a
commit
16d091497a
1 changed files with 12 additions and 14 deletions
|
@ -13,7 +13,7 @@ import { genId } from '@/misc/gen-id.js';
|
||||||
import { instanceChart, usersChart } from '@/services/chart/index.js';
|
import { instanceChart, usersChart } from '@/services/chart/index.js';
|
||||||
import { UserPublickey } from '@/models/entities/user-publickey.js';
|
import { UserPublickey } from '@/models/entities/user-publickey.js';
|
||||||
import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error.js';
|
import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error.js';
|
||||||
import { toPuny } from '@/misc/convert-host.js';
|
import { extractDbHost } from '@/misc/convert-host.js';
|
||||||
import { UserProfile } from '@/models/entities/user-profile.js';
|
import { UserProfile } from '@/models/entities/user-profile.js';
|
||||||
import { toArray } from '@/prelude/array.js';
|
import { toArray } from '@/prelude/array.js';
|
||||||
import { fetchInstanceMetadata } from '@/services/fetch-instance-metadata.js';
|
import { fetchInstanceMetadata } from '@/services/fetch-instance-metadata.js';
|
||||||
|
@ -86,7 +86,7 @@ function validateActor(x: IObject): IActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
const expectHost = extractDbHost(uri);
|
const expectHost = extractDbHost(uri);
|
||||||
const publicKeyIdHost = toPuny(new URL(x.publicKey.id).hostname);
|
const publicKeyIdHost = extractDbHost(x.publicKey.id);
|
||||||
if (publicKeyIdHost !== expectHost) {
|
if (publicKeyIdHost !== expectHost) {
|
||||||
throw new Error('invalid Actor: publicKey.id has different host');
|
throw new Error('invalid Actor: publicKey.id has different host');
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ export async function createPerson(uri: string, resolver: Resolver): Promise<Use
|
||||||
|
|
||||||
apLogger.info(`Creating the Person: ${person.id}`);
|
apLogger.info(`Creating the Person: ${person.id}`);
|
||||||
|
|
||||||
const host = toPuny(new URL(object.id).hostname);
|
const host = extractDbHost(object.id);
|
||||||
|
|
||||||
const { fields } = analyzeAttachments(person.attachment || []);
|
const { fields } = analyzeAttachments(person.attachment || []);
|
||||||
|
|
||||||
|
@ -279,18 +279,17 @@ export async function createPerson(uri: string, resolver: Resolver): Promise<Use
|
||||||
export async function updatePerson(value: IObject | string, resolver: Resolver): Promise<void> {
|
export async function updatePerson(value: IObject | string, resolver: Resolver): Promise<void> {
|
||||||
const uri = getApId(value);
|
const uri = getApId(value);
|
||||||
|
|
||||||
// URIがこのサーバーを指しているならスキップ
|
// skip local URIs
|
||||||
if (uri.startsWith(config.url + '/')) {
|
if (uri.startsWith(config.url)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//#region このサーバーに既に登録されているか
|
// do we already know this user?
|
||||||
const exist = await Users.findOneBy({ uri }) as IRemoteUser;
|
const exist = await Users.findOneBy({ uri }) as IRemoteUser;
|
||||||
|
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//#endregion
|
|
||||||
|
|
||||||
const object = await resolver.resolve(value);
|
const object = await resolver.resolve(value);
|
||||||
|
|
||||||
|
@ -298,7 +297,7 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
|
||||||
|
|
||||||
apLogger.info(`Updating the Person: ${person.id}`);
|
apLogger.info(`Updating the Person: ${person.id}`);
|
||||||
|
|
||||||
// アバターとヘッダー画像をフェッチ
|
// Fetch avatar and banner image
|
||||||
const [avatar, banner] = await Promise.all([
|
const [avatar, banner] = await Promise.all([
|
||||||
person.icon,
|
person.icon,
|
||||||
person.image,
|
person.image,
|
||||||
|
@ -308,7 +307,7 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
|
||||||
: resolveImage(exist, img, resolver).catch(() => null),
|
: resolveImage(exist, img, resolver).catch(() => null),
|
||||||
));
|
));
|
||||||
|
|
||||||
// カスタム絵文字取得
|
// Get custom emoji
|
||||||
const emojis = await extractEmojis(person.tag || [], exist.host).catch(e => {
|
const emojis = await extractEmojis(person.tag || [], exist.host).catch(e => {
|
||||||
apLogger.info(`extractEmojis: ${e}`);
|
apLogger.info(`extractEmojis: ${e}`);
|
||||||
return [] as Emoji[];
|
return [] as Emoji[];
|
||||||
|
@ -316,7 +315,7 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
|
||||||
|
|
||||||
const emojiNames = emojis.map(emoji => emoji.name);
|
const emojiNames = emojis.map(emoji => emoji.name);
|
||||||
|
|
||||||
const { fields } = analyzeAttachments(person.attachment || []);
|
const { fields } = analyzeAttachments(person.attachment ?? []);
|
||||||
|
|
||||||
const tags = extractApHashtags(person.tag).map(tag => normalizeForSearch(tag)).splice(0, 32);
|
const tags = extractApHashtags(person.tag).map(tag => normalizeForSearch(tag)).splice(0, 32);
|
||||||
|
|
||||||
|
@ -325,7 +324,7 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
|
||||||
const updates = {
|
const updates = {
|
||||||
lastFetchedAt: new Date(),
|
lastFetchedAt: new Date(),
|
||||||
inbox: person.inbox,
|
inbox: person.inbox,
|
||||||
sharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined),
|
sharedInbox: person.sharedInbox ?? (person.endpoints ? person.endpoints.sharedInbox : 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,
|
||||||
|
@ -365,14 +364,13 @@ export async function updatePerson(value: IObject | string, resolver: Resolver):
|
||||||
|
|
||||||
publishInternalEvent('remoteUserUpdated', { id: exist.id });
|
publishInternalEvent('remoteUserUpdated', { id: exist.id });
|
||||||
|
|
||||||
// ハッシュタグ更新
|
|
||||||
updateUsertags(exist, tags);
|
updateUsertags(exist, tags);
|
||||||
|
|
||||||
// 該当ユーザーが既にフォロワーになっていた場合はFollowingもアップデートする
|
// If the user in question is already a follower, followers will also be updated.
|
||||||
await Followings.update({
|
await Followings.update({
|
||||||
followerId: exist.id,
|
followerId: exist.id,
|
||||||
}, {
|
}, {
|
||||||
followerSharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined),
|
followerSharedInbox: person.sharedInbox ?? (person.endpoints ? person.endpoints.sharedInbox : undefined),
|
||||||
});
|
});
|
||||||
|
|
||||||
await updateFeatured(exist.id, resolver).catch(err => apLogger.error(err));
|
await updateFeatured(exist.id, resolver).catch(err => apLogger.error(err));
|
||||||
|
|
Loading…
Reference in a new issue