Commit a342466 1 parent 04e85db commit a342466 Copy full SHA for a342466
File tree 2 files changed +11
-2
lines changed
2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 3
3
URL pattern is ``/convert/SOURCE/DEST``, where ``SOURCE`` and ``DEST`` are the
4
4
``LABEL`` constants from the :class:`protocol.Protocol` subclasses.
5
5
"""
6
+ from datetime import timedelta
6
7
import logging
7
8
import re
8
9
from urllib .parse import quote , unquote
14
15
15
16
from activitypub import ActivityPub
16
17
from common import (
17
- CACHE_CONTROL_VARY_ACCEPT ,
18
+ CACHE_CONTROL ,
18
19
LOCAL_DOMAINS ,
19
20
subdomain_wrap ,
20
21
SUPERDOMAIN ,
21
22
)
22
23
from flask_app import app
24
+ import memcache
23
25
from models import Object , PROTOCOLS
24
26
from protocol import Protocol
25
27
from web import Web
28
30
29
31
30
32
@app .get (f'/convert/<to>/<path:_>' )
31
- @flask_util .headers (CACHE_CONTROL_VARY_ACCEPT )
33
+ @memcache .memoize (expire = timedelta (hours = 1 ))
34
+ @flask_util .headers (CACHE_CONTROL )
32
35
def convert (to , _ , from_ = None ):
33
36
"""Converts data from one protocol to another and serves it.
34
37
35
38
Fetches the source data if it's not already stored.
36
39
40
+ Note that we don't do conneg or otherwise care about the Accept header here,
41
+ we always serve the "to" protocol's format.
42
+
37
43
Args:
38
44
to (str): protocol
39
45
from_ (str): protocol, only used when called by
Original file line number Diff line number Diff line change 14
14
The conneg makes these ``/r/`` URLs searchable in Mastodon:
15
15
https://github.com/snarfed/bridgy-fed/issues/352
16
16
"""
17
+ from datetime import timedelta
17
18
import logging
18
19
import re
19
20
import urllib .parse
27
28
from activitypub import ActivityPub
28
29
from common import CACHE_CONTROL_VARY_ACCEPT , CONTENT_TYPE_HTML , as2_request_type
29
30
from flask_app import app
31
+ import memcache
30
32
from protocol import Protocol
31
33
from web import Web
32
34
38
40
39
41
40
42
@app .get (r'/r/<path:to>' )
43
+ @memcache .memoize (expire = timedelta (hours = 1 ), key = lambda to : (to , as2_request_type ()))
41
44
@flask_util .headers (CACHE_CONTROL_VARY_ACCEPT )
42
45
def redir (to ):
43
46
"""Either redirect to a given URL or convert it to another format.
You can’t perform that action at this time.
0 commit comments