feat: 统一下载地址,并规范下载文件名
This commit is contained in:
parent
f628c10db0
commit
50d2bd5406
|
@ -10,6 +10,7 @@ from ...entities.entities import ReturnInfo, FileInfo
|
|||
from ...libs.tools import read_json_file, read_txt_file, write_json, get_project_file
|
||||
import threading
|
||||
import time
|
||||
from urllib.parse import urlencode
|
||||
|
||||
#
|
||||
api = RedPrint('files')
|
||||
|
@ -96,9 +97,11 @@ def get_anno_json():
|
|||
if not fn.endswith('.json'):
|
||||
continue
|
||||
js.append(read_txt_file(anno_output_dir + '/' + fn))
|
||||
anno_json_path = DOWNLOAD_FILE_LOCATION.format(project_name).replace('result.json', 'anno.json')
|
||||
anno_json_path = DOWNLOAD_FILE_LOCATION.format(project_name)
|
||||
open('app/'+anno_json_path, 'w', encoding='utf-8').write('\n'.join(js))
|
||||
response = make_response(send_from_directory(directory='', path=anno_json_path, as_attachment=True))
|
||||
response.headers["Content-disposition"] = 'attachment; filename=result.json'
|
||||
filename = project_name + '_' + time.strftime('%Y%m%d_%H%M%S') + '.json'
|
||||
filename_urlencode = urlencode({'filename': filename})
|
||||
response.headers["Content-disposition"] = f'attachment; {filename_urlencode}'
|
||||
|
||||
return response
|
||||
|
|
|
@ -17,7 +17,7 @@ PROJECT_PATH = PROJECTS + '/{}/'
|
|||
PROJECT_CONFIG_PATH = PROJECTS + '/' + "{}" + '/config.json'
|
||||
|
||||
#下载标注结果所在的位置
|
||||
DOWNLOAD_FILE_LOCATION = 'projects/{}/result.json'
|
||||
DOWNLOAD_FILE_LOCATION = 'projects/{}/anno.json'
|
||||
|
||||
# 标注信息存储路径
|
||||
ANNO_OUTPUT_PATH = PROJECTS + '/{}/anno/{}.json'
|
||||
|
|
|
@ -3,7 +3,5 @@
|
|||
| url | methods | params | return |
|
||||
| -------------------------- | ------- | -------------------------------------------------------- | -------------------------------- |
|
||||
| v1/project/get_zipped_data | POST | projectName:项目名 file:数据集文件(目前只支持.zip格式) | json :errcode表示是否成功导入 |
|
||||
| v1/files/get_json | GET | projectName:项目名 | file(.json格式的数据集标注结果) |
|
||||
| v1/files/get_anno_json | GET | projectName:项目名 | file(.json格式的数据集标注结果) |
|
||||
|v1/project/delete_program |GET |projectName:项目名|json:errcode表示是否成功|
|
||||
| v1/files//get_labels | GET | projectName:项目名 | file(.json格式的数据集标注结果) |
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ module.exports = {
|
|||
assetsPublicPath: '/',
|
||||
proxyTable: {
|
||||
'/v1/': {
|
||||
target: 'http://localhost:9060/',
|
||||
target: 'http://127.0.0.1:9060/',
|
||||
// target: 'https://tekii.cn/',
|
||||
}
|
||||
},
|
||||
|
||||
// Various Dev Server settings
|
||||
host: '0.0.0.0', // can be overwritten by process.env.HOST
|
||||
host: '127.0.0.1', // can be overwritten by process.env.HOST
|
||||
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
|
||||
autoOpenBrowser: false,
|
||||
errorOverlay: true,
|
||||
|
|
|
@ -412,6 +412,10 @@ export default {
|
|||
* @param 类型
|
||||
*/
|
||||
setType: function (type, ev) {
|
||||
if (!this.nowFile) {
|
||||
// 如果没有选中文件,就不允许标注
|
||||
return false
|
||||
}
|
||||
if (this.projectType === '命名实体识别') {
|
||||
this.$set(this, 'nowType', type)
|
||||
} else if (this.projectType === '文本分类') {
|
||||
|
@ -639,11 +643,9 @@ export default {
|
|||
if (!isLocal) {
|
||||
// 非单机版,就直接通过url下载
|
||||
if (this.projectType === '命名实体识别') {
|
||||
window.open(`/v1/files/get_json?projectName=${this.projectName}`, '_self')
|
||||
window.open(`/v1/files/get_anno_json?projectName=${this.projectName}`, '_self')
|
||||
} else if (this.projectType === '文本分类') {
|
||||
get(`/v1/files/get_labels?projectName=${this.projectName}`, (text) => {
|
||||
saveAsFile(JSON.stringify(JSON.parse(text)), 'labels.json')
|
||||
}, {isDirect: true})
|
||||
window.open(`/v1/files/get_anno_json?projectName=${this.projectName}`, '_self')
|
||||
} else {
|
||||
window.open(`/v1/files/get_anno_json?projectName=${this.projectName}`, '_self')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue