File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 22from src .anno import router as anno_router
33from src .plan import router as plan_router
44from src .health_check import router as health_check_router
5+ from src .project import router as project_router
56
67app = FastAPI ()
78
89app .include_router (anno_router )
910app .include_router (plan_router )
1011app .include_router (health_check_router )
12+ app .include_router (project_router )
13+
Original file line number Diff line number Diff line change @@ -56,5 +56,21 @@ class Meta:
5656 database = db
5757 table_name = "plan"
5858
59+ class Project (Model ):
60+ type_id = CharField ()
61+ proj_index = IntegerField ()
62+ rid = CharField ()
63+ name = CharField ()
64+ desc = TextField ()
65+ image = TextField ()
66+ url = TextField ()
67+ platform = TextField ()
68+ available = BooleanField ()
69+
70+ class Meta :
71+ database = db
72+ table_name = "project"
73+
5974Anno .create_table ()
6075Plan .create_table ()
76+ Project .create_table ()
Original file line number Diff line number Diff line change 1+ from fastapi import APIRouter
2+ from loguru import logger
3+ from time import time
4+
5+ from src .database import Project
6+
7+ router = APIRouter ()
8+
9+ CacheExpiration = 60 # 秒
10+ project_cache = None
11+
12+
13+ @router .get ("/project" )
14+ async def query_project (type_id : str = "GameTools" ):
15+ logger .debug (f"type_id: { type_id } " )
16+
17+ if not type_id :
18+ logger .error (f"type_id is required" )
19+ return {"ec" : 400 , "msg" : "type_id is required" }
20+
21+ now = time ()
22+ global project_cache
23+ if not project_cache or (now - project_cache [1 ] > CacheExpiration ):
24+ project_cache = (
25+ Project .select ()
26+ .where (
27+ Project .available == True ,
28+ )
29+ .order_by (Project .proj_index ),
30+ now ,
31+ )
32+
33+ data = [
34+ {
35+ "type_id" : p .type_id ,
36+ "resource" : p .rid ,
37+ "name" : p .name ,
38+ "desc" : p .desc ,
39+ "image" : p .image ,
40+ "url" : p .url ,
41+ "support" : [
42+ platform .strip () for platform in p .platform .split ("," ) if platform .strip ()
43+ ],
44+ }
45+ for p in project_cache [0 ]
46+ if p .type_id == type_id
47+ ]
48+
49+ return {"ec" : 200 , "data" : data }
You can’t perform that action at this time.
0 commit comments