mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-08-31 22:50:43 +00:00
merge: Fix link verification for actors without a url field (!1180)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1180 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
commit
57d77b8f99
3 changed files with 12 additions and 6 deletions
|
@ -375,7 +375,8 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
||||||
|
|
||||||
const url = this.apUtilityService.findBestObjectUrl(person);
|
const url = this.apUtilityService.findBestObjectUrl(person);
|
||||||
|
|
||||||
const verifiedLinks = url ? await verifyFieldLinks(fields, url, this.httpRequestService) : [];
|
const profileUrls = url ? [url, person.id] : [person.id];
|
||||||
|
const verifiedLinks = await verifyFieldLinks(fields, profileUrls, this.httpRequestService);
|
||||||
|
|
||||||
// Create user
|
// Create user
|
||||||
let user: MiRemoteUser | null = null;
|
let user: MiRemoteUser | null = null;
|
||||||
|
@ -623,7 +624,8 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
||||||
|
|
||||||
const url = this.apUtilityService.findBestObjectUrl(person);
|
const url = this.apUtilityService.findBestObjectUrl(person);
|
||||||
|
|
||||||
const verifiedLinks = url ? await verifyFieldLinks(fields, url, this.httpRequestService) : [];
|
const profileUrls = url ? [url, person.id] : [person.id];
|
||||||
|
const verifiedLinks = await verifyFieldLinks(fields, profileUrls, this.httpRequestService);
|
||||||
|
|
||||||
const updates = {
|
const updates = {
|
||||||
lastFetchedAt: new Date(),
|
lastFetchedAt: new Date(),
|
||||||
|
|
|
@ -8,7 +8,7 @@ import type { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||||
|
|
||||||
type Field = { name: string, value: string };
|
type Field = { name: string, value: string };
|
||||||
|
|
||||||
export async function verifyFieldLinks(fields: Field[], profile_url: string, httpRequestService: HttpRequestService): Promise<string[]> {
|
export async function verifyFieldLinks(fields: Field[], profileUrls: string[], httpRequestService: HttpRequestService): Promise<string[]> {
|
||||||
const verified_links = [];
|
const verified_links = [];
|
||||||
for (const field_url of fields.filter(x => URL.canParse(x.value) && ['http:', 'https:'].includes((new URL(x.value).protocol)))) {
|
for (const field_url of fields.filter(x => URL.canParse(x.value) && ['http:', 'https:'].includes((new URL(x.value).protocol)))) {
|
||||||
try {
|
try {
|
||||||
|
@ -18,7 +18,7 @@ export async function verifyFieldLinks(fields: Field[], profile_url: string, htt
|
||||||
|
|
||||||
const links = doc('a[rel~="me"][href], link[rel~="me"][href]').toArray();
|
const links = doc('a[rel~="me"][href], link[rel~="me"][href]').toArray();
|
||||||
|
|
||||||
const includesProfileLinks = links.some(link => link.attribs.href === profile_url);
|
const includesProfileLinks = links.some(link => profileUrls.includes(link.attribs.href));
|
||||||
if (includesProfileLinks) {
|
if (includesProfileLinks) {
|
||||||
verified_links.push(field_url.value);
|
verified_links.push(field_url.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -615,11 +615,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.globalEventService.publishInternalEvent('localUserUpdated', { id: user.id });
|
this.globalEventService.publishInternalEvent('localUserUpdated', { id: user.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
const verified_links = await verifyFieldLinks(newFields, `${this.config.url}/@${user.username}`, this.httpRequestService);
|
const profileUrls = [
|
||||||
|
this.userEntityService.genLocalUserUri(user.id),
|
||||||
|
`${this.config.url}/@${user.username}`,
|
||||||
|
];
|
||||||
|
const verifiedLinks = await verifyFieldLinks(newFields, profileUrls, this.httpRequestService);
|
||||||
|
|
||||||
await this.userProfilesRepository.update(user.id, {
|
await this.userProfilesRepository.update(user.id, {
|
||||||
...profileUpdates,
|
...profileUpdates,
|
||||||
verifiedLinks: verified_links,
|
verifiedLinks,
|
||||||
});
|
});
|
||||||
|
|
||||||
const iObj = await this.userEntityService.pack(user.id, user, {
|
const iObj = await this.userEntityService.pack(user.id, user, {
|
||||||
|
|
Loading…
Add table
Reference in a new issue