Skip to content

Commit 86df971

Browse files
committed
feat: enhance FeedService to support HTTP and HTTPS URL retrieval with active feed status
1 parent b804031 commit 86df971

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/services/feed/feed.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { In } from 'typeorm';
12
import { AppDataSourceRead, AppDataSourceReadWrite } from '@orm/db';
23
import { Feed } from '@orm/entities/feed/feed';
34
import { FeedFlagStatusStatusEnum } from '@orm/entities/feed/feedFlagStatus';
@@ -48,6 +49,32 @@ export class FeedService {
4849
});
4950
}
5051

52+
async getByUrl(url: string): Promise<Feed | null> {
53+
const base = url.replace(/^https?:\/\//i, '');
54+
const httpsUrl = `https://${base}`;
55+
const httpUrl = `http://${base}`;
56+
57+
const httpsFeed = await this.repositoryRead.findOne({
58+
where: {
59+
url: httpsUrl,
60+
feed_flag_status: In([FeedFlagStatusStatusEnum.Active, FeedFlagStatusStatusEnum.AlwaysParse])
61+
},
62+
relations: ['channel', 'feed_flag_status', 'feed_log'],
63+
});
64+
if (httpsFeed) return httpsFeed;
65+
66+
const httpFeed = await this.repositoryRead.findOne({
67+
where: {
68+
url: httpUrl,
69+
feed_flag_status: In([FeedFlagStatusStatusEnum.Active, FeedFlagStatusStatusEnum.AlwaysParse])
70+
},
71+
relations: ['channel', 'feed_flag_status', 'feed_log'],
72+
});
73+
if (httpFeed) return httpFeed;
74+
75+
return null;
76+
}
77+
5178
async getByUrlAndPodcastIndexId({ url, podcast_index_id }: { url: string, podcast_index_id: number }): Promise<Feed | null> {
5279
return this.repositoryRead.findOne({
5380
where: {
@@ -65,7 +92,8 @@ export class FeedService {
6592
where: {
6693
channel: {
6794
podcast_index_id
68-
}
95+
},
96+
feed_flag_status: In([FeedFlagStatusStatusEnum.Active, FeedFlagStatusStatusEnum.AlwaysParse])
6997
},
7098
relations: ['channel', 'feed_flag_status', 'feed_log'],
7199
});

0 commit comments

Comments
 (0)