忘记做了什么先上传
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,5 +7,7 @@ mirrors/*
|
|||||||
blueprint/kami_views.py
|
blueprint/kami_views.py
|
||||||
templates/kami/*
|
templates/kami/*
|
||||||
static/upload/*
|
static/upload/*
|
||||||
|
static/counter.txt
|
||||||
|
static/message/*
|
||||||
templates/message/*
|
templates/message/*
|
||||||
blueprint/massage_views.py
|
blueprint/massage_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 flask import Blueprint, render_template, request, url_for, flash, redirect, send_from_directory, make_response, current_app
|
||||||
from database import get_owp_db
|
from database import get_owp_db
|
||||||
from flask_autoindex import AutoIndex
|
from flask_autoindex import AutoIndex
|
||||||
|
from werkzeug.utils import secure_filename
|
||||||
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
|
import shutil
|
||||||
|
|
||||||
def get_owp_db_conn():
|
def get_owp_db_conn():
|
||||||
conn = sqlite3.connect('/var/open-ww3-project-ww3-tw/databases/sqlite/owp.db')
|
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()
|
logs = conn.execute(sql_logs).fetchall()
|
||||||
posts = conn.execute(sql_posts).fetchall()
|
posts = conn.execute(sql_posts).fetchall()
|
||||||
conn.close()
|
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/')
|
@blog_bp.route('/about/')
|
||||||
def about():
|
def about():
|
||||||
@@ -46,6 +62,17 @@ def posts_list():
|
|||||||
|
|
||||||
@blog_bp.route('/posts/<int:posts_id>/')
|
@blog_bp.route('/posts/<int:posts_id>/')
|
||||||
def show_posts_id(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 = get_owp_db_conn()
|
||||||
conn_message = get_message_db_conn()
|
conn_message = get_message_db_conn()
|
||||||
sql_posts = "SELECT * FROM posts WHERE status = 1 AND id = ?"
|
sql_posts = "SELECT * FROM posts WHERE status = 1 AND id = ?"
|
||||||
@@ -55,11 +82,33 @@ def show_posts_id(posts_id):
|
|||||||
conn.close()
|
conn.close()
|
||||||
conn_message.close()
|
conn_message.close()
|
||||||
if posts is None:
|
if posts is None:
|
||||||
return f'未找到该文章{posts_id}<title>未找到该文章{posts_id}</title>', 404
|
shutil.rmtree(message_path)
|
||||||
return render_template('blog/posts.html', posts=posts, message=message[::-1])
|
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/')
|
@blog_bp.route('/db_test/')
|
||||||
@@ -121,3 +170,15 @@ def upload():
|
|||||||
@blog_bp.route('/message/')
|
@blog_bp.route('/message/')
|
||||||
def messages():
|
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"
|
||||||
@@ -97,12 +97,20 @@
|
|||||||
<div id="class">
|
<div id="class">
|
||||||
<h1></h1>
|
<h1></h1>
|
||||||
<h1>更多</h1>
|
<h1>更多</h1>
|
||||||
my plan
|
<form action="https://greendam.icu/" method="get">
|
||||||
|
<button>随机一张格林达姆</button>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
来源: <a href="https://greendam.icu/">https://greendam.icu/</a>
|
||||||
essay
|
</form>
|
||||||
|
<form action="./paint/" method="get">
|
||||||
|
<button>paint</button>
|
||||||
|
</form>
|
||||||
|
<p style="margin: 870px 0 0 0; text-align: center; color: white;">
|
||||||
|
主页访问计数: {{counter}}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#class {
|
#class {
|
||||||
margin: 0 0 0 0;
|
margin: 0 0 0 0;
|
||||||
|
|||||||
@@ -37,4 +37,5 @@
|
|||||||
<a href="https://icp.hentioe.dev/sites/20257900" target="_blank">喵ICP备20257900号</a>
|
<a href="https://icp.hentioe.dev/sites/20257900" target="_blank">喵ICP备20257900号</a>
|
||||||
<br>
|
<br>
|
||||||
<a href="https://icp.redcha.cn/beian/ICP-2026010278.html" title="茶ICP备2026010278号" target="_blank">茶ICP备2026010278号</a>
|
<a href="https://icp.redcha.cn/beian/ICP-2026010278.html" title="茶ICP备2026010278号" target="_blank">茶ICP备2026010278号</a>
|
||||||
|
<br>
|
||||||
</footer>
|
</footer>
|
||||||
16
templates/blog/paint.html
Normal file
16
templates/blog/paint.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{# 引入base #}
|
||||||
|
{% extends 'blog/extension/base.html' %}
|
||||||
|
|
||||||
|
{# 引入标题 #}
|
||||||
|
{% block title %}paint{% endblock %}
|
||||||
|
|
||||||
|
{% include 'blog/include/head.html' %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% include 'blog/include/navbar.html' %}
|
||||||
|
施工中...
|
||||||
|
<br>
|
||||||
|
这里会展示我绘制的一些屑作....
|
||||||
|
<br>
|
||||||
|
{% endblock %}
|
||||||
@@ -2,6 +2,13 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{{ posts['title'] }}</title>
|
<title>{{ posts['title'] }}</title>
|
||||||
|
<link rel="icon" type="image/x-icon" href="/static/icon/original.ico">
|
||||||
|
<meta property="og:title" content="{{ posts['title'] }}">
|
||||||
|
<meta property="og:description" content="{{ posts['content']}}">
|
||||||
|
<meta property="og:image" content="https://ww3.tw/static/img/open-ww3-project.png">
|
||||||
|
<meta property="og:url" content="https://ww3.tw/blog/posts/{{ posts['id']}}/">
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
</head>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<a href="/blog">返回主页</a>
|
<a href="/blog">返回主页</a>
|
||||||
@@ -13,11 +20,24 @@
|
|||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
<hr>
|
||||||
<h2>留言区: </h2>
|
<h2>留言区: </h2>
|
||||||
{% for message in message %}
|
<form method="post" action="./chat/">
|
||||||
[ {{ message['name'] }} ] >$
|
昵称: (20字)
|
||||||
{{ message['content'] }}<br>
|
<input type="text" name="name" maxlength="20" required>
|
||||||
{{ message['date'] }}
|
<br>
|
||||||
|
留言内容: (100字)
|
||||||
|
<br>
|
||||||
|
<textarea name="data" maxlength="100" style="height: 60px;" required></textarea>
|
||||||
|
<button type="submit">发送</button>
|
||||||
|
</form>
|
||||||
|
<br>
|
||||||
|
{% for message_ss in message_ss %}
|
||||||
|
<span class="msg-date">{{message_ss.date}}</span>
|
||||||
|
<br>
|
||||||
|
[{{message_ss.name}}@arch-cat ArchLinux]
|
||||||
|
<br>
|
||||||
|
$ {{message_ss.data}}
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -31,3 +51,25 @@
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelectorAll('.msg-date').forEach(el => {
|
||||||
|
let dateStr = el.innerText.trim();
|
||||||
|
if (dateStr) {
|
||||||
|
// 兼容 ISO 格式,将空格替换为 T 方便解析
|
||||||
|
let date = new Date(dateStr.replace(' ', 'T'));
|
||||||
|
// 增加 8 小时
|
||||||
|
date.setHours(date.getHours() + 8);
|
||||||
|
|
||||||
|
// 格式化回 YYYY-MM-DD HH:mm:ss
|
||||||
|
let formatted = date.getFullYear() + '-' +
|
||||||
|
String(date.getMonth() + 1).padStart(2, '0') + '-' +
|
||||||
|
String(date.getDate()).padStart(2, '0') + ' ' +
|
||||||
|
String(date.getHours()).padStart(2, '0') + ':' +
|
||||||
|
String(date.getMinutes()).padStart(2, '0') + ':' +
|
||||||
|
String(date.getSeconds()).padStart(2, '0');
|
||||||
|
|
||||||
|
el.innerText = formatted;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user