reyserver 1.1.41__py3-none-any.whl → 1.1.42__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/__init__.py +1 -0
- reyserver/rall.py +1 -0
- reyserver/rbase.py +42 -5
- reyserver/rclient.py +45 -0
- reyserver/rfile.py +227 -216
- reyserver/rserver.py +23 -9
- {reyserver-1.1.41.dist-info → reyserver-1.1.42.dist-info}/METADATA +1 -1
- reyserver-1.1.42.dist-info/RECORD +10 -0
- reyserver/rdb.py +0 -12
- reyserver-1.1.41.dist-info/RECORD +0 -10
- {reyserver-1.1.41.dist-info → reyserver-1.1.42.dist-info}/WHEEL +0 -0
- {reyserver-1.1.41.dist-info → reyserver-1.1.42.dist-info}/licenses/LICENSE +0 -0
reyserver/__init__.py
CHANGED
reyserver/rall.py
CHANGED
reyserver/rbase.py
CHANGED
@@ -12,14 +12,18 @@
|
|
12
12
|
from typing import Sequence
|
13
13
|
from inspect import iscoroutinefunction
|
14
14
|
from contextlib import asynccontextmanager
|
15
|
-
from fastapi import FastAPI
|
15
|
+
from fastapi import FastAPI, Depends
|
16
|
+
|
17
|
+
from reydb import DatabaseAsync
|
18
|
+
from reydb.rconn import DatabaseConnectionAsync
|
19
|
+
from reydb.rorm import DatabaseORMSessionAsync
|
16
20
|
from reykit.rbase import CoroutineFunctionSimple, Base, is_iterable
|
17
21
|
|
18
22
|
|
19
23
|
__all__ = (
|
20
24
|
'ServerBase',
|
21
25
|
'ServerAPI',
|
22
|
-
'
|
26
|
+
'create_lifespan'
|
23
27
|
)
|
24
28
|
|
25
29
|
|
@@ -35,12 +39,12 @@ class ServerAPI(ServerBase):
|
|
35
39
|
"""
|
36
40
|
|
37
41
|
|
38
|
-
def
|
42
|
+
def create_lifespan(
|
39
43
|
before: CoroutineFunctionSimple | Sequence[CoroutineFunctionSimple] | None = None,
|
40
44
|
after: CoroutineFunctionSimple | Sequence[CoroutineFunctionSimple] | None = None,
|
41
45
|
):
|
42
46
|
"""
|
43
|
-
|
47
|
+
Create function of lifespan manager.
|
44
48
|
|
45
49
|
Parameters
|
46
50
|
----------
|
@@ -58,7 +62,7 @@ def generate_lifespan(
|
|
58
62
|
elif iscoroutinefunction(after):
|
59
63
|
after = (after,)
|
60
64
|
|
61
|
-
|
65
|
+
|
62
66
|
@asynccontextmanager
|
63
67
|
async def lifespan(app: FastAPI):
|
64
68
|
"""
|
@@ -80,3 +84,36 @@ def generate_lifespan(
|
|
80
84
|
|
81
85
|
|
82
86
|
return lifespan
|
87
|
+
|
88
|
+
|
89
|
+
# def create_depend_conn(db: DatabaseAsync):
|
90
|
+
# """
|
91
|
+
# Create dependencie function of asynchronous database connection.
|
92
|
+
|
93
|
+
# Parameters
|
94
|
+
# ----------
|
95
|
+
# db : Asynchronous database instance.
|
96
|
+
# """
|
97
|
+
|
98
|
+
|
99
|
+
# @asynccontextmanager
|
100
|
+
# async def lifespan(app: FastAPI):
|
101
|
+
# """
|
102
|
+
# Server lifespan manager.
|
103
|
+
|
104
|
+
# Parameters
|
105
|
+
# ----------
|
106
|
+
# app : Server APP.
|
107
|
+
# """
|
108
|
+
|
109
|
+
# # Before.
|
110
|
+
# for task in before:
|
111
|
+
# await task()
|
112
|
+
# yield
|
113
|
+
|
114
|
+
# # After.
|
115
|
+
# for task in after:
|
116
|
+
# await after()
|
117
|
+
|
118
|
+
|
119
|
+
# return lifespan
|
reyserver/rclient.py
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# !/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
"""
|
5
|
+
@Time : 2025-10-09 00:02:09
|
6
|
+
@Author : Rey
|
7
|
+
@Contact : reyxbo@163.com
|
8
|
+
@Explain : Client methods.
|
9
|
+
"""
|
10
|
+
|
11
|
+
|
12
|
+
from rbase import ServerBase
|
13
|
+
|
14
|
+
|
15
|
+
__all__ = (
|
16
|
+
'ServerClient',
|
17
|
+
)
|
18
|
+
|
19
|
+
|
20
|
+
class ServerClient(ServerBase):
|
21
|
+
"""
|
22
|
+
Server client type.
|
23
|
+
"""
|
24
|
+
|
25
|
+
|
26
|
+
def __init__(self, url: str) -> None:
|
27
|
+
"""
|
28
|
+
Build instance attributes.
|
29
|
+
|
30
|
+
Parameters
|
31
|
+
----------
|
32
|
+
url : Server url.
|
33
|
+
"""
|
34
|
+
|
35
|
+
# Build.
|
36
|
+
self.url = url
|
37
|
+
|
38
|
+
|
39
|
+
def upload_file(self): ...
|
40
|
+
|
41
|
+
|
42
|
+
def download_file(self): ...
|
43
|
+
|
44
|
+
|
45
|
+
def index_file(self): ...
|
reyserver/rfile.py
CHANGED
@@ -9,24 +9,21 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from
|
12
|
+
from typing import Annotated
|
13
|
+
from fastapi import APIRouter, Form, File, UploadFile, Depends
|
13
14
|
from reydb import rorm, DatabaseAsync
|
15
|
+
from reykit.ros import FileStore, get_md5
|
14
16
|
|
15
|
-
from . import rserver
|
16
17
|
from .rbase import ServerAPI
|
17
18
|
|
18
19
|
|
19
20
|
__all__ = (
|
20
|
-
'file_router',
|
21
21
|
'DatabaseORMTableInfo',
|
22
22
|
'DatabaseORMTableData',
|
23
|
-
'
|
23
|
+
'ServerAPIFile'
|
24
24
|
)
|
25
25
|
|
26
26
|
|
27
|
-
file_router = APIRouter()
|
28
|
-
|
29
|
-
|
30
27
|
class DatabaseORMTableInfo(rorm.Model, table=True):
|
31
28
|
"""
|
32
29
|
Database `info` table ORM model.
|
@@ -35,7 +32,7 @@ class DatabaseORMTableInfo(rorm.Model, table=True):
|
|
35
32
|
__name__ = 'info'
|
36
33
|
__comment__ = 'File information table.'
|
37
34
|
create_time: rorm.Datetime = rorm.Field(field_default=':create_time', not_null=True, index_n=True, comment='Record create time.')
|
38
|
-
|
35
|
+
file_id: int = rorm.Field(rorm.types_mysql.MEDIUMINT(unsigned=True), key_auto=True, comment='File self increase ID.')
|
39
36
|
md5: str = rorm.Field(rorm.types.CHAR(32), not_null=True, index_n=True, comment='File MD5.')
|
40
37
|
name: str = rorm.Field(rorm.types.VARCHAR(260), index_n=True, comment='File name.')
|
41
38
|
note: str = rorm.Field(rorm.types.VARCHAR(500), comment='File note.')
|
@@ -53,218 +50,232 @@ class DatabaseORMTableData(rorm.Model, table=True):
|
|
53
50
|
path: str = rorm.Field(rorm.types.VARCHAR(4095), not_null=True, comment='File disk storage path.')
|
54
51
|
|
55
52
|
|
56
|
-
|
53
|
+
class ServerAPIFile(ServerAPI):
|
57
54
|
"""
|
58
|
-
|
59
|
-
|
60
|
-
Parameters
|
61
|
-
db : Asynchronous database instance.
|
55
|
+
Server File API type.
|
56
|
+
Can create database used `self.build_db` method.
|
62
57
|
"""
|
63
58
|
|
64
|
-
# Set parameter.
|
65
|
-
database = db.database
|
66
|
-
|
67
|
-
## Table.
|
68
|
-
tables = [DatabaseORMTableInfo, DatabaseORMTableData]
|
69
|
-
|
70
|
-
## View.
|
71
|
-
views = [
|
72
|
-
{
|
73
|
-
'path': 'data_info',
|
74
|
-
'select': (
|
75
|
-
'SELECT `b`.`last_time`, `a`.`md5`, `a`.`size`, `b`.`names`, `b`.`notes`\n'
|
76
|
-
f'FROM `{database}`.`data` AS `a`\n'
|
77
|
-
'LEFT JOIN (\n'
|
78
|
-
' SELECT\n'
|
79
|
-
' `md5`,\n'
|
80
|
-
" GROUP_CONCAT(DISTINCT(`name`) ORDER BY `create_time` DESC SEPARATOR ' | ') AS `names`,\n"
|
81
|
-
" GROUP_CONCAT(DISTINCT(`note`) ORDER BY `create_time` DESC SEPARATOR ' | ') AS `notes`,\n"
|
82
|
-
' MAX(`create_time`) as `last_time`\n'
|
83
|
-
f' FROM `{database}`.`info`\n'
|
84
|
-
' GROUP BY `md5`\n'
|
85
|
-
' ORDER BY `last_time` DESC\n'
|
86
|
-
') AS `b`\n'
|
87
|
-
'ON `a`.`md5` = `b`.`md5`\n'
|
88
|
-
'ORDER BY `last_time` DESC'
|
89
|
-
)
|
90
|
-
}
|
91
|
-
]
|
92
|
-
|
93
|
-
## View stats.
|
94
|
-
views_stats = [
|
95
|
-
{
|
96
|
-
'path': 'stats',
|
97
|
-
'items': [
|
98
|
-
{
|
99
|
-
'name': 'count',
|
100
|
-
'select': (
|
101
|
-
'SELECT COUNT(1)\n'
|
102
|
-
f'FROM `{database}`.`info`'
|
103
|
-
),
|
104
|
-
'comment': 'File information count.'
|
105
|
-
},
|
106
|
-
{
|
107
|
-
'name': 'past_day_count',
|
108
|
-
'select': (
|
109
|
-
'SELECT COUNT(1)\n'
|
110
|
-
f'FROM `{database}`.`info`\n'
|
111
|
-
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
112
|
-
),
|
113
|
-
'comment': 'File information count in the past day.'
|
114
|
-
},
|
115
|
-
{
|
116
|
-
'name': 'past_week_count',
|
117
|
-
'select': (
|
118
|
-
'SELECT COUNT(1)\n'
|
119
|
-
f'FROM `{database}`.`info`\n'
|
120
|
-
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
121
|
-
),
|
122
|
-
'comment': 'File information count in the past week.'
|
123
|
-
},
|
124
|
-
{
|
125
|
-
'name': 'past_month_count',
|
126
|
-
'select': (
|
127
|
-
'SELECT COUNT(1)\n'
|
128
|
-
f'FROM `{database}`.`info`\n'
|
129
|
-
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
130
|
-
),
|
131
|
-
'comment': 'File information count in the past month.'
|
132
|
-
},
|
133
|
-
{
|
134
|
-
'name': 'data_count',
|
135
|
-
'select': (
|
136
|
-
'SELECT COUNT(1)\n'
|
137
|
-
f'FROM `{database}`.`data`'
|
138
|
-
),
|
139
|
-
'comment': 'File data unique count.'
|
140
|
-
},
|
141
|
-
{
|
142
|
-
'name': 'total_size',
|
143
|
-
'select': (
|
144
|
-
'SELECT FORMAT(SUM(`size`), 0)\n'
|
145
|
-
f'FROM `{database}`.`data`'
|
146
|
-
),
|
147
|
-
'comment': 'File total byte size.'
|
148
|
-
},
|
149
|
-
{
|
150
|
-
'name': 'avg_size',
|
151
|
-
'select': (
|
152
|
-
'SELECT FORMAT(AVG(`size`), 0)\n'
|
153
|
-
f'FROM `{database}`.`data`'
|
154
|
-
),
|
155
|
-
'comment': 'File average byte size.'
|
156
|
-
},
|
157
|
-
{
|
158
|
-
'name': 'max_size',
|
159
|
-
'select': (
|
160
|
-
'SELECT FORMAT(MAX(`size`), 0)\n'
|
161
|
-
f'FROM `{database}`.`data`'
|
162
|
-
),
|
163
|
-
'comment': 'File maximum byte size.'
|
164
|
-
},
|
165
|
-
{
|
166
|
-
'name': 'last_time',
|
167
|
-
'select': (
|
168
|
-
'SELECT MAX(`create_time`)\n'
|
169
|
-
f'FROM `{database}`.`info`'
|
170
|
-
),
|
171
|
-
'comment': 'File last record create time.'
|
172
|
-
}
|
173
|
-
]
|
174
|
-
}
|
175
|
-
]
|
176
|
-
|
177
|
-
# Build.
|
178
|
-
db.build.build(tables=tables, views=views, views_stats=views_stats)
|
179
|
-
|
180
|
-
|
181
|
-
@file_router.post('/upload')
|
182
|
-
def upload(
|
183
|
-
source: bytes,
|
184
|
-
name: str | None = None,
|
185
|
-
note: str | None = None
|
186
|
-
) -> int:
|
187
|
-
"""
|
188
|
-
Upload file.
|
189
|
-
|
190
|
-
Parameters
|
191
|
-
----------
|
192
|
-
source : File path or file bytes.
|
193
|
-
name : File name.
|
194
|
-
- `None`: Automatic set.
|
195
|
-
`parameter 'file' is 'str'`: Use path file name.
|
196
|
-
`parameter 'file' is 'bytes'`: No name.
|
197
|
-
- `str`: Use this name.
|
198
|
-
note : File note.
|
199
|
-
|
200
|
-
Returns
|
201
|
-
-------
|
202
|
-
File ID.
|
203
|
-
"""
|
204
59
|
|
205
|
-
|
206
|
-
|
207
|
-
|
60
|
+
def __init__(
|
61
|
+
self,
|
62
|
+
db: DatabaseAsync,
|
63
|
+
path: str = 'file'
|
64
|
+
) -> None:
|
65
|
+
"""
|
66
|
+
Build instance attributes.
|
67
|
+
|
68
|
+
Parameters
|
69
|
+
----------
|
70
|
+
db : Asynchronous database instance.
|
71
|
+
path: File store directory.
|
72
|
+
"""
|
73
|
+
|
74
|
+
# Build.
|
75
|
+
self.db = db
|
76
|
+
self.path = path
|
77
|
+
|
78
|
+
## Router.
|
79
|
+
self.router = self.__create_router()
|
80
|
+
|
81
|
+
## Build Database.
|
82
|
+
self.build_db()
|
208
83
|
|
209
|
-
## File path.
|
210
|
-
case str():
|
211
|
-
file = File(source)
|
212
|
-
file_bytes = file.bytes
|
213
|
-
file_md5 = get_md5(file_bytes)
|
214
|
-
file_name = file.name_suffix
|
215
84
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
85
|
+
async def depend_sess(self):
|
86
|
+
"""
|
87
|
+
Dependencie function of asynchronous database session.
|
88
|
+
"""
|
89
|
+
|
90
|
+
# Context.
|
91
|
+
async with self.db.orm.session() as sess:
|
92
|
+
yield sess
|
93
|
+
|
94
|
+
|
95
|
+
def __create_router(self) -> APIRouter:
|
96
|
+
"""
|
97
|
+
Add APIs to router.
|
98
|
+
|
99
|
+
Returns
|
100
|
+
-------
|
101
|
+
Router.
|
102
|
+
"""
|
103
|
+
|
104
|
+
# Parameter.
|
105
|
+
router = APIRouter()
|
106
|
+
|
107
|
+
|
108
|
+
@router.post('/upload')
|
109
|
+
async def upload(
|
110
|
+
file: Annotated[UploadFile, File()],
|
111
|
+
note: Annotated[str, Form()],
|
112
|
+
sess: Annotated[rorm.DatabaseORMSessionAsync, Depends(self.depend_sess)]
|
113
|
+
):
|
114
|
+
"""
|
115
|
+
Upload file.
|
116
|
+
|
117
|
+
Parameters
|
118
|
+
----------
|
119
|
+
file : File instance.
|
120
|
+
note : File note.
|
121
|
+
sess : Asynchronous database session.
|
122
|
+
"""
|
123
|
+
|
124
|
+
# Handle parameter.
|
125
|
+
file_store = FileStore(self.path)
|
126
|
+
file_name = file.filename
|
127
|
+
file_bytes = await file.read()
|
221
128
|
file_md5 = get_md5(file_bytes)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
129
|
+
file_size = len(file_bytes)
|
130
|
+
|
131
|
+
# Upload.
|
132
|
+
file_path = file_store.index(file_md5)
|
133
|
+
|
134
|
+
## Data.
|
135
|
+
if file_path is None:
|
136
|
+
file_path = file_store.store(file_bytes)
|
137
|
+
table_data = DatabaseORMTableData(
|
138
|
+
md5=file_md5,
|
139
|
+
size=file_size,
|
140
|
+
path=file_path
|
141
|
+
)
|
142
|
+
await sess.add(table_data)
|
143
|
+
|
144
|
+
## Information.
|
145
|
+
table_info = DatabaseORMTableInfo(
|
146
|
+
md5=file_md5,
|
147
|
+
name=file_name,
|
148
|
+
note=note
|
149
|
+
)
|
150
|
+
await sess.add(table_info)
|
151
|
+
|
152
|
+
# Get ID.
|
153
|
+
await sess.flush()
|
154
|
+
file_id = table_info.file_id
|
155
|
+
|
156
|
+
return {'file_id': file_id}
|
157
|
+
|
158
|
+
|
159
|
+
return router
|
160
|
+
|
161
|
+
|
162
|
+
def build_db(self) -> None:
|
163
|
+
"""
|
164
|
+
Check and build database tables.
|
165
|
+
"""
|
166
|
+
|
167
|
+
# Set parameter.
|
168
|
+
database = self.db.database
|
169
|
+
|
170
|
+
## Table.
|
171
|
+
tables = [DatabaseORMTableInfo, DatabaseORMTableData]
|
172
|
+
|
173
|
+
## View.
|
174
|
+
views = [
|
175
|
+
{
|
176
|
+
'path': 'data_info',
|
177
|
+
'select': (
|
178
|
+
'SELECT `b`.`last_time`, `a`.`md5`, `a`.`size`, `b`.`names`, `b`.`notes`\n'
|
179
|
+
f'FROM `{database}`.`data` AS `a`\n'
|
180
|
+
'LEFT JOIN (\n'
|
181
|
+
' SELECT\n'
|
182
|
+
' `md5`,\n'
|
183
|
+
" GROUP_CONCAT(DISTINCT(`name`) ORDER BY `create_time` DESC SEPARATOR ' | ') AS `names`,\n"
|
184
|
+
" GROUP_CONCAT(DISTINCT(`note`) ORDER BY `create_time` DESC SEPARATOR ' | ') AS `notes`,\n"
|
185
|
+
' MAX(`create_time`) as `last_time`\n'
|
186
|
+
f' FROM `{database}`.`info`\n'
|
187
|
+
' GROUP BY `md5`\n'
|
188
|
+
' ORDER BY `last_time` DESC\n'
|
189
|
+
') AS `b`\n'
|
190
|
+
'ON `a`.`md5` = `b`.`md5`\n'
|
191
|
+
'ORDER BY `last_time` DESC'
|
192
|
+
)
|
193
|
+
}
|
194
|
+
]
|
195
|
+
|
196
|
+
## View stats.
|
197
|
+
views_stats = [
|
198
|
+
{
|
199
|
+
'path': 'stats',
|
200
|
+
'items': [
|
201
|
+
{
|
202
|
+
'name': 'count',
|
203
|
+
'select': (
|
204
|
+
'SELECT COUNT(1)\n'
|
205
|
+
f'FROM `{database}`.`info`'
|
206
|
+
),
|
207
|
+
'comment': 'File information count.'
|
208
|
+
},
|
209
|
+
{
|
210
|
+
'name': 'past_day_count',
|
211
|
+
'select': (
|
212
|
+
'SELECT COUNT(1)\n'
|
213
|
+
f'FROM `{database}`.`info`\n'
|
214
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
215
|
+
),
|
216
|
+
'comment': 'File information count in the past day.'
|
217
|
+
},
|
218
|
+
{
|
219
|
+
'name': 'past_week_count',
|
220
|
+
'select': (
|
221
|
+
'SELECT COUNT(1)\n'
|
222
|
+
f'FROM `{database}`.`info`\n'
|
223
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
224
|
+
),
|
225
|
+
'comment': 'File information count in the past week.'
|
226
|
+
},
|
227
|
+
{
|
228
|
+
'name': 'past_month_count',
|
229
|
+
'select': (
|
230
|
+
'SELECT COUNT(1)\n'
|
231
|
+
f'FROM `{database}`.`info`\n'
|
232
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
233
|
+
),
|
234
|
+
'comment': 'File information count in the past month.'
|
235
|
+
},
|
236
|
+
{
|
237
|
+
'name': 'data_count',
|
238
|
+
'select': (
|
239
|
+
'SELECT COUNT(1)\n'
|
240
|
+
f'FROM `{database}`.`data`'
|
241
|
+
),
|
242
|
+
'comment': 'File data unique count.'
|
243
|
+
},
|
244
|
+
{
|
245
|
+
'name': 'total_size',
|
246
|
+
'select': (
|
247
|
+
'SELECT FORMAT(SUM(`size`), 0)\n'
|
248
|
+
f'FROM `{database}`.`data`'
|
249
|
+
),
|
250
|
+
'comment': 'File total byte size.'
|
251
|
+
},
|
252
|
+
{
|
253
|
+
'name': 'avg_size',
|
254
|
+
'select': (
|
255
|
+
'SELECT FORMAT(AVG(`size`), 0)\n'
|
256
|
+
f'FROM `{database}`.`data`'
|
257
|
+
),
|
258
|
+
'comment': 'File average byte size.'
|
259
|
+
},
|
260
|
+
{
|
261
|
+
'name': 'max_size',
|
262
|
+
'select': (
|
263
|
+
'SELECT FORMAT(MAX(`size`), 0)\n'
|
264
|
+
f'FROM `{database}`.`data`'
|
265
|
+
),
|
266
|
+
'comment': 'File maximum byte size.'
|
267
|
+
},
|
268
|
+
{
|
269
|
+
'name': 'last_time',
|
270
|
+
'select': (
|
271
|
+
'SELECT MAX(`create_time`)\n'
|
272
|
+
f'FROM `{database}`.`info`'
|
273
|
+
),
|
274
|
+
'comment': 'File last record create time.'
|
275
|
+
}
|
276
|
+
]
|
277
|
+
}
|
278
|
+
]
|
279
|
+
|
280
|
+
# Build.
|
281
|
+
self.db.sync_database.build.build(tables=tables, views=views, views_stats=views_stats, skip=True)
|
reyserver/rserver.py
CHANGED
@@ -19,7 +19,8 @@ from uvicorn import run as uvicorn_run
|
|
19
19
|
from contextlib import asynccontextmanager
|
20
20
|
from reykit.rbase import CoroutineFunctionSimple
|
21
21
|
|
22
|
-
from .rbase import ServerBase,
|
22
|
+
from .rbase import ServerBase, create_lifespan
|
23
|
+
from .rfile import ServerAPIFile
|
23
24
|
|
24
25
|
|
25
26
|
__all__ = (
|
@@ -57,11 +58,13 @@ class Server(ServerBase):
|
|
57
58
|
# Parameter.
|
58
59
|
if type(ssl_cert) != type(ssl_key):
|
59
60
|
raise
|
60
|
-
lifespan =
|
61
|
-
if
|
61
|
+
lifespan = create_lifespan(before, after)
|
62
|
+
if depend is None:
|
63
|
+
depend = ()
|
64
|
+
elif iscoroutinefunction(depend):
|
62
65
|
depend = (depend,)
|
63
|
-
|
64
|
-
Depends(
|
66
|
+
depend = [
|
67
|
+
Depends(task)
|
65
68
|
for task in depend
|
66
69
|
]
|
67
70
|
|
@@ -71,8 +74,9 @@ class Server(ServerBase):
|
|
71
74
|
|
72
75
|
## App.
|
73
76
|
self.app = FastAPI(
|
74
|
-
dependencies=
|
75
|
-
lifespan=lifespan
|
77
|
+
dependencies=depend,
|
78
|
+
lifespan=lifespan,
|
79
|
+
debug=True
|
76
80
|
)
|
77
81
|
|
78
82
|
## Static.
|
@@ -81,7 +85,7 @@ class Server(ServerBase):
|
|
81
85
|
self.app.mount('/', subapp)
|
82
86
|
|
83
87
|
## Middleware.
|
84
|
-
self.app.add_middleware(GZipMiddleware)
|
88
|
+
# self.app.add_middleware(GZipMiddleware)
|
85
89
|
# self.app.add_middleware(TrustedHostMiddleware)
|
86
90
|
# self.app.add_middleware(HTTPSRedirectMiddleware)
|
87
91
|
|
@@ -99,4 +103,14 @@ class Server(ServerBase):
|
|
99
103
|
)
|
100
104
|
|
101
105
|
|
102
|
-
def
|
106
|
+
def add_api_base(self):
|
107
|
+
|
108
|
+
@self.app.get('/test')
|
109
|
+
async def test():
|
110
|
+
return {'message': 'test'}
|
111
|
+
|
112
|
+
|
113
|
+
def add_api_file(self, db):
|
114
|
+
|
115
|
+
api = ServerAPIFile(db)
|
116
|
+
self.app.include_router(api.router, prefix='/file')
|
@@ -0,0 +1,10 @@
|
|
1
|
+
reyserver/__init__.py,sha256=Zlfm-fsoVNYvVunQwy-ANR6ITAzksCgZzyHazAttXN4,316
|
2
|
+
reyserver/rall.py,sha256=wXhh90tEIqOyM_o2hXs6jWJrRM-B97uHsswhsg4vav0,257
|
3
|
+
reyserver/rbase.py,sha256=v06MgTGPYYx5KVoYPHr2OSIaYpDULggZF1eGZFzrO90,2399
|
4
|
+
reyserver/rclient.py,sha256=B6HOKyTz7kk6IfjuY0Yu-RlvWHRuWXd4zs1cxXud6pk,650
|
5
|
+
reyserver/rfile.py,sha256=sGGGcgzIBnvL45_6WFgH473Jtc_NfyR7ll_b4BiSKRI,9192
|
6
|
+
reyserver/rserver.py,sha256=hMUdILnIUPtqwj7IX022lLsPKAmwppG3_4wOzHfZxDQ,2948
|
7
|
+
reyserver-1.1.42.dist-info/METADATA,sha256=yT9vTRzQI6XpkUqKSvXRYrwjyQ4f57kWKrNLpwT88vc,1658
|
8
|
+
reyserver-1.1.42.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
+
reyserver-1.1.42.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
10
|
+
reyserver-1.1.42.dist-info/RECORD,,
|
reyserver/rdb.py
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
reyserver/__init__.py,sha256=ZNzM6wBvBSXe1LgV40ZJ1WIAbejWNYGl8x22dmt8C60,289
|
2
|
-
reyserver/rall.py,sha256=F-vUJIf5DgP0FXI0pdTrEeEiMtN-g81_yTo4ibUL9xk,233
|
3
|
-
reyserver/rbase.py,sha256=EVLCkX2xdPNdPwkRnZ2ZSjM7kctnMoQ_FSlSNHSZt2E,1630
|
4
|
-
reyserver/rdb.py,sha256=y6GY_G0KYwUqMNVmjs9pu75xNf20uUXRudjbY7c5PTw,201
|
5
|
-
reyserver/rfile.py,sha256=8UqyP12MbMaP-fSCO0a0PxmHyXV49KjM2YvcGaK_BPI,8191
|
6
|
-
reyserver/rserver.py,sha256=97v4zlrjHQcsuCdIdY-wRUGnYrJYdi9rmkCZI1ZRzGw,2620
|
7
|
-
reyserver-1.1.41.dist-info/METADATA,sha256=jVS4d9pHHGkUxHAngUIwUTSkRy9hb5zaFlYYBHG9WcU,1658
|
8
|
-
reyserver-1.1.41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
-
reyserver-1.1.41.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
10
|
-
reyserver-1.1.41.dist-info/RECORD,,
|
File without changes
|
File without changes
|