Commit 44af4162 authored by wanli's avatar wanli

feat: 返回数据增加lang字段

parent ab4625f5
...@@ -33,12 +33,30 @@ api = Blueprint("api", __name__, url_prefix="/api/v1/%s" % config['NAME']) ...@@ -33,12 +33,30 @@ api = Blueprint("api", __name__, url_prefix="/api/v1/%s" % config['NAME'])
logger.info("/api/v1/%s" % config['NAME']) logger.info("/api/v1/%s" % config['NAME'])
# 获取文件编码类型 # 获取文件编码类型
def get_encoding(file): def get_encoding(file: str):
# 二进制方式读取,获取字节数据,检测类型 # 二进制方式读取,获取字节数据,检测类型
with open(file, 'rb') as f: with open(file, 'rb') as f:
data = f.read() data = f.read()
return chardet.detect(data)['encoding'] return chardet.detect(data)['encoding']
def get_program_lang(file: Path):
suffix = file.suffix
lang = {
'c': [".c", "cpp", ".h", ".hpp"],
"javascript": [".js"],
"json": [".json"],
"python": [".py"]
}
l = "c"
for key in lang:
if suffix in lang[key]:
l = key
break
return l
@api.route("/system/getFileContent", methods=["POST"]) @api.route("/system/getFileContent", methods=["POST"])
def get_file_content(): def get_file_content():
params = request.json params = request.json
...@@ -60,7 +78,7 @@ def get_file_content(): ...@@ -60,7 +78,7 @@ def get_file_content():
# 判断文件类型 # 判断文件类型
# 将内容以字符串形式返回给前端 # 将内容以字符串形式返回给前端
return response_result(ResponseCode.OK, data=result) return response_result(ResponseCode.OK, data=result, lang=get_program_lang(fpath))
@api.route("/evm", methods=['GET','POST']) @api.route("/evm", methods=['GET','POST'])
def hello_evm(): def hello_evm():
......
...@@ -240,7 +240,6 @@ export default { ...@@ -240,7 +240,6 @@ export default {
console.log(editor); console.log(editor);
}, },
onFileChange(file) { onFileChange(file) {
console.log(file, this.form.file);
if (!this.result) return; if (!this.result) return;
this.getFileContent(file); this.getFileContent(file);
}, },
...@@ -279,7 +278,7 @@ export default { ...@@ -279,7 +278,7 @@ export default {
getFileContent({ file: file }) getFileContent({ file: file })
.then((res) => { .then((res) => {
this.code = res.data; this.code = res.data;
this.lang = "c"; this.lang = res.lang;
this.randomkey = this.createRamdomKey(); this.randomkey = this.createRamdomKey();
this.$message.success(res.message); this.$message.success(res.message);
}) })
...@@ -373,12 +372,7 @@ export default { ...@@ -373,12 +372,7 @@ export default {
}); });
}, },
}, },
mounted() { mounted() {},
setTimeout(() => {
this.code = "console.log(123456)";
console.log(this.code);
}, 2000);
},
created() { created() {
this.getMarkType(); this.getMarkType();
}, },
......
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