-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapp.py
85 lines (72 loc) · 3.65 KB
/
app.py
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
import flask
app = flask.Flask(__name__)
app.config['JSON_AS_ASCII'] = False
import json
import webcache
import logging
from util import patchUserData
patchUserData.createDefaultUser()
patchUserData.addAllDailies()
patchUserData.fixQuestAdventures()
from util.homuUtil import startCron
from util import tsurunoUtil as yuitil
app.logger = flask.logging.create_logger(app)
startCron()
from api import arena, friend, gacha, gameUser, logger, money, page, quest, shop, \
user, userCard, userChara, userDeck, userItem, userLive2d, userPiece, userPieceSet, userQuestAdventure, \
userDailyChallenge
app.add_url_rule('/page/<path:endpoint>', view_func=page.handlePage, methods=['GET', 'POST'])
app.add_url_rule('/friend/<path:endpoint>', view_func=friend.handleFriend, methods=['GET', 'POST'])
app.add_url_rule('/gacha/<path:endpoint>', view_func=gacha.handleGacha, methods=['GET', 'POST'])
app.add_url_rule('/money/<path:endpoint>', view_func=money.handleMoney, methods=['GET', 'POST'])
app.add_url_rule('/gameUser/<path:endpoint>', view_func=gameUser.handleGameUser, methods=['GET', 'POST'])
app.add_url_rule('/quest/<path:endpoint>', view_func=quest.handleQuest, methods=['GET', 'POST'])
app.add_url_rule('/shop/<path:endpoint>', view_func=shop.handleShop, methods=['GET', 'POST'])
app.add_url_rule('/arena/<path:endpoint>', view_func=arena.handleArena, methods=['GET', 'POST'])
app.add_url_rule('/user/<path:endpoint>', view_func=user.handleUser, methods=['GET', 'POST'])
app.add_url_rule('/userCard/<path:endpoint>', view_func=userCard.handleUserCard, methods=['GET', 'POST'])
app.add_url_rule('/userChara/<path:endpoint>', view_func=userChara.handleUserChara, methods=['GET', 'POST'])
app.add_url_rule('/userDailyChallenge/<path:endpoint>', view_func=userDailyChallenge.handleDaily, methods=['GET', 'POST'])
app.add_url_rule('/userDeck/<path:endpoint>', view_func=userDeck.handleUserDeck, methods=['GET', 'POST'])
app.add_url_rule('/userItem/<path:endpoint>', view_func=userItem.handleUserItem, methods=['GET', 'POST'])
app.add_url_rule('/userLive2d/<path:endpoint>', view_func=userLive2d.handleUserLive2d, methods=['GET', 'POST'])
app.add_url_rule('/userPiece/<path:endpoint>', view_func=userPiece.handleUserPiece, methods=['GET', 'POST'])
app.add_url_rule('/userPieceSet/<path:endpoint>', view_func=userPieceSet.handleUserPieceSet, methods=['GET', 'POST'])
app.add_url_rule('/userQuestAdventure/<path:endpoint>', view_func=userQuestAdventure.handleUserQuestAdventure, methods=['GET', 'POST'])
app.add_url_rule('/test/logger/error', view_func=logger.handleError, methods=['POST'])
@app.route('/search/<path:endpoint>', methods=['GET', 'POST'])
def dummysearch(endpoint):
return flask.jsonify({
"_shards": {
"failed": 0,
"successful": 0,
"total": 0
},
"hits": {
"hits": [],
"max_score": 0,
"total": 0
},
"timed_out": False,
"took": 2
})
@app.route('/file/<path:path>')
def getFile(path):
return webcache.getFile(path)
@app.before_request
def before():
# no idea why, but flask request is json even for file
if not 'file' in flask.request.path and flask.request.is_json:
app.logger.info(flask.request.json)
@app.after_request
def after(response):
if response is None: return
# binary files, don't log
if not 'file' in flask.request.path \
and not 'page' in flask.request.path: # too long, slows it down a lot with logging
app.logger.info(response.json)
if not 'search' in flask.request.path:
response = yuitil.handleChallenge(response)
return response
if __name__ == "__main__":
app.run(host='127.0.0.1')