-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirect.py
More file actions
36 lines (25 loc) · 825 Bytes
/
Copy pathredirect.py
File metadata and controls
36 lines (25 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Blueprint, abort, redirect, render_template, current_app
import json
import functools
import database_helper
redir_page = Blueprint("redirect", __name__)
# Routes
@redir_page.route("/")
def root():
return redirect(current_app.config["DEFAULT_URL"], 301)
@redir_page.route("/<shortcode>")
def target(shortcode):
is_view = False
if shortcode[-1:] == "+":
shortcode = shortcode[:-1]
is_view = True
result = database_helper.get_shortcode_target(shortcode)
if result == None:
return abort(404)
if is_view:
return render_template("index_view.html", shortcode=shortcode, data=result, sitename=current_app.config["SITENAME"])
if result.is_random:
code = 301
else:
code = 307
return redirect(result.target_url, code)