忘记做了什么先上传
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
from flask import Blueprint, render_template, request, url_for, flash, redirect, send_from_directory, make_response, current_app
|
||||
from database import get_owp_db
|
||||
from flask_autoindex import AutoIndex
|
||||
from werkzeug.utils import secure_filename
|
||||
from datetime import datetime
|
||||
import os
|
||||
import sqlite3
|
||||
import time
|
||||
import json
|
||||
import shutil
|
||||
|
||||
def get_owp_db_conn():
|
||||
conn = sqlite3.connect('/var/open-ww3-project-ww3-tw/databases/sqlite/owp.db')
|
||||
@@ -29,7 +33,19 @@ def home():
|
||||
logs = conn.execute(sql_logs).fetchall()
|
||||
posts = conn.execute(sql_posts).fetchall()
|
||||
conn.close()
|
||||
return render_template('blog/home.html', logs=logs[::-1], posts=posts[::-1])
|
||||
count_file = '/var/open-ww3-project-ww3-tw/static/counter.txt'
|
||||
def load_couter():
|
||||
if os.path.exists(count_file):
|
||||
with open(count_file, 'r') as f:
|
||||
return int(f.read().strip())
|
||||
return 0
|
||||
def save_couter(couter):
|
||||
with open(count_file, 'w') as f:
|
||||
f.write(str(couter))
|
||||
counter = load_couter()
|
||||
counter += 1
|
||||
save_couter(counter)
|
||||
return render_template('blog/home.html', logs=logs[::-1], posts=posts[::-1], counter=counter)
|
||||
|
||||
@blog_bp.route('/about/')
|
||||
def about():
|
||||
@@ -46,6 +62,17 @@ def posts_list():
|
||||
|
||||
@blog_bp.route('/posts/<int:posts_id>/')
|
||||
def show_posts_id(posts_id):
|
||||
message_path = f"/var/open-ww3-project-ww3-tw/static/message/{posts_id}"
|
||||
|
||||
if not os.path.exists(message_path):
|
||||
os.makedirs(message_path)
|
||||
message_json = f"{message_path}/chat.json"
|
||||
if not os.path.exists(message_json):
|
||||
with open(message_json, 'w', encoding='utf-8') as file:
|
||||
json.dump([], file, ensure_ascii=False)
|
||||
message_ss = json.load(open(message_json, 'r', encoding='utf-8'))
|
||||
|
||||
|
||||
conn = get_owp_db_conn()
|
||||
conn_message = get_message_db_conn()
|
||||
sql_posts = "SELECT * FROM posts WHERE status = 1 AND id = ?"
|
||||
@@ -55,11 +82,33 @@ def show_posts_id(posts_id):
|
||||
conn.close()
|
||||
conn_message.close()
|
||||
if posts is None:
|
||||
return f'未找到该文章{posts_id}<title>未找到该文章{posts_id}</title>', 404
|
||||
return render_template('blog/posts.html', posts=posts, message=message[::-1])
|
||||
|
||||
shutil.rmtree(message_path)
|
||||
return f'未找到该文章{posts_id}<title>未找到该文章{posts_id}/</title>', 404
|
||||
return render_template('blog/posts.html', posts=posts, message=message[::-1], message_ss=message_ss[::-1])
|
||||
|
||||
# posts 留言
|
||||
@blog_bp.route('/posts/<int:posts_id>/chat/', methods=['POST', 'GET'])
|
||||
def posts_chat(posts_id):
|
||||
message_path = f"/var/open-ww3-project-ww3-tw/static/message/{posts_id}/chat.json"
|
||||
if request.method == "POST":
|
||||
name = request.form.get("name", None)
|
||||
data = request.form.get("data", None)
|
||||
|
||||
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
json_push = {
|
||||
"name": name,
|
||||
"data": data,
|
||||
"date": date
|
||||
}
|
||||
|
||||
with open(message_path, 'r', encoding='utf-8') as f:
|
||||
old_date_data = json.load(f)
|
||||
old_date_data.append(json_push)
|
||||
with open(message_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(old_date_data, f, ensure_ascii=False, indent=4)
|
||||
return "留言成功<br><a href='../'>返回文章</a>"
|
||||
return "GET"
|
||||
|
||||
# 数据库测试
|
||||
@blog_bp.route('/db_test/')
|
||||
@@ -120,4 +169,16 @@ def upload():
|
||||
|
||||
@blog_bp.route('/message/')
|
||||
def messages():
|
||||
return render_template('message/home.html')
|
||||
return render_template('message/home.html')
|
||||
|
||||
@blog_bp.route('/paint/')
|
||||
def paint():
|
||||
paint_path = "/var/open-ww3-project-ww3-tw/static/upload/paint_data"
|
||||
paint_json = f"{paint_path}/paint.json"
|
||||
paint_open = json.load(open(paint_json, 'r', encoding='utf-8'))
|
||||
return render_template('blog/paint.html', paint_open=paint_open)
|
||||
|
||||
@blog_bp.route('/paint/upload/', methods=['POST',])
|
||||
def paint_upload():
|
||||
if request.method == "POST":
|
||||
return "POST"
|
||||
Reference in New Issue
Block a user