-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: upgrade-deps-version (#48) * chore: 升级依赖包版本号 * fix: 修改requirements.txt的依赖版本 * chore: 升级核心库版本号 * 修改readme文件 * chore: upgrade requirements.txt * chore: 更新为bate版本 * feat: 新增文件上传API * feat: 改建文件上传 * fix: 删除多余的模块导入 * fix: 修改文件上传返回的key值 * feat: 增加文件上传默认配置 * chore: 更新核心库版本 * fix: 修复win系统在cmd下执行初始化插件脚本的编码问题 * fix: 删除LocalUpload下upload的多余参数
- Loading branch information
Showing
12 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
:copyright: © 2019 by the Lin team. | ||
:license: MIT, see LICENSE for more details. | ||
""" | ||
from flask import request, jsonify | ||
from lin import login_required | ||
from lin.redprint import Redprint | ||
|
||
from app.extensions.file.local_uploader import LocalUploader | ||
|
||
file_api = Redprint('file') | ||
|
||
|
||
@file_api.route('/', methods=['POST']) | ||
@login_required | ||
def post_file(): | ||
files = request.files | ||
uploader = LocalUploader(files) | ||
ret = uploader.upload() | ||
return jsonify(ret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 文件相关配置 | ||
FILE = { | ||
"STORE_DIR": 'app/assets', | ||
"SINGLE_LIMIT": 1024 * 1024 * 2, | ||
"TOTAL_LIMIT": 1024 * 1024 * 20, | ||
"NUMS": 10, | ||
"INCLUDE": set([]), | ||
"EXCLUDE": set([]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from flask import current_app | ||
from werkzeug.utils import secure_filename | ||
|
||
from lin.core import File | ||
from lin.file import Uploader | ||
|
||
|
||
class LocalUploader(Uploader): | ||
|
||
def upload(self): | ||
ret = [] | ||
site_domain = current_app.config.get('SITE_DOMAIN')\ | ||
if current_app.config.get('SITE_DOMAIN') else 'http://127.0.0.1:5000' | ||
for single in self._file_storage: | ||
file_md5 = self._generate_md5(single.read()) | ||
single.seek(0) | ||
exists = File.query.filter_by(md5=file_md5).first() | ||
if exists: | ||
ret.append({ | ||
"key": single.name, | ||
"id": exists.id, | ||
"url": site_domain + '/assets/' + exists.path | ||
}) | ||
else: | ||
absolute_path, relative_path, real_name = self._get_store_path(single.filename) | ||
secure_filename(single.filename) | ||
single.save(absolute_path) | ||
file = File.create_file( | ||
name=real_name, | ||
path=relative_path, | ||
extension=self._get_ext(single.filename), | ||
size=self._get_size(single), | ||
md5=file_md5, | ||
commit=True | ||
) | ||
ret.append({ | ||
"key": single.name, | ||
"id": file.id, | ||
"url": site_domain + '/assets/' + file.path | ||
}) | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters