feat: Add feed source filtering to settings and API

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-01-03 00:01:46 +00:00
parent 93903eedf9
commit ab15868397
3 changed files with 72 additions and 18 deletions

View File

@@ -76,8 +76,12 @@ cors = CORS(flask_app)
def api():
skip = request.args.get('skip', 0)
limit = request.args.get('limit', settings.FEED_LENGTH)
is_smallweb_filter = request.args.get('smallweb') == 'true' and smallweb_set
sources_filter = request.args.getlist('source')
if request.args.get('smallweb') == 'true' and smallweb_set:
if not is_smallweb_filter and not sources_filter:
stories = database.get_stories(limit, skip)
else:
limit = int(limit)
skip = int(skip)
filtered_stories = []
@@ -90,24 +94,28 @@ def api():
for story_str in stories_batch:
story = json.loads(story_str)
story_url = story.get('url') or story.get('link') or ''
if not story_url:
continue
hostname = urlparse(story_url).hostname
if hostname:
hostname = hostname.replace('www.', '')
if hostname in smallweb_set:
filtered_stories.append(story_str)
if len(filtered_stories) == limit:
break
if is_smallweb_filter:
story_url = story.get('url') or story.get('link') or ''
if not story_url:
continue
hostname = urlparse(story_url).hostname
if not hostname or hostname.replace('www.', '') not in smallweb_set:
continue
if sources_filter:
if story.get('source') not in sources_filter:
continue
filtered_stories.append(story_str)
if len(filtered_stories) == limit:
break
if len(filtered_stories) == limit:
break
current_skip += limit
stories = filtered_stories
else:
stories = database.get_stories(limit, skip)
# hacky nested json
res = Response('{"stories":[' + ','.join(stories) + ']}')