reyserver 1.1.47__py3-none-any.whl → 1.1.49__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reyserver/rauth.py +218 -0
- reyserver/rbase.py +26 -27
- reyserver/rfile.py +4 -6
- {reyserver-1.1.47.dist-info → reyserver-1.1.49.dist-info}/METADATA +1 -1
- reyserver-1.1.49.dist-info/RECORD +11 -0
- reyserver-1.1.47.dist-info/RECORD +0 -11
- {reyserver-1.1.47.dist-info → reyserver-1.1.49.dist-info}/WHEEL +0 -0
- {reyserver-1.1.47.dist-info → reyserver-1.1.49.dist-info}/licenses/LICENSE +0 -0
reyserver/rauth.py
CHANGED
@@ -9,3 +9,221 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
+
from fastapi import APIRouter
|
13
|
+
from reydb import rorm
|
14
|
+
|
15
|
+
from .rbase import ServerConfig, Bind, exit_api
|
16
|
+
|
17
|
+
|
18
|
+
__all__ = (
|
19
|
+
'DatabaseORMTableInfo',
|
20
|
+
'DatabaseORMTableData',
|
21
|
+
'build_file_db',
|
22
|
+
'file_router'
|
23
|
+
)
|
24
|
+
|
25
|
+
|
26
|
+
class DatabaseORMTableUser(rorm.Model, table=True):
|
27
|
+
"""
|
28
|
+
Database `user` table ORM model.
|
29
|
+
"""
|
30
|
+
|
31
|
+
__name__ = 'user'
|
32
|
+
__comment__ = 'User information table.'
|
33
|
+
create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
|
34
|
+
update_time: rorm.Datetime = rorm.Field(field_default=':update_time', not_null=True, index_n=True, comment='Record update time.')
|
35
|
+
user_id: int = rorm.Field(rorm.types_mysql.MEDIUMINT(unsigned=True), key_auto=True, comment='User ID.')
|
36
|
+
name: str = rorm.Field(rorm.types.VARCHAR(50), not_null=True, index_u=True, comment='User name.')
|
37
|
+
password: str
|
38
|
+
email: rorm.Email
|
39
|
+
phone: int
|
40
|
+
head: int
|
41
|
+
is_valid: bool = rorm.Field(rorm.types_mysql.TINYINT(unsigned=True), field_default='1', not_null=True, comment='Is the valid.')
|
42
|
+
|
43
|
+
|
44
|
+
class DatabaseORMTableRole(rorm.Model, table=True):
|
45
|
+
"""
|
46
|
+
Database `role` table ORM model.
|
47
|
+
"""
|
48
|
+
|
49
|
+
__name__ = 'role'
|
50
|
+
__comment__ = 'Role information table.'
|
51
|
+
create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
|
52
|
+
update_time: rorm.Datetime = rorm.Field(field_default=':update_time', not_null=True, index_n=True, comment='Record update time.')
|
53
|
+
role_id: int = rorm.Field(rorm.types_mysql.SMALLINT(unsigned=True), key_auto=True, comment='Role ID.')
|
54
|
+
name: str = rorm.Field(rorm.types.VARCHAR(50), not_null=True, index_u=True, comment='Role name.')
|
55
|
+
desc: str = rorm.Field(rorm.types.VARCHAR(500), comment='Role description.')
|
56
|
+
|
57
|
+
|
58
|
+
class DatabaseORMTablePerm(rorm.Model, table=True):
|
59
|
+
"""
|
60
|
+
Database `perm` table ORM model.
|
61
|
+
"""
|
62
|
+
|
63
|
+
__name__ = 'perm'
|
64
|
+
__comment__ = 'Permission information table.'
|
65
|
+
create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
|
66
|
+
update_time: rorm.Datetime = rorm.Field(field_default=':update_time', not_null=True, index_n=True, comment='Record update time.')
|
67
|
+
perm_id: int = rorm.Field(rorm.types_mysql.SMALLINT(unsigned=True), key_auto=True, comment='Permission ID.')
|
68
|
+
name: str = rorm.Field(rorm.types.VARCHAR(50), not_null=True, index_u=True, comment='Permission name.')
|
69
|
+
desc: str = rorm.Field(rorm.types.VARCHAR(500), comment='Permission description.')
|
70
|
+
code: str
|
71
|
+
|
72
|
+
|
73
|
+
class DatabaseORMTableUserRole(rorm.Model, table=True):
|
74
|
+
"""
|
75
|
+
Database `user_role` table ORM model.
|
76
|
+
"""
|
77
|
+
|
78
|
+
__name__ = 'user_role'
|
79
|
+
__comment__ = 'User and role association table.'
|
80
|
+
create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
|
81
|
+
update_time: rorm.Datetime = rorm.Field(field_default=':update_time', not_null=True, index_n=True, comment='Record update time.')
|
82
|
+
user_id: int = rorm.Field(rorm.types_mysql.MEDIUMINT(unsigned=True), key=True, comment='User ID.')
|
83
|
+
role_id: int = rorm.Field(rorm.types_mysql.SMALLINT(unsigned=True), key=True, comment='Role ID.')
|
84
|
+
|
85
|
+
|
86
|
+
class DatabaseORMTableRolePerm(rorm.Model, table=True):
|
87
|
+
"""
|
88
|
+
Database `role_perm` table ORM model.
|
89
|
+
"""
|
90
|
+
|
91
|
+
__name__ = 'role_perm'
|
92
|
+
__comment__ = 'role and permission association table.'
|
93
|
+
create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
|
94
|
+
update_time: rorm.Datetime = rorm.Field(field_default=':update_time', not_null=True, index_n=True, comment='Record update time.')
|
95
|
+
role_id: int = rorm.Field(rorm.types_mysql.SMALLINT(unsigned=True), key=True, comment='Role ID.')
|
96
|
+
perm_id: int = rorm.Field(rorm.types_mysql.SMALLINT(unsigned=True), key=True, comment='Permission ID.')
|
97
|
+
|
98
|
+
|
99
|
+
def build_file_db() -> None:
|
100
|
+
"""
|
101
|
+
Check and build `file` database tables.
|
102
|
+
"""
|
103
|
+
|
104
|
+
# Set parameter.
|
105
|
+
engine = ServerConfig.server.db.file
|
106
|
+
database = engine.database
|
107
|
+
|
108
|
+
## Table.
|
109
|
+
tables = [
|
110
|
+
DatabaseORMTableUser,
|
111
|
+
DatabaseORMTableRole,
|
112
|
+
DatabaseORMTablePerm,
|
113
|
+
DatabaseORMTableUserRole,
|
114
|
+
DatabaseORMTableRolePerm
|
115
|
+
]
|
116
|
+
|
117
|
+
## View stats.
|
118
|
+
views_stats = [
|
119
|
+
{
|
120
|
+
'path': 'stats',
|
121
|
+
'items': [
|
122
|
+
{
|
123
|
+
'name': 'count',
|
124
|
+
'select': (
|
125
|
+
'SELECT COUNT(1)\n'
|
126
|
+
f'FROM `{database}`.`info`'
|
127
|
+
),
|
128
|
+
'comment': 'File information count.'
|
129
|
+
},
|
130
|
+
{
|
131
|
+
'name': 'past_day_count',
|
132
|
+
'select': (
|
133
|
+
'SELECT COUNT(1)\n'
|
134
|
+
f'FROM `{database}`.`info`\n'
|
135
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
136
|
+
),
|
137
|
+
'comment': 'File information count in the past day.'
|
138
|
+
},
|
139
|
+
{
|
140
|
+
'name': 'past_week_count',
|
141
|
+
'select': (
|
142
|
+
'SELECT COUNT(1)\n'
|
143
|
+
f'FROM `{database}`.`info`\n'
|
144
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
145
|
+
),
|
146
|
+
'comment': 'File information count in the past week.'
|
147
|
+
},
|
148
|
+
{
|
149
|
+
'name': 'past_month_count',
|
150
|
+
'select': (
|
151
|
+
'SELECT COUNT(1)\n'
|
152
|
+
f'FROM `{database}`.`info`\n'
|
153
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
154
|
+
),
|
155
|
+
'comment': 'File information count in the past month.'
|
156
|
+
},
|
157
|
+
{
|
158
|
+
'name': 'data_count',
|
159
|
+
'select': (
|
160
|
+
'SELECT COUNT(1)\n'
|
161
|
+
f'FROM `{database}`.`data`'
|
162
|
+
),
|
163
|
+
'comment': 'File data unique count.'
|
164
|
+
},
|
165
|
+
{
|
166
|
+
'name': 'total_size',
|
167
|
+
'select': (
|
168
|
+
'SELECT FORMAT(SUM(`size`), 0)\n'
|
169
|
+
f'FROM `{database}`.`data`'
|
170
|
+
),
|
171
|
+
'comment': 'File total byte size.'
|
172
|
+
},
|
173
|
+
{
|
174
|
+
'name': 'avg_size',
|
175
|
+
'select': (
|
176
|
+
'SELECT FORMAT(AVG(`size`), 0)\n'
|
177
|
+
f'FROM `{database}`.`data`'
|
178
|
+
),
|
179
|
+
'comment': 'File average byte size.'
|
180
|
+
},
|
181
|
+
{
|
182
|
+
'name': 'max_size',
|
183
|
+
'select': (
|
184
|
+
'SELECT FORMAT(MAX(`size`), 0)\n'
|
185
|
+
f'FROM `{database}`.`data`'
|
186
|
+
),
|
187
|
+
'comment': 'File maximum byte size.'
|
188
|
+
},
|
189
|
+
{
|
190
|
+
'name': 'last_time',
|
191
|
+
'select': (
|
192
|
+
'SELECT MAX(`create_time`)\n'
|
193
|
+
f'FROM `{database}`.`info`'
|
194
|
+
),
|
195
|
+
'comment': 'File last record create time.'
|
196
|
+
}
|
197
|
+
]
|
198
|
+
}
|
199
|
+
]
|
200
|
+
|
201
|
+
# Build.
|
202
|
+
engine.sync_engine.build.build(tables=tables, views=views, views_stats=views_stats, skip=True)
|
203
|
+
|
204
|
+
|
205
|
+
file_router = APIRouter()
|
206
|
+
depend_file_sess = Bind.create_depend_db('file', 'sess')
|
207
|
+
depend_file_conn = Bind.create_depend_db('file', 'conn')
|
208
|
+
|
209
|
+
|
210
|
+
@file_router.post('/')
|
211
|
+
async def upload_file(
|
212
|
+
file: Bind.File = Bind.forms,
|
213
|
+
name: str = Bind.forms_n,
|
214
|
+
note: str = Bind.forms_n,
|
215
|
+
sess: Bind.Sess = depend_file_sess
|
216
|
+
) -> DatabaseORMTableInfo:
|
217
|
+
"""
|
218
|
+
Upload file.
|
219
|
+
|
220
|
+
Parameters
|
221
|
+
----------
|
222
|
+
file : File instance.
|
223
|
+
name : File name.
|
224
|
+
note : File note.
|
225
|
+
|
226
|
+
Returns
|
227
|
+
-------
|
228
|
+
File information.
|
229
|
+
"""
|
reyserver/rbase.py
CHANGED
@@ -9,10 +9,11 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import Sequence, Literal
|
12
|
+
from typing import Sequence, Literal, NoReturn
|
13
13
|
from inspect import iscoroutinefunction
|
14
14
|
from contextlib import asynccontextmanager, _AsyncGeneratorContextManager
|
15
|
-
from
|
15
|
+
from http import HTTPStatus
|
16
|
+
from fastapi import FastAPI, HTTPException, UploadFile as File
|
16
17
|
from fastapi.params import (
|
17
18
|
Depends,
|
18
19
|
Path,
|
@@ -26,7 +27,7 @@ from fastapi.params import (
|
|
26
27
|
from reydb.rconn import DatabaseConnectionAsync
|
27
28
|
from reydb.rorm import DatabaseORMModel, DatabaseORMSessionAsync
|
28
29
|
from reykit.rwrap import wrap_cache
|
29
|
-
from reykit.rbase import CoroutineFunctionSimple, Base, Exit, StaticMeta, ConfigMeta
|
30
|
+
from reykit.rbase import CoroutineFunctionSimple, Base, Exit, StaticMeta, ConfigMeta, throw
|
30
31
|
|
31
32
|
from . import rserver
|
32
33
|
|
@@ -35,10 +36,9 @@ __all__ = (
|
|
35
36
|
'ServerBase',
|
36
37
|
'ServerConfig',
|
37
38
|
'ServerExit',
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'create_depend_sess'
|
39
|
+
'ServerExitAPI',
|
40
|
+
'exit_api',
|
41
|
+
'ServerBind'
|
42
42
|
)
|
43
43
|
|
44
44
|
|
@@ -63,33 +63,32 @@ class ServerExit(ServerBase, Exit):
|
|
63
63
|
"""
|
64
64
|
|
65
65
|
|
66
|
-
class
|
66
|
+
class ServerExitAPI(ServerExit, HTTPException):
|
67
67
|
"""
|
68
|
-
Server
|
68
|
+
Server exit API type.
|
69
69
|
"""
|
70
70
|
|
71
|
-
status_code: int
|
72
71
|
|
73
|
-
|
74
|
-
def __init__(self, text: str | None = None):
|
75
|
-
"""
|
76
|
-
Build instance attributes.
|
77
|
-
|
78
|
-
Parameters
|
79
|
-
----------
|
80
|
-
text : Explain text.
|
81
|
-
"""
|
82
|
-
|
83
|
-
# Super.
|
84
|
-
super().__init__(self.status_code, text)
|
85
|
-
|
86
|
-
|
87
|
-
class ServerExitHTTP404(ServerExitHTTP):
|
72
|
+
def exit_api(code: int = 400, text: str | None = None) -> NoReturn:
|
88
73
|
"""
|
89
|
-
|
74
|
+
Throw exception to exit API.
|
75
|
+
|
76
|
+
Parameters
|
77
|
+
----------
|
78
|
+
code : Response status code.
|
79
|
+
text : Explain text.
|
80
|
+
`None`: Use Default text.
|
90
81
|
"""
|
91
82
|
|
92
|
-
|
83
|
+
# Parameter.
|
84
|
+
if not 400 <= code <= 499:
|
85
|
+
throw(ValueError, code)
|
86
|
+
if text is None:
|
87
|
+
status = HTTPStatus(code)
|
88
|
+
text = status.description
|
89
|
+
|
90
|
+
# Throw exception.
|
91
|
+
raise ServerExitAPI(code, text)
|
93
92
|
|
94
93
|
|
95
94
|
class ServerBind(ServerBase, metaclass=StaticMeta):
|
reyserver/rfile.py
CHANGED
@@ -12,11 +12,9 @@
|
|
12
12
|
from fastapi import APIRouter
|
13
13
|
from fastapi.responses import FileResponse
|
14
14
|
from reydb import rorm
|
15
|
-
from reydb.rorm import DatabaseORMSessionAsync
|
16
|
-
from reydb.rconn import DatabaseConnectionAsync
|
17
15
|
from reykit.ros import FileStore, get_md5
|
18
16
|
|
19
|
-
from .rbase import ServerConfig,
|
17
|
+
from .rbase import ServerConfig, Bind, exit_api
|
20
18
|
|
21
19
|
|
22
20
|
__all__ = (
|
@@ -35,7 +33,7 @@ class DatabaseORMTableInfo(rorm.Model, table=True):
|
|
35
33
|
__name__ = 'info'
|
36
34
|
__comment__ = 'File information table.'
|
37
35
|
create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
|
38
|
-
file_id: int = rorm.Field(rorm.types_mysql.MEDIUMINT(unsigned=True), key_auto=True, comment='File
|
36
|
+
file_id: int = rorm.Field(rorm.types_mysql.MEDIUMINT(unsigned=True), key_auto=True, comment='File ID.')
|
39
37
|
md5: str = rorm.Field(rorm.types.CHAR(32), not_null=True, index_n=True, comment='File MD5.')
|
40
38
|
name: str = rorm.Field(rorm.types.VARCHAR(260), index_n=True, comment='File name.')
|
41
39
|
note: str = rorm.Field(rorm.types.VARCHAR(500), comment='File note.')
|
@@ -268,7 +266,7 @@ async def download_file(
|
|
268
266
|
|
269
267
|
# Check.
|
270
268
|
if result.empty:
|
271
|
-
|
269
|
+
exit_api(404)
|
272
270
|
file_name, file_path = result.first()
|
273
271
|
|
274
272
|
# Response.
|
@@ -299,6 +297,6 @@ async def get_file_info(
|
|
299
297
|
|
300
298
|
# Check.
|
301
299
|
if table_info is None:
|
302
|
-
|
300
|
+
exit_api(404)
|
303
301
|
|
304
302
|
return table_info
|
@@ -0,0 +1,11 @@
|
|
1
|
+
reyserver/__init__.py,sha256=7GX64p7uI2eetJH9NJ-DTg-8iyQwOsGcviADFJCPxVA,373
|
2
|
+
reyserver/rall.py,sha256=riyDRTUsigco_Bee1H4aZFb8IgvjnxdX9qcnVb9i9mE,270
|
3
|
+
reyserver/rauth.py,sha256=VC6Gq2uoiQuON4pmSueZojucU4m2FTdPxLPhGgM4G0A,8390
|
4
|
+
reyserver/rbase.py,sha256=IUVkkNsLmQh-QRLX6qtbCjPZAbQAsxoe0goPLCxG9KA,5283
|
5
|
+
reyserver/rclient.py,sha256=pTJtn78jPKgFo5EoQwZRdM0cYHdCs7QUKqfl-jUBRgk,4220
|
6
|
+
reyserver/rfile.py,sha256=C_kuH9KQS6E5VFDmg_dvbEYfyWxa1hl64fjoh8BFiXQ,8874
|
7
|
+
reyserver/rserver.py,sha256=hqpemzJHO6xHy_7pO3cvvjnfy8Yfqy8HfyIq4sjk4Dc,5889
|
8
|
+
reyserver-1.1.49.dist-info/METADATA,sha256=LnFaa55uE9AkN95GWcvdVCPyIjQjw9S-xh3OE7QOLlo,1689
|
9
|
+
reyserver-1.1.49.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
+
reyserver-1.1.49.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
11
|
+
reyserver-1.1.49.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
reyserver/__init__.py,sha256=7GX64p7uI2eetJH9NJ-DTg-8iyQwOsGcviADFJCPxVA,373
|
2
|
-
reyserver/rall.py,sha256=riyDRTUsigco_Bee1H4aZFb8IgvjnxdX9qcnVb9i9mE,270
|
3
|
-
reyserver/rauth.py,sha256=QyY4gZ0ulpH9Kxvux_jnZBhzfWZZEuOWB1oYU9uzCnY,167
|
4
|
-
reyserver/rbase.py,sha256=nJ0x4hm_YZN210quppSFu_6mRNKDLLNyS27jzSc0Yg8,5220
|
5
|
-
reyserver/rclient.py,sha256=pTJtn78jPKgFo5EoQwZRdM0cYHdCs7QUKqfl-jUBRgk,4220
|
6
|
-
reyserver/rfile.py,sha256=5ynG0LlJLdvNiuFBBBuZhT-0jf_1LxEzac55Q40bsk8,9086
|
7
|
-
reyserver/rserver.py,sha256=hqpemzJHO6xHy_7pO3cvvjnfy8Yfqy8HfyIq4sjk4Dc,5889
|
8
|
-
reyserver-1.1.47.dist-info/METADATA,sha256=gav3pRrTdUZXsbSxo-3JkNjlzhzhasdolU8iywyKQmc,1689
|
9
|
-
reyserver-1.1.47.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
-
reyserver-1.1.47.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
11
|
-
reyserver-1.1.47.dist-info/RECORD,,
|
File without changes
|
File without changes
|