环境搭建配置

This commit is contained in:
super
2026-03-21 10:00:16 +08:00
parent 32f4705491
commit 7f9a6bd9cb
38 changed files with 885 additions and 611 deletions

12
app/.env Normal file
View File

@@ -0,0 +1,12 @@
base_url=http://159.75.121.33:15124
workflow_id=7608812635877900322
mysql_host=159.75.121.33
mysql_user=AIimage
proxy_url=https://api.jikip.com/ip-get?num=1&minute=1&format=json&area=all&protocol=1&mode=2&key=r4m8dov52giup2o
proxy_mode=2
client_name=NanriAI
java_api_base=http://127.0.0.1:18080

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -37,7 +37,7 @@ app = create_app()
def run_app(host='127.0.0.1', port=5123):
init_db()
# init_db()
app.run(host=host, port=port, threaded=True, use_reloader=False)

View File

@@ -14,6 +14,7 @@ from config import mysql_host, mysql_user, mysql_password, mysql_database
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_DIR = os.path.join(BASE_DIR, 'static')
ASSETS_DIR = os.path.join(BASE_DIR, 'assets')
def get_db():
@@ -42,6 +43,22 @@ def _render_html(template_name: str, **context):
return render_template_string(content, **context)
def _render_html_new(template_name: str, **context):
"""读取 HTML 模板:若为加密文件则先解密,再渲染。未加密或解密失败时按明文渲染。"""
path = os.path.join(BASE_DIR, "web_source", template_name)
if not os.path.isfile(path):
return render_template(template_name, **context)
with open(path, "rb") as f:
raw = f.read()
try:
from html_crypto import decrypt
content = decrypt(raw).decode("utf-8")
except Exception:
content = raw.decode("utf-8", errors="replace")
return render_template_string(content, **context)
def _is_session_user_valid():
"""校验 session 中的 user_id 是否在数据库中仍存在;不存在则清除 session 并返回 False"""
uid = session.get('user_id')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -2,7 +2,8 @@
主页面蓝图首页、home、图片工作台、品牌页、静态文件、Logo
"""
import os
from flask import Blueprint, send_file
import requests
from flask import Blueprint, Response, request, send_file
from app_common import (
get_db,
@@ -16,7 +17,9 @@ from app_common import (
)
from flask import redirect, url_for, session
from config import base_url,version
from config import base_url,version,java_api_base
JAVA_API_BASE = java_api_base
main_bp = Blueprint('main', __name__)
@@ -90,6 +93,36 @@ def serve_new_web_source(filename):
@main_bp.route('/newApi/<path:subpath>', methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'])
def proxy_new_api(subpath):
target_url = f"{JAVA_API_BASE}/{subpath}"
try:
headers = {
key: value
for key, value in request.headers.items()
if key.lower() not in {'host', 'content-length'}
}
upstream = requests.request(
method=request.method,
url=target_url,
params=request.args,
data=request.get_data(),
headers=headers,
cookies=request.cookies,
allow_redirects=False,
timeout=300,
)
excluded_headers = {'content-encoding', 'content-length', 'transfer-encoding', 'connection'}
response_headers = [
(name, value)
for name, value in upstream.headers.items()
if name.lower() not in excluded_headers
]
return Response(upstream.content, upstream.status_code, response_headers)
except requests.RequestException as exc:
return {'success': False, 'message': str(exc), 'data': None}, 502
@main_bp.route('/logo.jpg', methods=['GET'])
def get_logo_image():
return send_file(os.path.join(BASE_DIR, "logo.jpg"), mimetype='image/jpeg')

Binary file not shown.

Binary file not shown.

View File

@@ -7,6 +7,7 @@ import os
from dotenv import load_dotenv
load_dotenv()
_base_url = os.getenv("base_url","http://159.75.121.33:15124")
java_api_base = os.getenv("java_api_base", "http://127.0.0.1:18080")
# MySQL 配置
mysql_host = os.getenv("mysql_host")
@@ -16,6 +17,7 @@ mysql_database = os.getenv("mysql_database","aiimage")
proxy_url = os.getenv("proxy_url")
proxy_mode = int(os.getenv("proxy_mode",1))
client_name=os.getenv("client_name") + ".exe"
cache_path = "./user_data"

View File

@@ -1,7 +1,7 @@
"""
基于 pywebview 实现的跨平台 UI需先登录方可使用
"""
from config import cache_path,debug,version
from config import cache_path,debug,version,java_api_base
import datetime
import json
import sys
@@ -15,6 +15,7 @@ if not debug:
import webview
import threading
import time
import requests
with open("version.txt","w",encoding="utf-8") as file:
@@ -25,6 +26,7 @@ with open("version.txt","w",encoding="utf-8") as file:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
APP_URL = "http://127.0.0.1:5123"
PORT = 5123
JAVA_API_BASE = java_api_base
def generate_images(params):
@@ -143,6 +145,28 @@ class WindowAPI:
)
return result[0] if result else ''
def upload_file_to_java(self, file_path):
"""按本地路径读取文件并上传到 Java 后端临时目录。"""
if not file_path or not str(file_path).strip():
return {'success': False, 'error': '文件路径为空'}
normalized_path = os.path.abspath(str(file_path).strip())
if not os.path.isfile(normalized_path):
return {'success': False, 'error': '文件不存在'}
try:
with open(normalized_path, 'rb') as file_obj:
response = requests.post(
f"{JAVA_API_BASE}/api/files/upload",
files={'file': (os.path.basename(normalized_path), file_obj)},
timeout=120,
)
response.raise_for_status()
payload = response.json()
if not isinstance(payload, dict):
return {'success': False, 'error': 'Java 返回格式错误'}
return payload
except Exception as e:
return {'success': False, 'error': str(e)}
def save_file_from_url(self, url, default_filename='download.zip'):
"""弹窗选择保存位置,从 url 下载文件并保存。用于品牌任务结果 zip 等。"""
if not url or not url.strip():
@@ -332,7 +356,7 @@ def main():
easy_drag=True
)
api = WindowAPI(window)
window.expose(api.close, api.minimize, api.maximize, api.toggle_maximize, generate_images, api.save_image, api.save_image_to_folder, api.select_folder, api.select_brand_xlsx_files, api.select_brand_folder, api.save_file_from_url, api.save_template_xlsx,api.save_template_zip)
window.expose(api.close, api.minimize, api.maximize, api.toggle_maximize, generate_images, api.save_image, api.save_image_to_folder, api.select_folder, api.select_brand_xlsx_files, api.select_brand_folder, api.upload_file_to_java, api.save_file_from_url, api.save_template_xlsx,api.save_template_zip)
webview.start(
debug=True,
storage_path=cache_path,

Binary file not shown.

1
app/version.txt Normal file
View File

@@ -0,0 +1 @@
{"version": "1.0.3"}