Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
善良的小乔
dr_py
提交
35e8a09d
dr_py
项目概览
善良的小乔
/
dr_py
与 Fork 源项目一致
Fork自
晚风拂柳颜 / dr_py
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
dr_py
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
35e8a09d
编写于
8月 31, 2022
作者:
H
hjdhnx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加了文件上传校验,非规则文件不会成功上传
上级
dcbbeefa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
4 deletion
+23
-4
app.py
app.py
+14
-1
templates/admin.html
templates/admin.html
+9
-3
未找到文件。
app.py
浏览文件 @
35e8a09d
...
...
@@ -155,11 +155,24 @@ def upload_file():
if
request
.
method
==
'POST'
:
try
:
f
=
request
.
files
[
'file'
]
# print(f)
# print(request.files)
filename
=
secure_filename
(
f
.
filename
)
savePath
=
f
'js/
{
filename
}
'
print
(
f
'推荐安全文件命名:
{
filename
}
'
)
# savePath = f'js/{filename}'
savePath
=
f
'js/
{
f
.
filename
}
'
# print(savePath)
if
os
.
path
.
exists
(
savePath
):
return
jsonify
(
error
.
failed
(
f
'上传失败,文件已存在,请先查看删除再试'
))
with
open
(
'js/模板.js'
,
encoding
=
'utf-8'
)
as
f2
:
before
=
f2
.
read
()
upcode
=
f
.
stream
.
read
().
decode
(
'utf-8'
)
check_to_run
=
before
+
upcode
# print(check_to_run)
try
:
js2py
.
eval_js
(
check_to_run
)
except
:
return
jsonify
(
error
.
failed
(
'文件上传失败,检测到上传的文件不是drpy框架支持的源代码'
))
# print(savePath)
f
.
save
(
savePath
)
return
jsonify
(
error
.
success
(
'文件上传成功'
))
...
...
templates/admin.html
浏览文件 @
35e8a09d
...
...
@@ -82,12 +82,17 @@
console
.
log
(
file_data
);
if
(
!
file_data
){
alert
(
'
文件必选
'
);
return
return
false
}
var
name
=
file_data
.
name
;
if
(
!
name
.
endsWith
(
'
.js
'
)){
alert
(
'
仅支持上传js文件
'
);
return
false
}
var
form_data
=
new
FormData
();
// 把所有表单信息
form_data
.
append
(
"
id
"
,
"
001
"
);
form_data
.
append
(
"
name
"
,
file_data
.
name
);
form_data
.
append
(
"
name
"
,
name
);
form_data
.
append
(
"
file
"
,
file_data
);
$
.
ajax
({
type
:
"
POST
"
,
...
...
@@ -117,7 +122,8 @@
<h2
class=
"title"
>
欢迎使用py_dr管理员界面
</h2><h4><a
href=
"/index"
>
返回首页
</a></h4>
<p>
你可以在此页面在线上传规则文件到js目录或者删除js目录的文件
</p>
<form
action =
"/upload"
method =
"POST"
enctype =
"multipart/form-data"
>
<input
type =
"file"
name =
"file"
class=
"btn"
accept=
".js"
onchange=
"getFileSize(this)"
/>
<!-- <input type = "file" name = "file" class="btn" accept=".js" onchange="getFileSize(this)"/>-->
<input
type =
"file"
name =
"file"
class=
"btn"
onchange=
"getFileSize(this)"
/>
<!-- <input type = "submit" value="上传" class="btn"/>-->
<input
type=
"button"
id=
"upload"
value=
"上传"
class=
"btn"
/>
</form>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录