mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 04:26:58 +00:00
check summary.haveNoteLocally after setting summary.activityPub to improve support for Akkoma
This commit is contained in:
parent
c05aa7a281
commit
70d75f1d57
1 changed files with 11 additions and 14 deletions
|
@ -31,7 +31,7 @@ export type LocalSummalyResult = SummalyResult & {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Increment this to invalidate cached previews after a major change.
|
// Increment this to invalidate cached previews after a major change.
|
||||||
const cacheFormatVersion = 1;
|
const cacheFormatVersion = 2;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UrlPreviewService {
|
export class UrlPreviewService {
|
||||||
|
@ -159,11 +159,11 @@ export class UrlPreviewService {
|
||||||
summary.icon = this.wrap(summary.icon);
|
summary.icon = this.wrap(summary.icon);
|
||||||
summary.thumbnail = this.wrap(summary.thumbnail);
|
summary.thumbnail = this.wrap(summary.thumbnail);
|
||||||
|
|
||||||
|
// Summaly cannot always detect links to a fedi post, so do some additional tests to try and find missed cases.
|
||||||
|
summary.activityPub ??= await this.inferActivityPubLink(summary);
|
||||||
|
|
||||||
if (summary.activityPub) {
|
if (summary.activityPub) {
|
||||||
summary.haveNoteLocally = !!await this.apDbResolverService.getNoteFromApId(summary.activityPub);
|
summary.haveNoteLocally = !!await this.apDbResolverService.getNoteFromApId(summary.activityPub);
|
||||||
} else {
|
|
||||||
// Summaly cannot always detect links to a fedi post, so check if it matches anything we already have
|
|
||||||
await this.inferActivityPubLink(summary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Await this to avoid hammering redis when a bunch of URLs are fetched at once
|
// Await this to avoid hammering redis when a bunch of URLs are fetched at once
|
||||||
|
@ -261,14 +261,12 @@ export class UrlPreviewService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async inferActivityPubLink(summary: LocalSummalyResult) {
|
private async inferActivityPubLink(summary: LocalSummalyResult): Promise<string | null> {
|
||||||
// Match canonical URI first.
|
// Match canonical URI first.
|
||||||
// This covers local and remote links.
|
// This covers local and remote links.
|
||||||
const isCanonicalUri = !!await this.apDbResolverService.getNoteFromApId(summary.url);
|
const isCanonicalUri = !!await this.apDbResolverService.getNoteFromApId(summary.url);
|
||||||
if (isCanonicalUri) {
|
if (isCanonicalUri) {
|
||||||
summary.activityPub = summary.url;
|
return summary.url;
|
||||||
summary.haveNoteLocally = true;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try public URL next.
|
// Try public URL next.
|
||||||
|
@ -286,18 +284,17 @@ export class UrlPreviewService {
|
||||||
// Older versions did not validate URL, so do it now to avoid impersonation.
|
// Older versions did not validate URL, so do it now to avoid impersonation.
|
||||||
const matchByUrl = urlMatches.find(({ uri }) => this.apUtilityService.haveSameAuthority(uri, summary.url));
|
const matchByUrl = urlMatches.find(({ uri }) => this.apUtilityService.haveSameAuthority(uri, summary.url));
|
||||||
if (matchByUrl) {
|
if (matchByUrl) {
|
||||||
summary.activityPub = matchByUrl.uri;
|
return matchByUrl.uri;
|
||||||
summary.haveNoteLocally = true;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, attempt a signed GET in case it's a direct link to an instance with authorized fetch.
|
// Finally, attempt a signed GET in case it's a direct link to an instance with authorized fetch.
|
||||||
const instanceActor = await this.systemAccountService.getInstanceActor();
|
const instanceActor = await this.systemAccountService.getInstanceActor();
|
||||||
const remoteObject = await this.apRequestService.signedGet(summary.url, instanceActor).catch(() => null);
|
const remoteObject = await this.apRequestService.signedGet(summary.url, instanceActor).catch(() => null);
|
||||||
if (remoteObject) {
|
if (remoteObject) {
|
||||||
summary.activityPub = remoteObject.id;
|
return remoteObject.id;
|
||||||
summary.haveNoteLocally = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No match :(
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue