Add site notice and timestamp display updates
This commit is contained in:
34
back/main.py
34
back/main.py
@@ -97,6 +97,15 @@ class ImgFile(db.Model):
|
||||
name = db.Column(db.String(255), nullable=True)
|
||||
identity_token = db.Column(db.String(36), nullable=True)
|
||||
|
||||
class SiteNotice(db.Model):
|
||||
__tablename__ = 'site_notice'
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
type = db.Column(db.String(10), default='md', nullable=False)
|
||||
content = db.Column(db.Text, default='', nullable=False)
|
||||
version = db.Column(db.Integer, default=0, nullable=False)
|
||||
created_at = db.Column(db.DateTime, default=lambda: datetime.now())
|
||||
updated_at = db.Column(db.DateTime, default=lambda: datetime.now(), onupdate=datetime.now)
|
||||
|
||||
# 初始化数据库函数
|
||||
def init_db():
|
||||
if not os.path.exists('./data'):
|
||||
@@ -105,6 +114,14 @@ def init_db():
|
||||
os.makedirs(IMG_DIR)
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
try:
|
||||
existing = SiteNotice.query.first()
|
||||
if not existing:
|
||||
n = SiteNotice(type='md', content='', version=0)
|
||||
db.session.add(n)
|
||||
db.session.commit()
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
|
||||
def load_config():
|
||||
global NEED_AUDIT, FILE_SIZE_LIMIT_MB, FILE_FORMATS
|
||||
@@ -180,6 +197,23 @@ def get_about():
|
||||
"data": "# 默认关于页面\n关于页面未设置,请前往管理面板操作。"
|
||||
})
|
||||
|
||||
@app.route('/api/site_notice', methods=['GET'])
|
||||
def get_site_notice():
|
||||
try:
|
||||
notice = SiteNotice.query.order_by(SiteNotice.id.asc()).first()
|
||||
if not notice:
|
||||
notice = SiteNotice(type='md', content='', version=0)
|
||||
db.session.add(notice)
|
||||
db.session.commit()
|
||||
data = {
|
||||
"type": notice.type if notice.type in ['md', 'url'] else 'md',
|
||||
"content": notice.content or '',
|
||||
"version": int(notice.version or 0),
|
||||
}
|
||||
return jsonify({"code": 1000, "data": data})
|
||||
except Exception as e:
|
||||
return jsonify({"code": 2003, "data": str(e)})
|
||||
|
||||
@app.route('/api/get_id_token', methods=['GET'])
|
||||
def get_id_token():
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user