Compare commits

..

1 Commits

Author SHA1 Message Date
Super-Passerby
e9ae452cd2
Merge e0cb7443fe into 4b2d78a0b2 2025-04-12 21:39:08 +08:00
3 changed files with 38 additions and 57 deletions

View File

@ -46,7 +46,7 @@ PYTHON_PATH = "python3" if os.path.exists("/usr/bin/python3") else "python"
SCRIPT_PATH = os.environ.get("SCRIPT_PATH", "./quark_auto_save.py")
CONFIG_PATH = os.environ.get("CONFIG_PATH", "./config/quark_config.json")
PLUGIN_FLAGS = os.environ.get("PLUGIN_FLAGS", "")
DEBUG = os.environ.get("DEBUG", "false").lower() == "true"
DEBUG = os.environ.get("DEBUG", False)
config_data = {}
task_plugins_config_default = {}
@ -86,7 +86,10 @@ def get_login_token():
def is_login():
login_token = get_login_token()
if session.get("token") == login_token or request.args.get("token") == login_token:
if (
session.get("token") == login_token
or request.args.get("token") == login_token
):
return True
else:
return False
@ -221,12 +224,7 @@ def get_task_suggestions():
query = request.args.get("q", "").lower()
deep = request.args.get("d", "").lower()
try:
cs_data = config_data.get("source", {}).get("cloudsaver", {})
if (
cs_data.get("server")
and cs_data.get("username")
and cs_data.get("password")
):
if cs_data := config_data.get("source", {}).get("cloudsaver", {}):
cs = CloudSaver(cs_data.get("server"))
cs.set_auth(
cs_data.get("username", ""),
@ -239,16 +237,16 @@ def get_task_suggestions():
cs_data["token"] = search.get("new_token")
Config.write_json(CONFIG_PATH, config_data)
search_results = cs.clean_search_results(search.get("data"))
return jsonify({"success": True, "source": "CloudSaver", "data": search_results})
return jsonify({"success": True, "data": search_results})
else:
return jsonify({"success": True, "message": search.get("message")})
else:
base_url = base64.b64decode("aHR0cHM6Ly9zLjkxNzc4OC54eXo=").decode()
url = f"{base_url}/task_suggestions?q={query}&d={deep}"
response = requests.get(url)
return jsonify({"success": True, "source": "网络公开", "data": response.json()})
return jsonify({"success": True, "data": response.json()})
except Exception as e:
return jsonify({"success": True, "message": f"error: {str(e)}"})
return jsonify({"success": False, "message": str(e)})
@app.route("/get_share_detail")

View File

@ -1,4 +1,3 @@
import re
import requests
@ -77,10 +76,7 @@ class CloudSaver:
if result.get("success"):
return result
else:
if (
result.get("message") == "无效的 token"
or result.get("message") == "未提供 token"
):
if result.get("message") == "无效的 token" or result.get("message") == "未提供 token":
login_result = self.login()
if login_result.get("success"):
result = self.search(keyword, last_message_id)
@ -103,40 +99,26 @@ class CloudSaver:
Returns:
list: 夸克网盘链接列表
"""
pattern_title = r"(名称|标题)[:]?(.*)"
pattern_content = r"(描述|简介)[:]?(.*)(链接|标签)"
clean_results = []
link_array = []
for channel in search_results:
for item in channel.get("list", []):
cloud_links = item.get("cloudLinks", [])
for link in cloud_links:
if link.get("cloudType") == "quark":
# 清洗标题
title = item.get("title", "")
if match := re.search(pattern_title, title, re.DOTALL):
title = match.group(2)
title = title.replace("&", "&").strip()
# 清洗内容
content = item.get("content", "")
if match := re.search(pattern_content, content, re.DOTALL):
content = match.group(2)
content = content.replace('<mark class="highlight">', "")
content = content.replace("</mark>", "")
content = content.strip()
# 链接去重
if link.get("link") not in link_array:
link_array.append(link.get("link"))
clean_results.append(
{
"shareurl": link.get("link"),
"taskname": title,
"content": content,
"tags": item.get("tags", []),
"channel": item.get("channel", ""),
"channel_id": item.get("channelId", ""),
}
)
clean_results.append(
{
"shareurl": link.get("link"),
"taskname": item.get("title", "")
.strip("名称:")
.replace("&amp;", "&"),
"content": item.get("content", "")
.split("描述:")[1]
.split("链接:")[0]
.replace('<mark class="highlight">', "")
.replace("</mark>", ""),
"tags": item.get("tags", []),
}
)
return clean_results

View File

@ -198,7 +198,7 @@
<div class="form-group row">
<label class="col-sm-2 col-form-label">服务器</label>
<div class="col-sm-10">
<input type="text" v-model="formData.source.cloudsaver.server" class="form-control" placeholder="资源搜索服务器地址,如 http://172.17.0.1:8008">
<input type="text" v-model="formData.source.cloudsaver.server" class="form-control" placeholder="资源搜索服务器地址">
</div>
</div>
<div class="form-group row">
@ -272,7 +272,7 @@
<div class="input-group">
<input type="text" name="taskname[]" class="form-control" v-model="task.taskname" placeholder="必填" @focus="smart_param.showSuggestions=true;focusTaskname(index, task)" @input="changeTaskname(index, task)">
<div class="dropdown-menu show task-suggestions" v-if="smart_param.showSuggestions && smart_param.taskSuggestions.success && smart_param.index === index">
<div class="text-muted text-center" style="font-size:12px;">{{ smart_param.taskSuggestions.message ? smart_param.taskSuggestions.message : smart_param.taskSuggestions.data.length ? `以下资源来自 ${smart_param.taskSuggestions.source} 搜索,请自行辨识,如有侵权请联系资源方` : "未搜索到资源" }}</div>
<div class="text-muted text-center" style="font-size:12px;">{{ smart_param.taskSuggestions.message ? smart_param.taskSuggestions.message : smart_param.taskSuggestions.data.length ? "以下资源来自网络公开搜索,请自行辨识,如有侵权请联系资源方" : "未搜索到资源" }}</div>
<div v-for="suggestion in smart_param.taskSuggestions.data" :key="suggestion.taskname" class="dropdown-item" @click.prevent="selectSuggestion(task, suggestion)" style="cursor: pointer;font-size: 12px;" :title="suggestion.content">
<span v-html="suggestion.verify ? '✅': '❔'"></span> {{ suggestion.taskname }}
<small class="text-muted">
@ -516,8 +516,8 @@
origin_savepath: "",
taskSuggestions: {},
showSuggestions: false,
lastSuggestionsTime: 0,
isSearching: false,
searchTimer: null,
},
activeTab: 'tasklist',
configModified: false,
@ -707,12 +707,7 @@
}
},
changeTaskname(index, task) {
if (this.smart_param.searchTimer) {
clearTimeout(this.smart_param.searchTimer);
}
this.smart_param.searchTimer = setTimeout(() => {
this.searchSuggestions(index, task.taskname, 0);
}, 1000);
this.searchSuggestions(index, task.taskname, 500);
if (this.smart_param.savepath)
task.savepath = this.smart_param.savepath.replace('TASKNAME', task.taskname);
},
@ -875,16 +870,22 @@
task.runweek = [1, 2, 3, 4, 5, 6, 7];
}
},
searchSuggestions(index, taskname, deep = 1) {
searchSuggestions(index, taskname, limit_msec = 0) {
if (taskname.length == 0)
return;
this.smart_param.isSearching = true;
return
if (limit_msec > 0) {
const now = Date.now();
if (now - this.smart_param.lastSuggestionsTime < limit_msec)
return;
this.smart_param.lastSuggestionsTime = now;
}
this.smart_param.isSearching = true
this.smart_param.index = index;
try {
axios.get('/task_suggestions', {
params: {
q: taskname,
d: deep
d: limit_msec == 0 ? 1 : 0
}
}).then(response => {
this.smart_param.taskSuggestions = response.data;