v1.0.5: 网址列表支持上传txt批量导入(UTF-8/GBK自动识别/去重/行内注释清理)
This commit is contained in:
@@ -154,6 +154,19 @@ def api_tasks():
|
||||
return jsonify(tasks)
|
||||
|
||||
|
||||
def _clean_urls(lines):
|
||||
"""清洗网址行: 去空白, 去行内 # 注释 (URL 本身不含空格, 安全), 自动补 https 前缀"""
|
||||
out = []
|
||||
for u in lines or []:
|
||||
u = str(u).split(" #")[0].strip()
|
||||
if not u:
|
||||
continue
|
||||
if not u.startswith("http"):
|
||||
u = "https://" + u
|
||||
out.append(u)
|
||||
return out
|
||||
|
||||
|
||||
@app.route("/api/tasks", methods=["POST"])
|
||||
def api_create_task():
|
||||
body = request.get_json(force=True) or {}
|
||||
@@ -171,7 +184,7 @@ def api_create_task():
|
||||
"created_at": now_str(),
|
||||
"updated_at": now_str(),
|
||||
"config": {**DEFAULT_CONFIG, **(body.get("config") or {})},
|
||||
"urls": [u.strip() for u in (body.get("urls") or []) if u.strip()],
|
||||
"urls": _clean_urls(body.get("urls") or []),
|
||||
}
|
||||
|
||||
if mode == "auto":
|
||||
@@ -230,7 +243,7 @@ def api_update_task(tid):
|
||||
if "name" in body and str(body["name"]).strip():
|
||||
task["name"] = str(body["name"]).strip()
|
||||
if "urls" in body:
|
||||
task["urls"] = [u.strip() for u in body["urls"] if u.strip()]
|
||||
task["urls"] = _clean_urls(body["urls"])
|
||||
if "config" in body:
|
||||
merged = {**task.get("config", {}), **body["config"]}
|
||||
task["config"] = merged
|
||||
|
||||
Reference in New Issue
Block a user