mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
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:
parent
043c9bb35d
commit
8ed0c19a1c
2 changed files with 11 additions and 4 deletions
|
@ -97,10 +97,8 @@ export class IncomingRecommendationService {
|
||||||
const url = new URL(mention.source.toString().replace(/\/.well-known\/recommendations\.json$/, ''));
|
const url = new URL(mention.source.toString().replace(/\/.well-known\/recommendations\.json$/, ''));
|
||||||
|
|
||||||
// Check if we are also recommending this URL
|
// Check if we are also recommending this URL
|
||||||
const existing = await this.#recommendationService.countRecommendations({
|
const existing = await this.#recommendationService.readRecommendationByUrl(url);
|
||||||
filter: `url:~'${url}'`
|
const recommendingBack = !!existing;
|
||||||
});
|
|
||||||
const recommendingBack = existing > 0;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: mention.sourceTitle,
|
title: mention.sourceTitle,
|
||||||
|
|
|
@ -183,4 +183,13 @@ export class RecommendationService {
|
||||||
const subscribeEvent = SubscribeEvent.create({recommendationId: id, memberId});
|
const subscribeEvent = SubscribeEvent.create({recommendationId: id, memberId});
|
||||||
await this.subscribeEventRepository.save(subscribeEvent);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue