Skip to content

Commit 9ec62e8

Browse files
committed
fix: 修复漏洞
1 parent 996f23f commit 9ec62e8

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

core/orm.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,24 @@ def fetchData(base_time: datetime) -> List[Dict[str, int]]:
6060
timestamps = [
6161
int((base_time + timedelta(hours=i)).timestamp()) for i in range(24)
6262
] + [int((base_time.replace(hour=1) + timedelta(days=1)).timestamp())]
63+
6364
return [
6465
{
6566
"hits": sum(item.hits for item in query) if query else 0,
6667
"bytes": sum(item.bytes for item in query) if query else 0,
6768
}
6869
for i in range(24)
69-
if (
70-
query := session.execute(
70+
for query in [
71+
session.execute(
7172
select(HitsInfo).where(
7273
HitsInfo.time >= timestamps[i],
7374
HitsInfo.time < timestamps[i + 1],
7475
)
75-
)
76-
.scalars()
77-
.all()
78-
)
76+
).scalars().all()
77+
]
7978
]
8079

80+
8181
current = datetime.now().replace(hour=1, minute=0, second=0, microsecond=0)
8282
previous = current - timedelta(days=1)
8383
return {"stats": fetchData(current), "prevStats": fetchData(previous)}
@@ -87,25 +87,23 @@ def getDailyHits() -> Dict[str, List[Dict[str, int]]]:
8787
def fetchData(year: int, month: int, total_days: int) -> List[Dict[str, int]]:
8888
return [
8989
{
90-
"hits": sum(item.hits for item in query) if query else 0,
91-
"bytes": sum(item.bytes for item in query) if query else 0,
90+
"hits": sum(item.hits for item in query),
91+
"bytes": sum(item.bytes for item in query),
9292
}
9393
for day in range(1, total_days + 1)
94-
if (
95-
query := session.execute(
94+
for query in [
95+
session.execute(
9696
select(HitsInfo).where(
9797
HitsInfo.time >= int(datetime(year, month, day).timestamp()),
98-
HitsInfo.time
99-
< int(
98+
HitsInfo.time < int(
10099
(datetime(year, month, day) + timedelta(days=1)).timestamp()
101100
),
102101
)
103-
)
104-
.scalars()
105-
.all()
106-
)
102+
).scalars().all()
103+
]
107104
]
108105

106+
109107
now = datetime.now()
110108
current_year, current_month = now.year, now.month
111109
previous_year, previous_month = (
@@ -128,25 +126,24 @@ def getMonthlyHits() -> Dict[str, List[Dict[str, int]]]:
128126
def fetchData(year: int) -> List[Dict[str, int]]:
129127
return [
130128
{
131-
"hits": sum(item.hits for item in query) if query else 0,
132-
"bytes": sum(item.bytes for item in query) if query else 0,
129+
"hits": sum(item.hits for item in query),
130+
"bytes": sum(item.bytes for item in query),
133131
}
134132
for month in range(1, 13)
135-
if (
136-
query := session.execute(
133+
for query in [
134+
session.execute(
137135
select(HitsInfo).where(
138136
HitsInfo.time >= int(datetime(year, month, 1).timestamp()),
139-
HitsInfo.time
140-
< int(
141-
datetime(year, month + 1 if month < 12 else 1, 1)
142-
.replace(year=year if month < 12 else year + 1)
143-
.timestamp()
137+
HitsInfo.time < int(
138+
datetime(
139+
year if month < 12 else year + 1,
140+
month + 1 if month < 12 else 1,
141+
1
142+
).timestamp()
144143
),
145144
)
146-
)
147-
.scalars()
148-
.all()
149-
)
145+
).scalars().all()
146+
]
150147
]
151148

152149
now = datetime.now()

0 commit comments

Comments
 (0)