From 9ae4738572b2332de56a300780f84785cd30082f Mon Sep 17 00:00:00 2001 From: fujiale33 Date: Wed, 3 Jul 2019 21:05:10 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=88=90=E5=8A=9F=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E7=9A=84=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/extensions/file/local_uploader.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/extensions/file/local_uploader.py b/app/extensions/file/local_uploader.py index 07aa8bb..51f699e 100644 --- a/app/extensions/file/local_uploader.py +++ b/app/extensions/file/local_uploader.py @@ -20,7 +20,8 @@ def upload(self): ret.append({ "key": single.name, "id": exists.id, - "url": site_domain + '/assets/' + exists.path + "url": site_domain + '/assets/' + exists.path, + "path": exists.path }) else: absolute_path, relative_path, real_name = self._get_store_path(single.filename) @@ -37,6 +38,7 @@ def upload(self): ret.append({ "key": single.name, "id": file.id, - "url": site_domain + '/assets/' + file.path + "url": site_domain + '/assets/' + file.path, + "path": file.path }) return ret From 4dad6326f07ca9ab2200925a45cdf65ba731aeef Mon Sep 17 00:00:00 2001 From: fujiale33 Date: Wed, 3 Jul 2019 21:38:24 +0800 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=E5=B0=86=E5=A4=B4=E5=83=8F=E7=9A=84?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E4=BD=8D=E7=BD=AE=E6=94=B9=E4=B8=BA=E7=9B=B8?= =?UTF-8?q?=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/cms/user.py | 8 +++++++- app/extensions/file/local_uploader.py | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/api/cms/user.py b/app/api/cms/user.py index 7c1b061..8eb46f4 100644 --- a/app/api/cms/user.py +++ b/app/api/cms/user.py @@ -4,9 +4,10 @@ :copyright: © 2019 by the Lin team. :license: MIT, see LICENSE for more details. """ +import os from operator import and_ -from flask import jsonify +from flask import jsonify, current_app from flask_jwt_extended import create_access_token, get_jwt_identity, get_current_user, \ create_refresh_token, verify_jwt_refresh_token_in_request from lin.core import manager, route_meta, Log @@ -97,6 +98,11 @@ def change_password(): @login_required def get_information(): current_user = get_current_user() + site_domain = current_app.config.get('SITE_DOMAIN') if current_app.config.get( + 'SITE_DOMAIN') else "http://127.0.0.1:5000" + if current_user.avatar is not None: + current_user.avatar = site_domain + os.path.join( + current_app.static_url_path, current_user.avatar) return jsonify(current_user) diff --git a/app/extensions/file/local_uploader.py b/app/extensions/file/local_uploader.py index 51f699e..5ceda78 100644 --- a/app/extensions/file/local_uploader.py +++ b/app/extensions/file/local_uploader.py @@ -1,3 +1,5 @@ +import os + from flask import current_app from werkzeug.utils import secure_filename @@ -20,8 +22,8 @@ def upload(self): ret.append({ "key": single.name, "id": exists.id, - "url": site_domain + '/assets/' + exists.path, - "path": exists.path + "path": exists.path, + "url": site_domain + os.path.join(current_app.static_url_path, exists.path) }) else: absolute_path, relative_path, real_name = self._get_store_path(single.filename) @@ -38,7 +40,7 @@ def upload(self): ret.append({ "key": single.name, "id": file.id, - "url": site_domain + '/assets/' + file.path, - "path": file.path + "path": file.path, + "url": site_domain + os.path.join(current_app.static_url_path, exists.path) }) return ret From 90ca4f66fff5ae2dd26a966bd5abb3d1d2bdb19e Mon Sep 17 00:00:00 2001 From: fujiale33 Date: Sun, 7 Jul 2019 21:53:25 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E5=B0=86=E5=A4=B4=E5=83=8Furl?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=A7=BB=E5=88=B0=E6=A0=B8=E5=BF=83=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/cms/user.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/api/cms/user.py b/app/api/cms/user.py index 8eb46f4..0962e9f 100644 --- a/app/api/cms/user.py +++ b/app/api/cms/user.py @@ -98,11 +98,6 @@ def change_password(): @login_required def get_information(): current_user = get_current_user() - site_domain = current_app.config.get('SITE_DOMAIN') if current_app.config.get( - 'SITE_DOMAIN') else "http://127.0.0.1:5000" - if current_user.avatar is not None: - current_user.avatar = site_domain + os.path.join( - current_app.static_url_path, current_user.avatar) return jsonify(current_user) From 375bee5d1a319e7f12a1087eb4b621633319c9a9 Mon Sep 17 00:00:00 2001 From: fujiale33 Date: Tue, 9 Jul 2019 20:10:47 +0800 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20=E9=80=9A=E8=BF=87=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E5=8C=BA=E5=88=AB=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/cms/user.py | 3 +- app/app.py | 12 ++++++-- app/config/secure.py | 24 ++++++++++++++-- app/config/setting.py | 67 ++++++++++++++++++++++++++++++++----------- starter.py | 2 +- 5 files changed, 83 insertions(+), 25 deletions(-) diff --git a/app/api/cms/user.py b/app/api/cms/user.py index 0962e9f..7c1b061 100644 --- a/app/api/cms/user.py +++ b/app/api/cms/user.py @@ -4,10 +4,9 @@ :copyright: © 2019 by the Lin team. :license: MIT, see LICENSE for more details. """ -import os from operator import and_ -from flask import jsonify, current_app +from flask import jsonify from flask_jwt_extended import create_access_token, get_jwt_identity, get_current_user, \ create_refresh_token, verify_jwt_refresh_token_in_request from lin.core import manager, route_meta, Log diff --git a/app/app.py b/app/app.py index 43d2ffa..a534482 100644 --- a/app/app.py +++ b/app/app.py @@ -62,10 +62,16 @@ def log_response(resp): return resp -def create_app(register_all=True): +def create_app(register_all=True, environment='production'): app = Flask(__name__, static_folder='./assets') - app.config.from_object('app.config.setting') - app.config.from_object('app.config.secure') + app.config['ENV'] = environment + env = app.config.get('ENV') + if env == 'production': + app.config.from_object('app.config.setting.ProductionConfig') + app.config.from_object('app.config.secure.ProductionSecure') + elif env == 'development': + app.config.from_object('app.config.setting.DevelopmentConfig') + app.config.from_object('app.config.secure.DevelopmentSecure') app.config.from_object('app.config.log') if register_all: register_blueprints(app) diff --git a/app/config/secure.py b/app/config/secure.py index d4e59f0..5674b13 100644 --- a/app/config/secure.py +++ b/app/config/secure.py @@ -4,8 +4,26 @@ """ # 安全性配置 -SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:123456@localhost:3306/lin-cms' +from app.config.setting import BaseConfig -SQLALCHEMY_ECHO = False -SECRET_KEY = '\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4' +class DevelopmentSecure(BaseConfig): + """ + 开发环境安全性配置 + """ + SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:123456@localhost:3306/lin-cms' + + SQLALCHEMY_ECHO = False + + SECRET_KEY = '\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4' + + +class ProductionSecure(BaseConfig): + """ + 生产环境安全性配置 + """ + SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:123456@localhost:3306/lin-cms' + + SQLALCHEMY_ECHO = False + + SECRET_KEY = '\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4' diff --git a/app/config/setting.py b/app/config/setting.py index 950ab57..fb3aed0 100644 --- a/app/config/setting.py +++ b/app/config/setting.py @@ -5,19 +5,54 @@ from datetime import timedelta -# 分页配置 -COUNT_DEFAULT = 10 -PAGE_DEFAULT = 0 - -# 令牌配置 -JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1) - -# 屏蔽 sql alchemy 的 FSADeprecationWarning -SQLALCHEMY_TRACK_MODIFICATIONS = False - -# 插件模块暂时没有开启,以下配置可忽略 -# plugin config写在字典里面 -PLUGIN_PATH = { - 'poem': {'path': 'app.plugins.poem', 'enable': True, 'version': '0.0.1', 'limit': 20}, - 'oss': {'path': 'app.plugins.oss', 'enable': True, 'version': '0.0.1', 'access_key_id': 'not complete', 'access_key_secret': 'not complete', 'endpoint': 'http://oss-cn-shenzhen.aliyuncs.com', 'bucket_name': 'not complete', 'upload_folder': 'app', 'allowed_extensions': ['jpg', 'gif', 'png', 'bmp']} -} + +class BaseConfig(object): + """ + 基础配置 + """ + # 分页配置 + COUNT_DEFAULT = 10 + PAGE_DEFAULT = 0 + + # 屏蔽 sql alchemy 的 FSADeprecationWarning + SQLALCHEMY_TRACK_MODIFICATIONS = False + + +class DevelopmentConfig(BaseConfig): + """ + 开发环境普通配置 + """ + DEBUG = True + + # 令牌配置 + JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1) + + # 插件模块暂时没有开启,以下配置可忽略 + # plugin config写在字典里面 + PLUGIN_PATH = { + 'poem': {'path': 'app.plugins.poem', 'enable': True, 'version': '0.0.1', 'limit': 20}, + 'oss': {'path': 'app.plugins.oss', 'enable': True, 'version': '0.0.1', 'access_key_id': 'not complete', + 'access_key_secret': 'not complete', 'endpoint': 'http://oss-cn-shenzhen.aliyuncs.com', + 'bucket_name': 'not complete', 'upload_folder': 'app', + 'allowed_extensions': ['jpg', 'gif', 'png', 'bmp']} + } + + +class ProductionConfig(BaseConfig): + """ + 生产环境普通配置 + """ + DEBUG = False + + # 令牌配置 + JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1) + + # 插件模块暂时没有开启,以下配置可忽略 + # plugin config写在字典里面 + PLUGIN_PATH = { + 'poem': {'path': 'app.plugins.poem', 'enable': True, 'version': '0.0.1', 'limit': 20}, + 'oss': {'path': 'app.plugins.oss', 'enable': True, 'version': '0.0.1', 'access_key_id': 'not complete', + 'access_key_secret': 'not complete', 'endpoint': 'http://oss-cn-shenzhen.aliyuncs.com', + 'bucket_name': 'not complete', 'upload_folder': 'app', + 'allowed_extensions': ['jpg', 'gif', 'png', 'bmp']} + } diff --git a/starter.py b/starter.py index cb4f941..fc1b6cc 100644 --- a/starter.py +++ b/starter.py @@ -5,7 +5,7 @@ from app.app import create_app -app = create_app() +app = create_app(environment='development') @app.route('/', methods=['GET'], strict_slashes=False) From 4dee94734e4a3395a930489fc806d0d205ec7ed6 Mon Sep 17 00:00:00 2001 From: fujiale33 Date: Wed, 10 Jul 2019 22:18:33 +0800 Subject: [PATCH 5/6] fix: fix bug --- app/extensions/file/local_uploader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/extensions/file/local_uploader.py b/app/extensions/file/local_uploader.py index 5ceda78..161b5d2 100644 --- a/app/extensions/file/local_uploader.py +++ b/app/extensions/file/local_uploader.py @@ -41,6 +41,6 @@ def upload(self): "key": single.name, "id": file.id, "path": file.path, - "url": site_domain + os.path.join(current_app.static_url_path, exists.path) + "url": site_domain + os.path.join(current_app.static_url_path, file.path) }) return ret From 34372cfa04a4a089c39c4fa18d15e47321d53387 Mon Sep 17 00:00:00 2001 From: fujiale33 Date: Thu, 18 Jul 2019 22:59:35 +0800 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20=E5=8D=87=E7=BA=A7=E6=A0=B8?= =?UTF-8?q?=E5=BF=83=E5=BA=93=E7=89=88=E6=9C=AC=E5=8F=B7=E4=B8=BA0.2.0b1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- Pipfile | 2 +- README.md | 8 +++++--- app/api/cms/user.py | 2 +- requirements.txt | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 13cd4da..df488ed 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ __pycache__ *.pytest_cache/ *.db *.pyc -*.cpython-36.pyc \ No newline at end of file +*.cpython-36.pyc +app/assets/* diff --git a/Pipfile b/Pipfile index 1f7e95f..75b5a8f 100644 --- a/Pipfile +++ b/Pipfile @@ -12,7 +12,7 @@ Flask = "==1.0.2" Flask-SQLAlchemy = "==2.3.2" Flask-WTF = "==0.14.2" Flask-Cors = "==2.1.0" -Lin-CMS = "==0.1.1b4" +Lin-CMS = "==0.2.0b1" [dev-packages] pytest = "*" diff --git a/README.md b/README.md index 3588c96..717aeaf 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,9 @@ Lin-CMS 是林间有风团队经过大量项目实践所提炼出的一套**内 ## 最新版本 -核心库:0.1.1b3 +核心库:0.2.0b1 -示例工程:0.1.0-beta.2 +示例工程:0.2.0-beta.1 ### 文档地址 @@ -177,4 +177,6 @@ pipenv shell ## 下个版本开发计划 -- [ ] 系统访问日志、错误日志 +- [x] 系统访问日志、错误日志 +- [ ] 完善文档 +- [ ] 重构核心库结构 diff --git a/app/api/cms/user.py b/app/api/cms/user.py index 7c1b061..9096ebe 100644 --- a/app/api/cms/user.py +++ b/app/api/cms/user.py @@ -143,7 +143,7 @@ def set_avatar(): form = AvatarUpdateForm().validate_for_api() user = get_current_user() with db.auto_commit(): - user.avatar = form.avatar.data + user._avatar = form.avatar.data return Success(msg='更新头像成功') diff --git a/requirements.txt b/requirements.txt index d85fe5d..7d7e8ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ Flask-WTF==0.14.2 idna==2.6 itsdangerous==1.1.0 Jinja2==2.10 -Lin-CMS==0.1.1b4 +Lin-CMS==0.2.0b1 MarkupSafe==1.1.1 pipfile==0.0.2 PyJWT==1.7.1