Add timestamps and file upload precheck
This commit is contained in:
25
back/main.py
25
back/main.py
@@ -52,6 +52,7 @@ class Submission(db.Model):
|
||||
identity_token = db.Column(db.String(36), nullable=True)
|
||||
status = db.Column(db.String(20), default='Pending')
|
||||
created_at = db.Column(db.DateTime, default=lambda: datetime.now())
|
||||
updated_at = db.Column(db.DateTime, default=lambda: datetime.now())
|
||||
upvotes = db.Column(db.Integer, default=0)
|
||||
downvotes = db.Column(db.Integer, default=0)
|
||||
|
||||
@@ -153,7 +154,9 @@ def get_settings():
|
||||
"footer_text": settings.footer_text,
|
||||
"repo_link": settings.repo_link,
|
||||
"enable_repo_button": settings.enable_repo_button,
|
||||
"enable_notice": settings.enable_notice
|
||||
"enable_notice": settings.enable_notice,
|
||||
"file_size_limit": settings.file_size_limit,
|
||||
"file_formats": settings.file_formats
|
||||
}
|
||||
return jsonify({
|
||||
"code": 1000,
|
||||
@@ -252,10 +255,13 @@ def submit_post():
|
||||
identity_token = None
|
||||
|
||||
# 保存
|
||||
now = datetime.now()
|
||||
new_post = Submission(
|
||||
content=content,
|
||||
identity_token=identity_token,
|
||||
status='Pending' if NEED_AUDIT else 'Pass'
|
||||
status='Pending' if NEED_AUDIT else 'Pass',
|
||||
created_at=now,
|
||||
updated_at=now,
|
||||
)
|
||||
db.session.add(new_post)
|
||||
db.session.commit()
|
||||
@@ -349,6 +355,10 @@ def submit_report():
|
||||
submission_id = data.get('id')
|
||||
title = data.get('title')
|
||||
content = data.get('content')
|
||||
title = str(title).strip() if title is not None else ''
|
||||
content = str(content).strip() if content is not None else ''
|
||||
if not title or not content:
|
||||
return jsonify({"code": 2000, "data": "参数错误"})
|
||||
|
||||
submission = db.session.get(Submission, submission_id)
|
||||
if not submission:
|
||||
@@ -363,8 +373,8 @@ def submit_report():
|
||||
|
||||
report = Report(
|
||||
submission_id=submission_id,
|
||||
title=str(title).strip() if title is not None else '',
|
||||
content=str(content).strip() if content is not None else '',
|
||||
title=title,
|
||||
content=content,
|
||||
identity_token=identity_token,
|
||||
status='Pending',
|
||||
)
|
||||
@@ -399,7 +409,8 @@ def get_comments():
|
||||
"id": c.id,
|
||||
"nickname": c.nickname,
|
||||
"content": c.content,
|
||||
"parent_comment_id": c.parent_comment_id if c.parent_comment_id is not None else 0
|
||||
"parent_comment_id": c.parent_comment_id if c.parent_comment_id is not None else 0,
|
||||
"time": c.created_at.isoformat() if c.created_at else None
|
||||
} for c in pagination.items]
|
||||
|
||||
return jsonify({"code": 1000, "data": {"comments": data, "total_pages": pagination.pages}})
|
||||
@@ -549,6 +560,8 @@ def get_posts_info():
|
||||
"upvotes": s.upvotes,
|
||||
"downvotes": s.downvotes,
|
||||
"created_at": s.created_at.isoformat() if s.created_at else None,
|
||||
"time": s.created_at.isoformat() if s.created_at else None,
|
||||
"modified": 0 if (not s.updated_at or not s.created_at or s.updated_at == s.created_at) else 1,
|
||||
"comment_count": len(s.comments),
|
||||
"total_pages": pagination.total,
|
||||
})
|
||||
@@ -577,6 +590,8 @@ def get_post_info():
|
||||
"upvotes": submission.upvotes,
|
||||
"downvotes": submission.downvotes,
|
||||
"created_at": submission.created_at.isoformat() if submission.created_at else None,
|
||||
"time": submission.created_at.isoformat() if submission.created_at else None,
|
||||
"modified": 0 if (not submission.updated_at or not submission.created_at or submission.updated_at == submission.created_at) else 1,
|
||||
"comment_count": len(submission.comments),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user