Commit 1566733f authored by wanli's avatar wanli

feat(view/api.py): 新增支持多个evue文件解析为字节码文件

parent 4c27f841
No preview for this file type
......@@ -150,9 +150,12 @@ def action_build():
# 解析这个evue文件,分别生成3个文件:index.html.bc/index.css.bc/index.js.bc
# 对这三个进行zip压缩,将压缩后的zip链接返回给前端
binfile = request.files.get("binfile")
if not binfile:
return response_result(ResponseCode.REQUEST_ERROR, msg="upload field name error")
# binfile = request.files.get("binfile")
# if not binfile:
# return response_result(ResponseCode.REQUEST_ERROR, msg="upload field name error")
if len(request.files.getlist('binfile')) < 0:
return response_result(ResponseCode.REQUEST_ERROR, msg="upload file is null")
target_path = Path(config.get("UPLOAD_PATH")).joinpath(config.get("BYTECODE_DIR"))
if not target_path.exists():
......@@ -162,36 +165,40 @@ def action_build():
if not target_path.exists():
target_path.mkdir()
target = target_path.joinpath(binfile.filename)
with open(target.resolve().as_posix(), "wb+") as fd:
fd.write(binfile.stream.read())
content = vbuild.render(target.resolve().as_posix())
if content:
files = [
(target.parent.joinpath("{}.hml".format(Path(binfile.filename).stem)).resolve().as_posix(), content.html),
(target.parent.joinpath("{}.css".format(Path(binfile.filename).stem)).resolve().as_posix(), content.style),
(target.parent.joinpath("{}.js".format(Path(binfile.filename).stem)).resolve().as_posix(), content.script)
]
dst_files = []
for item in files:
file, text = item
with open(file, "w+") as fd:
fd.write(text)
result = subprocess.call("./executable -c {file}".format(file=file), shell=True)
logger.info(result)
t = Path(file)
res = t.rename("{}.{}".format(t.name, "bc"))
dst_files.append(res)
zip_filepath = target_path.joinpath("{}.zip".format(target_path.name)).resolve().as_posix()
z = zipfile.ZipFile(zip_filepath, 'w')
for file in dst_files:
z.write(file.resolve().as_posix(), arcname=file.name)
shutil.move(file.resolve().as_posix(), target_path.joinpath(file.name).resolve().as_posix())
z.close()
dst_files = []
zip_filepath = target_path.joinpath("{}.zip".format(target_path.name)).resolve().as_posix()
z = zipfile.ZipFile(zip_filepath, 'w')
for f in request.files.getlist('binfile'):
target = target_path.joinpath(f.filename)
with open(target.resolve().as_posix(), "wb+") as fd:
fd.write(f.stream.read())
content = vbuild.render(target.resolve().as_posix())
if content:
files = [
(target.parent.joinpath("{}.hml".format(Path(f.filename).stem)).resolve().as_posix(), content.html),
(target.parent.joinpath("{}.css".format(Path(f.filename).stem)).resolve().as_posix(), content.style),
(target.parent.joinpath("{}.js".format(Path(f.filename).stem)).resolve().as_posix(), content.script)
]
for item in files:
file, text = item
with open(file, "w+") as fd:
fd.write(text)
result = subprocess.call("./executable -c {file}".format(file=file), shell=True)
logger.info(result)
t = Path(file)
res = t.rename("{}.{}".format(t.name, "bc"))
dst_files.append(res)
for file in dst_files:
z.write(file.resolve().as_posix(), arcname=file.name)
shutil.move(file.resolve().as_posix(), target_path.joinpath(file.name).resolve().as_posix())
# 压缩
z.close()
result = Path(zip_filepath).resolve().relative_to(Path(config.get("UPLOAD_PATH"))).as_posix()
return response_result(ResponseCode.OK, data=result)
......
<template>
<div class="app-container">
<el-alert title="代码混淆工具" type="success"></el-alert>
<div style="margin: 10px 0px">
<el-form>
<el-form-item>
<el-upload
class="upload-demo"
action="/api/v1/evm_store/build"
name="binfile"
:on-success="handleUploaded"
:file-list="fileList"
>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">
上传C源文件,转换完成后会自动下载
</div>
</el-upload>
</el-form-item>
<el-form-item>
<el-button type="success" @click="getConvertString">转换</el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
import { actionOpqcp } from "@/api/app-store";
export default {
name: "Opqcp",
data() {
return {
fileList: [],
inputString: null,
outputString: null,
filename: "app.js",
};
},
methods: {
createFile(content, filename) {
const a = document.createElement("a");
const blob = new Blob([content]);
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
},
handleUploaded(response) {
if (response.code == 200) {
this.filename = response.data.filename
actionOpqcp({ filename: response.data.filepath })
.then((res) => {
this.$message.success(res.message);
// const a = document.createElement("a");
// a.href = url;
// a.download = filename;
// a.click();
})
.catch((err) => {
this.$message.error(err.message);
});
}
console.log(response)
},
downloadFile() {
this.$prompt("请输入文件名", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
inputValue: this.filename,
inputErrorMessage: "文件名格式不正确",
})
.then(({ value }) => {
if (value) this.filename = value;
this.createFile(this.outputString, this.filename);
})
.catch(() => {
this.$message({
type: "info",
message: "取消输入",
});
});
},
getConvertString() {
},
},
mounted() {},
created() {},
};
</script>
<style lang="scss" scoped>
.app-container {
& > div.page-wrapper {
margin: 10px 0px;
}
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment