From 27aeb902856f43bf18d96472fcf1cfe098087695 Mon Sep 17 00:00:00 2001 From: skimrme Date: Sun, 8 Feb 2026 10:54:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=98=E8=AE=B0=E5=81=9A=E4=BA=86=E4=BB=80?= =?UTF-8?q?=E4=B9=88=E5=85=88=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + blueprint/blog_views.py | 71 +++++++++++++++++++++++++++--- templates/blog/home.html | 16 +++++-- templates/blog/include/footer.html | 1 + templates/blog/paint.html | 16 +++++++ templates/blog/posts.html | 52 +++++++++++++++++++--- 6 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 templates/blog/paint.html diff --git a/.gitignore b/.gitignore index 4ef1ad2..725cacf 100755 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,7 @@ mirrors/* blueprint/kami_views.py templates/kami/* static/upload/* +static/counter.txt +static/message/* templates/message/* blueprint/massage_views.py \ No newline at end of file diff --git a/blueprint/blog_views.py b/blueprint/blog_views.py index 880adc4..f97fded 100755 --- a/blueprint/blog_views.py +++ b/blueprint/blog_views.py @@ -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//') 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}未找到该文章{posts_id}', 404 - return render_template('blog/posts.html', posts=posts, message=message[::-1]) - + shutil.rmtree(message_path) + return f'未找到该文章{posts_id}未找到该文章{posts_id}/', 404 + return render_template('blog/posts.html', posts=posts, message=message[::-1], message_ss=message_ss[::-1]) +# posts 留言 +@blog_bp.route('/posts//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 "留言成功
返回文章" + 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') \ No newline at end of file + 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" \ No newline at end of file diff --git a/templates/blog/home.html b/templates/blog/home.html index b3aa7fe..351e3da 100644 --- a/templates/blog/home.html +++ b/templates/blog/home.html @@ -97,11 +97,19 @@

更多

- my plan -
-
- essay +
+ +
+ 来源: https://greendam.icu/ +
+
+ +
+

+ 主页访问计数: {{counter}} +

+ \ No newline at end of file + + +