-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (83 loc) · 2.96 KB
/
main.py
File metadata and controls
105 lines (83 loc) · 2.96 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from flask import Flask, render_template, abort, redirect
from functions import get_all_repos, search_packages, search_harder
from database import db, Repository
app = Flask(__name__)
app.config["JSONIFY_PRETTYPRINT_REGULAR"] = True
repos = get_all_repos()
@app.route("/")
def home():
"""
Homepage ¯\_(ツ)_/¯
"""
return render_template("home.html")
@app.route("/documentation")
def api_documentaion():
"""
Documentation page ¯\_(ツ)_/¯
"""
return render_template("api_documentation.html", repositories=[{"name": repo.name, "url": f"https://spartacusdev.herokuapp.com/api/{repo.name.replace(' ', '%20')}"} for repo in repos])
@app.route("/<repo_endpoint>")
def wrong_website(repo_endpoint: str):
"""
Redirect to the Cydia repo in case somebody thought this is the repo
"""
if repo_endpoint.lower().startswith("packages") or repo_endpoint.lower().startswith("release") or \
repo_endpoint.lower().startswith("cydiaicon"):
return redirect(f"https://spartacusdev.github.io/{repo_endpoint}")
abort(404)
@app.route("/depictions/<depiction_endpoint>")
def redirect_to_depictions(depiction_endpoint: str):
"""
Redirect to the Cydia repo in case somebody thought this is the repo
"""
return redirect(f"https://spartacusdev.github.io/depictions/{depiction_endpoint}")
@app.route("/SileoDepictions/<depiction_endpoint>")
def redirect_to_sileo_depictions(depiction_endpoint: str):
"""
Redirect to the Cydia repo in case somebody thought this is the repo
"""
return redirect(f"https://spartacusdev.github.io/SileoDepictions/{depiction_endpoint}")
@app.route("/images/<image_endpoint>")
def redirect_to_images(image_endpoint: str):
"""
Redirect to the Cydia repo in case somebody thought this is the repo
"""
return redirect(f"https://spartacusdev.github.io/images/{image_endpoint}")
@app.route("/debs/<deb_endpoint>")
def redirect_to_dbs(deb_endpoint: str):
"""
Redirect to the Cydia repo in case somebody thought this is the repo
"""
return redirect(f"https://spartacusdev.github.io/debs/{deb_endpoint}")
@app.route("/api/search/<package_name>")
def search(package_name: str):
"""
Search packages
"""
package_name = package_name.replace("%20", " ")
return {
"data": search_packages(package_name)
}
@app.route("/api/search_harder/<package_name>")
def find_more_results(package_name: str):
"""
Search packages, but show more results (slower)
"""
package_name = package_name.replace("%20", " ")
return {
"data": search_harder(package_name)
}
@app.route(f"/api/<repo>")
def get_repo(repo: str):
"""
Get all packages from a certain repo
"""
repo = repo.replace("%20", " ")
repo = db.query(Repository).filter(Repository.name.ilike(repo)).first()
if repo is None:
abort(404)
return {
"data": [package.to_dict() for package in repo.packages]
}
if __name__ == "__main__":
app.run()