forked from kerlomz/captcha_platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.py
154 lines (136 loc) · 5.38 KB
/
constants.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Author: kerlomz <kerlomz@gmail.com>
from enum import Enum, unique
@unique
class ModelScene(Enum):
"""模型场景枚举"""
Classification = 'Classification'
@unique
class ModelField(Enum):
"""模型类别枚举"""
Image = 'Image'
Text = 'Text'
class SystemConfig:
split_flag = b'\x99\x99\x99\x00\xff\xff\xff\x00\x99\x99\x99'
default_route = [
{
"Class": "AuthHandler",
"Route": "/captcha/auth/v2"
},
{
"Class": "NoAuthHandler",
"Route": "/captcha/v1"
},
{
"Class": "SimpleHandler",
"Route": "/captcha/v3"
},
{
"Class": "HeartBeatHandler",
"Route": "/check_backend_active.html"
},
{
"Class": "HeartBeatHandler",
"Route": "/verification"
},
{
"Class": "HeartBeatHandler",
"Route": "/"
},
{
"Class": "ServiceHandler",
"Route": "/service/info"
},
{
"Class": "FileHandler",
"Route": "/service/logs/(.*)",
"Param": {"path": "logs"}
},
{
"Class": "BaseHandler",
"Route": ".*"
}
]
default_config = {
"System": {
"DefaultModel": "default",
"SplitFlag": b'\x99\x99\x99\x00\xff\xff999999.........99999\xff\x00\x99\x99\x99',
"SavePath": "",
"RequestCountInterval": 86400,
"GlobalRequestCountInterval": 86400,
"RequestLimit": -1,
"GlobalRequestLimit": -1,
"WithoutLogger": False,
"RequestSizeLimit": {},
"DefaultPort": 19952,
"IllegalTimeMessage": "The maximum number of requests has been exceeded.",
"ExceededMessage": "Illegal access time, please request in open hours.",
"BlacklistTriggerTimes": -1,
"Whitelist": False,
"ErrorMessage": {
400: "Bad Request",
401: "Unicode Decode Error",
403: "Forbidden",
404: "404 Not Found",
405: "Method Not Allowed",
500: "Internal Server Error"
}
},
"RouteMap": default_route,
"Security": {
"AccessKey": "",
"SecretKey": ""
},
"RequestDef": {
"InputData": "image",
"ModelName": "model_name",
},
"ResponseDef": {
"Message": "message",
"StatusCode": "code",
"StatusBool": "success",
"Uid": "uid",
}
}
class ServerType(str):
FLASK = 19951
TORNADO = 19952
SANIC = 19953
class Response:
def __init__(self, def_map: dict):
# SIGN
self.INVALID_PUBLIC_PARAMS = dict(Message='Invalid Public Params', StatusCode=400001, StatusBool=False)
self.UNKNOWN_SERVER_ERROR = dict(Message='Unknown Server Error', StatusCode=400002, StatusBool=False)
self.INVALID_TIMESTAMP = dict(Message='Invalid Timestamp', StatusCode=400004, StatusBool=False)
self.INVALID_ACCESS_KEY = dict(Message='Invalid Access Key', StatusCode=400005, StatusBool=False)
self.INVALID_QUERY_STRING = dict(Message='Invalid Query String', StatusCode=400006, StatusBool=False)
# SERVER
self.SUCCESS = dict(Message=None, StatusCode=000000, StatusBool=True)
self.INVALID_IMAGE_FORMAT = dict(Message='Invalid Image Format', StatusCode=500001, StatusBool=False)
self.INVALID_BASE64_STRING = dict(Message='Invalid Base64 String', StatusCode=500002, StatusBool=False)
self.IMAGE_DAMAGE = dict(Message='Image Damage', StatusCode=500003, StatusBool=False)
self.IMAGE_SIZE_NOT_MATCH_GRAPH = dict(Message='Image Size Not Match Graph Value', StatusCode=500004, StatusBool=False)
self.INVALID_PUBLIC_PARAMS = self.parse(self.INVALID_PUBLIC_PARAMS, def_map)
self.UNKNOWN_SERVER_ERROR = self.parse(self.UNKNOWN_SERVER_ERROR, def_map)
self.INVALID_TIMESTAMP = self.parse(self.INVALID_TIMESTAMP, def_map)
self.INVALID_ACCESS_KEY = self.parse(self.INVALID_ACCESS_KEY, def_map)
self.INVALID_QUERY_STRING = self.parse(self.INVALID_QUERY_STRING, def_map)
self.SUCCESS = self.parse(self.SUCCESS, def_map)
self.INVALID_IMAGE_FORMAT = self.parse(self.INVALID_IMAGE_FORMAT, def_map)
self.INVALID_BASE64_STRING = self.parse(self.INVALID_BASE64_STRING, def_map)
self.IMAGE_DAMAGE = self.parse(self.IMAGE_DAMAGE, def_map)
self.IMAGE_SIZE_NOT_MATCH_GRAPH = self.parse(self.IMAGE_SIZE_NOT_MATCH_GRAPH, def_map)
def find_message(self, _code):
e = [value for value in vars(self).values()]
_t = [i['message'] for i in e if i['code'] == _code]
return _t[0] if _t else None
def find(self, _code):
e = [value for value in vars(self).values()]
_t = [i for i in e if i['code'] == _code]
return _t[0] if _t else None
def all_code(self):
return [i['message'] for i in [value for value in vars(self).values()]]
@staticmethod
def parse(src: dict, target_map: dict):
return {target_map[k]: v for k, v in src.items()}