This commit is contained in:
@@ -73,9 +73,22 @@ def parse_rrule(value: str) -> dict[str, str]:
|
||||
raise HTTPException(422, "无效的 RRULE")
|
||||
key, val = part.split("=", 1)
|
||||
parts[key] = val
|
||||
allowed = {"FREQ", "INTERVAL", "BYDAY", "BYMONTHDAY", "BYMONTH", "COUNT", "UNTIL"}
|
||||
if set(parts) - allowed:
|
||||
raise HTTPException(422, "重复规则包含不支持的字段")
|
||||
if parts.get("FREQ") not in {"DAILY", "WEEKLY", "MONTHLY", "YEARLY"}:
|
||||
raise HTTPException(422, "仅支持 DAILY、WEEKLY、MONTHLY、YEARLY")
|
||||
if "BYDAY" in parts:
|
||||
weekdays = parts["BYDAY"].split(",")
|
||||
if not weekdays or any(day not in _WEEKDAYS for day in weekdays):
|
||||
raise HTTPException(422, "无效的重复星期")
|
||||
try:
|
||||
month_days = [int(day) for day in parts.get("BYMONTHDAY", "").split(",") if day]
|
||||
months = [int(month) for month in parts.get("BYMONTH", "").split(",") if month]
|
||||
if any(day < 1 or day > 31 for day in month_days) or any(month < 1 or month > 12 for month in months):
|
||||
raise ValueError
|
||||
if "UNTIL" in parts:
|
||||
datetime.fromisoformat(parts["UNTIL"])
|
||||
if "INTERVAL" in parts and int(parts["INTERVAL"]) < 1:
|
||||
raise ValueError
|
||||
if "COUNT" in parts and int(parts["COUNT"]) < 1:
|
||||
|
||||
Reference in New Issue
Block a user