Updated logic for whether a site is recommending you back (#18426)

refs https://github.com/TryGhost/Product/issues/3958

- `url:~a.com` matches a.com, sub.a.com and a.com/path
- added a stricter check based on hostname and pathname, but that
ignores www, protocol, query parameters and hash fragments
This commit is contained in:
Sag 2023-10-02 12:14:59 -03:00 committed by GitHub
parent 043c9bb35d
commit 8ed0c19a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -97,10 +97,8 @@ export class IncomingRecommendationService {
const url = new URL(mention.source.toString().replace(/\/.well-known\/recommendations\.json$/, ''));
// Check if we are also recommending this URL
const existing = await this.#recommendationService.countRecommendations({
filter: `url:~'${url}'`
});
const recommendingBack = existing > 0;
const existing = await this.#recommendationService.readRecommendationByUrl(url);
const recommendingBack = !!existing;
return {
title: mention.sourceTitle,

View File

@ -183,4 +183,13 @@ export class RecommendationService {
const subscribeEvent = SubscribeEvent.create({recommendationId: id, memberId});
await this.subscribeEventRepository.save(subscribeEvent);
}
async readRecommendationByUrl(url: URL): Promise<RecommendationPlain|null> {
const recommendation = await this.repository.getByUrl(url);
if (!recommendation) {
return null;
}
return recommendation.plain;
}
}