文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 812f9465 by Wang Yuhang

Merge branch 'develop' of ssh://gitlab.redhtc.com:1422/Berlincen/DA-Platform into dev

parents 4563923a 092651bd
...@@ -12956,6 +12956,11 @@ ...@@ -12956,6 +12956,11 @@
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
"dev": true "dev": true
}, },
"vuex": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/vuex/-/vuex-3.4.0.tgz",
"integrity": "sha512-ajtqwEW/QhnrBZQsZxCLHThZZaa+Db45c92Asf46ZDXu6uHXgbfVuBaJ4gzD2r4UX0oMJHstFwd2r2HM4l8umg=="
},
"watchpack": { "watchpack": {
"version": "1.6.1", "version": "1.6.1",
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.1.tgz", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.1.tgz",
......
...@@ -33,7 +33,7 @@ def create_user(username, password, email): ...@@ -33,7 +33,7 @@ def create_user(username, password, email):
user = User(username=username, password=password, email=email) user = User(username=username, password=password, email=email)
try: try:
user.save() user.save()
except BaseException: except Exception:
print(0) print(0)
else: else:
print(1) print(1)
......
from flask import Flask from flask import Flask
from views.uploadDownload import uploadDownload # from views.uploadDownload import uploadDownload
from views.textAnnotation import textAnnotation # from views.textAnnotation import textAnnotation
from views.login import user
app = Flask(__name__) app = Flask(__name__)
app.register_blueprint(textAnnotation) # app.register_blueprint(textAnnotation)
app.register_blueprint(uploadDownload) # app.register_blueprint(uploadDownload)
app.register_blueprint(user)
@app.route("/") @app.route("/")
......
import json
from flask import Blueprint
from flask import request
from Dao import User
user = Blueprint("user", __name__, url_prefix="/user")
@user.route("/register")
def register():
username = request.args['username']
password = request.args['passwd']
email = request.args['email']
User.create_user(username, password, email)
return json.dumps(username)
@user.route("/login", methods=["Post"])
def login():
username = request.form['name']
passwd = request.form['passwd']
User.find_user(username, passwd)
return json.dumps(username)
import json # import json
from flask import Blueprint # from flask import Blueprint
from flask import request # from flask import request
from Dao import mongodbTest # from Dao import mongodbTest
#
textAnnotation = Blueprint("textAnnotation", __name__, url_prefix="/textAnnotation") # textAnnotation = Blueprint("textAnnotation", __name__, url_prefix="/textAnnotation")
collectionTest = mongodbTest.db.test # collectionTest = mongodbTest.db.test
# x = mongodbTest.revOne(collectionTest, {"annotatorId": "10"}, {"$set": {"fragmentId": "1000"}}) # # x = mongodbTest.revOne(collectionTest, {"annotatorId": "10"}, {"$set": {"fragmentId": "1000"}})
x = mongodbTest.findAll(collectionTest) # x = mongodbTest.findAll(collectionTest)
# mongodbTest.insert(collectionTest,{"annotatorId": "10", "fragmentId": "1000", # # mongodbTest.insert(collectionTest,{"annotatorId": "10", "fragmentId": "1000",
# "textUrl": "198.111.23.12:23/file/10.txt", # # "textUrl": "198.111.23.12:23/file/10.txt",
# "tokenList": # # "tokenList":
# [{"entityId": "1", "word": "滑坡1号", "begin": "1", "end": "4", "attribute": "滑坡 基本信息 滑坡名称"}]}) # # [{"entityId": "1", "word": "滑坡1号", "begin": "1", "end": "4", "attribute": "滑坡 基本信息 滑坡名称"}]})
mongodbTest.addToken(collectionTest, {"annotatorId": "10"}, {"entityId": "2", "word": "滑坡2号", "begin": "10", "end": "14", "attribute": "滑坡 基本信息 滑坡名称"}) # mongodbTest.addToken(collectionTest, {"annotatorId": "10"}, {"entityId": "2", "word": "滑坡2号", "begin": "10", "end": "14", "attribute": "滑坡 基本信息 滑坡名称"})
mongodbTest.deleteToken(collectionTest, {"annotatorId": "10"}, {"entityId": "1"}) # mongodbTest.deleteToken(collectionTest, {"annotatorId": "10"}, {"entityId": "1"})
#
#
@textAnnotation.route("/") # @textAnnotation.route("/")
def hello_world(): # def hello_world():
return json.dumps(x, ensure_ascii=False) # return json.dumps(x, ensure_ascii=False)
#
#
@textAnnotation.route("/test", methods=["POST"]) # @textAnnotation.route("/test", methods=["POST"])
def check(): # def check():
# 默认返回内容 # # 默认返回内容
return_dict = {'return_code': '200', 'return_info': '处理成功', 'result': False} # return_dict = {'return_code': '200', 'return_info': '处理成功', 'result': False}
# 判断传入的json数据是否为空 # # 判断传入的json数据是否为空
# if request.get_data() is None: # # if request.get_data() is None:
# return_dict['return_code'] = '5004' # # return_dict['return_code'] = '5004'
# return_dict['return_info'] = '请求参数为空' # # return_dict['return_info'] = '请求参数为空'
# return json.dumps(return_dict, ensure_ascii=False) # # return json.dumps(return_dict, ensure_ascii=False)
# 获取传入的参数 # # 获取传入的参数
get_Data = request.get_data() # get_Data = request.get_data()
# 传入的参数为bytes类型,需要转化成json # # 传入的参数为bytes类型,需要转化成json
get_Data = json.loads(get_Data) # get_Data = json.loads(get_Data)
name = get_Data.get('name') # name = get_Data.get('name')
age = get_Data.get('age') # age = get_Data.get('age')
# 对参数进行操作 # # 对参数进行操作
return_dict['result'] = "%s,%s" % (name, age) # return_dict['result'] = "%s,%s" % (name, age)
return json.dumps(return_dict, ensure_ascii=False) # return json.dumps(return_dict, ensure_ascii=False)
#
import json # import json
import os # import os
import time # import time
#
#
from flask import Blueprint # from flask import Blueprint
from support import basedir # from support import basedir
from flask import jsonify, request, send_file # from flask import jsonify, request, send_file
from werkzeug.utils import secure_filename # from werkzeug.utils import secure_filename
#
#
uploadDownload = Blueprint("uploadDownload", __name__, url_prefix="/uploadDownload") # uploadDownload = Blueprint("uploadDownload", __name__, url_prefix="/uploadDownload")
UPLOAD_FOLDER = 'upload' # 用于保存上传文件的文件夹名称 # UPLOAD_FOLDER = 'upload' # 用于保存上传文件的文件夹名称
ALLOWED_EXTENSIONS = {'txt', 'xls', 'xlsx'} # 允许上传的文件格式 # ALLOWED_EXTENSIONS = {'txt', 'xls', 'xlsx'} # 允许上传的文件格式
#
#
# 用于判断文件后缀 # # 用于判断文件后缀
def allowed_file(filename): # def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS # return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
#
#
# 上传文件 # # 上传文件
@uploadDownload.route('/upload', methods=['POST'], strict_slashes=False) # @uploadDownload.route('/upload', methods=['POST'], strict_slashes=False)
def upload(): # def upload():
file_dir = os.path.join(basedir, UPLOAD_FOLDER) # file_dir = os.path.join(basedir, UPLOAD_FOLDER)
if not os.path.exists(file_dir): # if not os.path.exists(file_dir):
os.makedirs(file_dir) # os.makedirs(file_dir)
f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值 # f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值
#
if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 # if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型
fName = secure_filename(f.filename) # fName = secure_filename(f.filename)
ext = fName.rsplit('.', 1)[1] # 获取文件后缀 # ext = fName.rsplit('.', 1)[1] # 获取文件后缀
unix_time = int(time.time()) # unix_time = int(time.time())
new_filename = str(unix_time)+'.'+ext # 修改了上传的文件名 # new_filename = str(unix_time)+'.'+ext # 修改了上传的文件名
f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录 # f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录
print(new_filename) # print(new_filename)
#
return jsonify({"errno": 0, "msg": "succeed ", "token": new_filename}) # return jsonify({"errno": 0, "msg": "succeed ", "token": new_filename})
else: # else:
return jsonify({"errno": 1001, "errmsg": u"failed"}) # return jsonify({"errno": 1001, "errmsg": u"failed"})
#
#
# 下载接口 # # 下载接口
@uploadDownload.route('/download/<fileName>', methods=['GET']) # @uploadDownload.route('/download/<fileName>', methods=['GET'])
def download(fileName): # def download(fileName):
file_dir = os.path.join(basedir, UPLOAD_FOLDER, fileName) # file_dir = os.path.join(basedir, UPLOAD_FOLDER, fileName)
return send_file(file_dir, as_attachment=True, attachment_filename=fileName) # return send_file(file_dir, as_attachment=True, attachment_filename=fileName)
#
#
# 显示文档 # # 显示文档
@uploadDownload.route('/getfile/<path>', methods=['GET']) # @uploadDownload.route('/getfile/<path>', methods=['GET'])
def today(path): # def today(path):
fileStr = open(os.path.join(basedir, UPLOAD_FOLDER, path), 'r', encoding='UTF-8').read() # fileStr = open(os.path.join(basedir, UPLOAD_FOLDER, path), 'r', encoding='UTF-8').read()
x1 = [{"file": fileStr}] # x1 = [{"file": fileStr}]
return json.dumps(x1, ensure_ascii=False) # return json.dumps(x1, ensure_ascii=False)
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