Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…q=#TAG

for #1634, thanks @Tamschi!
  • Loading branch information
snarfed committed Dec 20, 2024
1 parent 572ca2c commit f7bf986
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
20 changes: 16 additions & 4 deletions atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
import brevity
import dag_json
from flask import abort, request
from flask import abort, redirect, request
from google.cloud import dns
from google.cloud.dns.resource_record_set import ResourceRecordSet
from google.cloud import ndb
Expand All @@ -36,9 +36,11 @@
from oauth_dropins.webutil import util
from oauth_dropins.webutil.appengine_config import ndb_client
from oauth_dropins.webutil.appengine_info import DEBUG
from oauth_dropins.webutil.flask_util import cloud_tasks_only, get_required_param
from oauth_dropins.webutil import flask_util
from oauth_dropins.webutil.flask_util import get_required_param
from oauth_dropins.webutil.models import StringIdModel
from oauth_dropins.webutil.util import add, json_dumps, json_loads
from werkzeug.exceptions import NotFound

import common
from common import (
Expand All @@ -50,7 +52,7 @@
SUPERDOMAIN,
USER_AGENT,
)
import flask_app
from flask_app import app
import ids
from models import Follower, Object, PROTOCOLS, Target, User
from protocol import Protocol
Expand Down Expand Up @@ -1054,7 +1056,7 @@ def send_chat(*, msg, from_repo, to_did):
return True


@cloud_tasks_only(log=False)
@flask_util.cloud_tasks_only(log=False)
def poll_chat_task():
"""Polls for incoming chat messages for our protocol bot users.
Expand Down Expand Up @@ -1106,3 +1108,13 @@ def poll_chat_task():
# done!
bot.put()
return 'OK'


@app.get(f'/hashtag/<hashtag>')
@flask_util.headers(common.CACHE_CONTROL)
def hashtag_redirect(hashtag):
if (util.domain_from_link(request.host_url) ==
f'{ATProto.ABBREV}{common.SUPERDOMAIN}'):
return redirect(f'https://bsky.app/search?q=%23{hashtag}')

raise NotFound()
13 changes: 13 additions & 0 deletions tests/test_atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2697,3 +2697,16 @@ def test_poll_atproto_chat_messages(self, mock_get, mock_create_task):
received_at='1900-04-04T00:04:04Z')

self.assertEqual('dunn', fa.key.get().atproto_last_chat_log_cursor)

def test_hashtag_redirect(self):
resp = self.get('/hashtag/foo', base_url='https://bsky.brid.gy')
self.assert_equals(302, resp.status_code)
self.assert_equals('https://bsky.app/search?q=%23foo',
resp.headers['Location'])

# only on bsky subdomain
resp = self.get('/hashtag/foo')
self.assert_equals(404, resp.status_code)

resp = self.get('/hashtag/foo', base_url='https://web.brid.gy')
self.assert_equals(404, resp.status_code)

0 comments on commit f7bf986

Please sign in to comment.