reyserver 1.1.48__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 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/rfile.py CHANGED
@@ -33,7 +33,7 @@ class DatabaseORMTableInfo(rorm.Model, table=True):
33
33
  __name__ = 'info'
34
34
  __comment__ = 'File information table.'
35
35
  create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
36
- file_id: int = rorm.Field(rorm.types_mysql.MEDIUMINT(unsigned=True), key_auto=True, comment='File self increase ID.')
36
+ file_id: int = rorm.Field(rorm.types_mysql.MEDIUMINT(unsigned=True), key_auto=True, comment='File ID.')
37
37
  md5: str = rorm.Field(rorm.types.CHAR(32), not_null=True, index_n=True, comment='File MD5.')
38
38
  name: str = rorm.Field(rorm.types.VARCHAR(260), index_n=True, comment='File name.')
39
39
  note: str = rorm.Field(rorm.types.VARCHAR(500), comment='File note.')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reyserver
3
- Version: 1.1.48
3
+ Version: 1.1.49
4
4
  Summary: Backend server method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reyserver/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -1,11 +1,11 @@
1
1
  reyserver/__init__.py,sha256=7GX64p7uI2eetJH9NJ-DTg-8iyQwOsGcviADFJCPxVA,373
2
2
  reyserver/rall.py,sha256=riyDRTUsigco_Bee1H4aZFb8IgvjnxdX9qcnVb9i9mE,270
3
- reyserver/rauth.py,sha256=QyY4gZ0ulpH9Kxvux_jnZBhzfWZZEuOWB1oYU9uzCnY,167
3
+ reyserver/rauth.py,sha256=VC6Gq2uoiQuON4pmSueZojucU4m2FTdPxLPhGgM4G0A,8390
4
4
  reyserver/rbase.py,sha256=IUVkkNsLmQh-QRLX6qtbCjPZAbQAsxoe0goPLCxG9KA,5283
5
5
  reyserver/rclient.py,sha256=pTJtn78jPKgFo5EoQwZRdM0cYHdCs7QUKqfl-jUBRgk,4220
6
- reyserver/rfile.py,sha256=6Dwq8_X1kiY1n-9RhbLL3hvdhTAnsAUHyXivcviYcoA,8888
6
+ reyserver/rfile.py,sha256=C_kuH9KQS6E5VFDmg_dvbEYfyWxa1hl64fjoh8BFiXQ,8874
7
7
  reyserver/rserver.py,sha256=hqpemzJHO6xHy_7pO3cvvjnfy8Yfqy8HfyIq4sjk4Dc,5889
8
- reyserver-1.1.48.dist-info/METADATA,sha256=T6Q2BrTheAiAziG15T9seCxh_Yi9IRcplL35YTa-wGo,1689
9
- reyserver-1.1.48.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- reyserver-1.1.48.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
11
- reyserver-1.1.48.dist-info/RECORD,,
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,,