fix: clean upload dspy with simple script, no complex escaping
This commit is contained in:
parent
eaef9e9596
commit
1a85c77ba4
@ -76,8 +76,10 @@
|
||||
"binds": [{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "(function(){var s=document.createElement('script');s.text='document.addEventListener(\"dragover\",function(e){e.preventDefault();e.stopPropagation()});document.addEventListener(\"drop\",function(e){e.preventDefault();e.stopPropagation();var files=e.dataTransfer.files;if(!files.length)return;for(var i=0;i<files.length;i++){var f=files[i];var xhr=new XMLHttpRequest();var kb=\"{{params_kw.kb_id}}\";xhr.open(\"POST\",\"/api/doc/upload?kb_id=\"+kb+\"&file_name=\"+encodeURIComponent(f.name));xhr.onload=function(){if(xhr.status===200){location.reload()}};xhr.send(f)}}});var inp=document.createElement(\"input\");inp.type=\"file\";inp.multiple=true;inp.onchange=function(){for(var j=0;j<inp.files.length;j++){var f=inp.files[j];var xhr=new XMLHttpRequest();var kb=\"{{params_kw.kb_id}}\";xhr.open(\"POST\",\"/api/doc/upload?kb_id=\"+kb+\"&file_name=\"+encodeURIComponent(f.name));xhr.onload=function(){if(xhr.status===200){location.reload()}};xhr.send(f)}};inp.click()';document.body.appendChild(s)})()"
|
||||
"actiontype": "urlwidget",
|
||||
"target": "app.detail_content",
|
||||
"mode": "replace",
|
||||
"options": {"url": "{{entire_url('./upload.dspy')}}", "params": {"kb_id": "{{params_kw.kb_id}}"}}
|
||||
}]
|
||||
}
|
||||
]
|
||||
|
||||
@ -1,26 +1,38 @@
|
||||
ns = params_kw.copy()
|
||||
kb_id = ns.get('kb_id', '')
|
||||
|
||||
body = """{
|
||||
import json
|
||||
body = json.dumps({
|
||||
"widgettype": "VBox",
|
||||
"options": {"width": "100%", "padding": "0", "spacing": "16px"},
|
||||
"options": {"spacing": "16px", "padding": "0"},
|
||||
"subwidgets": [
|
||||
{"widgettype": "Text", "options": {"text": "📤 上传文件", "cfontsize": 20, "fontWeight": "bold", "color": "#333"}},
|
||||
{"widgettype": "Text", "options": {"text": "📤 上传文件", "cfontsize": 18, "fontWeight": "bold", "color": "#333"}},
|
||||
{"widgettype": "Text", "options": {"text": "知识库: " + kb_id, "cfontsize": 12, "color": "#888"}},
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {
|
||||
"id": "drop_zone", "width": "100%", "cheight": 12,
|
||||
"bgcolor": "#f8f9fa", "padding": "32px", "css": "card",
|
||||
"border": "2px dashed #3b82f6",
|
||||
"alignItems": "center", "justifyContent": "center"
|
||||
},
|
||||
"options": {"id": "upload_zone", "width": "100%", "cheight": 10, "bgcolor": "#f8f9fa", "padding": "24px", "css": "card", "border": "2px dashed #3b82f6", "alignItems": "center", "justifyContent": "center"},
|
||||
"subwidgets": [
|
||||
{"widgettype": "Text", "options": {"text": "📂", "cfontsize": 40}},
|
||||
{"widgettype": "Text", "options": {"text": "点击选择文件上传", "cfontsize": 16, "color": "#555"}},
|
||||
{"widgettype": "Text", "options": {"text": "支持: TXT, PDF, JPG, PNG, MP3, WAV, MP4", "cfontsize": 12, "color": "#999"}}
|
||||
{"widgettype": "Text", "options": {"text": "拖拽文件到此处上传", "cfontsize": 15, "color": "#888"}},
|
||||
{"widgettype": "Text", "options": {"text": "支持: TXT,PDF,JPG,PNG,MP3,WAV,MP4", "cfontsize": 12, "color": "#aaa"}},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {"label": "选择文件上传", "bgcolor": "#3b82f6", "color": "#fff", "marginTop": "12px"},
|
||||
"binds": [{
|
||||
"wid": "self",
|
||||
"event": "click",
|
||||
"actiontype": "script",
|
||||
"script": "var i=document.createElement('input');i.type='file';i.onchange=function(){for(var j=0;j<i.files.length;j++){var f=i.files[j];var x=new XMLHttpRequest();x.open('POST','/api/doc/upload?kb_id=" + kb_id + "&file_name='+encodeURIComponent(f.name));x.send(f)}};i.click()"
|
||||
}]
|
||||
},
|
||||
{"widgettype": "Text", "options": {"text": "", "id": "upload_status", "cfontsize": 12, "color": "#50b86c", "marginTop": "8px"}}
|
||||
]
|
||||
},
|
||||
{
|
||||
"widgettype": "Button",
|
||||
"options": {"label": "← 返回文件管理", "bgcolor": "#e0e0e0", "color": "#666"},
|
||||
"binds": [{"wid": "self", "event": "click", "actiontype": "urlwidget", "target": "app.rag_main_content", "mode": "replace", "options": {"url": entire_url('/knowledge_bases_list/index.ui')}}]
|
||||
}
|
||||
]
|
||||
}"""
|
||||
import json
|
||||
})
|
||||
return json.loads(body)
|
||||
|
||||
26
wwwroot/knowledge_bases_list/upload.js
Normal file
26
wwwroot/knowledge_bases_list/upload.js
Normal file
@ -0,0 +1,26 @@
|
||||
// File drop upload handler - prevents browser default, uploads to API
|
||||
(function(){
|
||||
var kb_id = '{{params_kw.kb_id}}';
|
||||
document.addEventListener('dragover', function(e){ e.preventDefault(); e.stopPropagation(); });
|
||||
document.addEventListener('drop', function(e){
|
||||
e.preventDefault(); e.stopPropagation();
|
||||
var files = e.dataTransfer.files;
|
||||
if (!files.length) return;
|
||||
var st = document.getElementById('status_text');
|
||||
if (st) st.innerHTML = '上传中...';
|
||||
for (var i=0; i<files.length; i++){
|
||||
(function(f){
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/api/doc/upload?kb_id='+kb_id+'&file_name='+encodeURIComponent(f.name));
|
||||
xhr.onload = function(){
|
||||
if (xhr.status === 200){
|
||||
if (st) st.innerHTML = '上传成功: '+f.name;
|
||||
} else {
|
||||
if (st) st.innerHTML = '上传失败: HTTP '+xhr.status;
|
||||
}
|
||||
};
|
||||
xhr.send(f);
|
||||
})(files[i]);
|
||||
}
|
||||
});
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user