初始化提交

This commit is contained in:
2025-12-13 21:35:46 +08:00
parent 487457e0a9
commit 4573a21f88
54 changed files with 20690 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
# 环境配置文件示例
# 复制此文件为 .env 并修改相应的值
# Flask 配置
FLASK_APP=app.py
FLASK_ENV=development
FLASK_DEBUG=True
# 服务器配置
HOST=0.0.0.0
PORT=5000
# CORS 配置(前端地址)
FRONTEND_URL=http://localhost:3000

42
mengyaprofile-backend/.gitignore vendored Normal file
View File

@@ -0,0 +1,42 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# Flask
instance/
.webassets-cache
# IDEs
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Logs
*.log

View File

@@ -0,0 +1,33 @@
# 萌芽个人主页 - 后端
基于 Flask 的个人主页后端 API 服务。
## 安装依赖
```bash
pip install -r requirements.txt
```
## 运行服务
```bash
python app.py
```
服务将运行在 `http://localhost:5000`
## API 接口
- `GET /api/profile` - 获取个人基本信息
- `GET /api/projects` - 获取精选项目列表
- `GET /api/contacts` - 获取联系方式
- `GET /api/all` - 获取所有数据
## 数据配置
数据存储在 `data` 目录下的 JSON 文件中:
- `profile.json` - 个人信息
- `projects.json` - 项目列表
- `contacts.json` - 联系方式
可根据需要编辑这些文件来更新网站内容。

View File

@@ -0,0 +1,173 @@
from flask import Flask, jsonify, send_from_directory, request
from flask_cors import CORS
import json
import os
import random
# 检测运行模式:通过环境变量控制
RUN_MODE = os.environ.get('RUN_MODE', 'development') # development 或 production
# 根据运行模式配置
if RUN_MODE == 'production':
# 生产环境:使用构建后的前端
FRONTEND_BUILD_PATH = os.path.join(os.path.dirname(__file__), '..', 'frontend', 'build')
app = Flask(__name__, static_folder=FRONTEND_BUILD_PATH, static_url_path='')
BACKGROUND_DIR = os.path.join(FRONTEND_BUILD_PATH, 'background')
else:
# 开发环境:不服务前端,只提供 API
app = Flask(__name__)
BACKGROUND_DIR = os.path.join(os.path.dirname(__file__), '..', 'mengyaprofile-frontend', 'public', 'background')
CORS(app) # 允许跨域请求
# 数据文件路径 - 支持环境变量配置
DATA_DIR = os.environ.get('DATA_DIR', os.path.join(os.path.dirname(__file__), 'data'))
def load_json_file(filename):
"""加载JSON文件"""
try:
with open(os.path.join(DATA_DIR, filename), 'r', encoding='utf-8') as f:
return json.load(f)
except FileNotFoundError:
return None
except Exception as e:
print(f"Error loading {filename}: {e}")
return None
@app.route('/api/profile', methods=['GET'])
def get_profile():
"""获取个人基本信息"""
data = load_json_file('profile.json')
if data:
return jsonify(data)
return jsonify({"error": "Profile没有找到"}), 404
@app.route('/api/projects', methods=['GET'])
def get_projects():
"""获取精选项目列表"""
data = load_json_file('projects.json')
if data:
return jsonify(data)
return jsonify({"error": "Projects没有找到"}), 404
@app.route('/api/contacts', methods=['GET'])
def get_contacts():
"""获取联系方式"""
data = load_json_file('contacts.json')
if data:
return jsonify(data)
return jsonify({"error": "Contacts没有找到"}), 404
@app.route('/api/techstack', methods=['GET'])
def get_techstack():
"""获取技术栈"""
data = load_json_file('techstack.json')
if data:
return jsonify(data)
return jsonify({"error": "Tech stack没有找到"}), 404
@app.route('/api/random-background', methods=['GET'])
def get_random_background():
"""获取随机背景图片"""
try:
# 获取背景图片目录中的所有图片
if os.path.exists(BACKGROUND_DIR):
images = [f for f in os.listdir(BACKGROUND_DIR)
if f.lower().endswith(('.png', '.jpg', '.jpeg', '.webp', '.gif'))]
if images:
random_image = random.choice(images)
return jsonify({"image": f"/background/{random_image}"})
return jsonify({"image": None})
except Exception as e:
print(f"获取随机背景出错: {e}")
return jsonify({"image": None})
@app.route('/api/all', methods=['GET'])
def get_all():
"""获取所有数据"""
profile = load_json_file('profile.json')
projects = load_json_file('projects.json')
contacts = load_json_file('contacts.json')
techstack = load_json_file('techstack.json')
return jsonify({
"profile": profile,
"techstack": techstack,
"projects": projects,
"contacts": contacts
})
@app.route('/', methods=['GET'])
def index():
"""服务前端页面或API信息"""
if RUN_MODE == 'production' and app.static_folder:
# 生产环境,返回前端页面
return send_from_directory(app.static_folder, 'index.html')
else:
# 开发环境,返回API信息
return jsonify({
"message": "萌芽主页 后端API - 开发模式",
"author": "树萌芽",
"version": "1.0.0",
"mode": "development",
"note": "前端开发服务器运行在 http://localhost:3000",
"endpoints": {
"/api/profile": "获取个人信息",
"/api/techstack": "获取技术栈",
"/api/projects": "获取项目列表",
"/api/contacts": "获取联系方式",
"/api/random-background": "获取随机背景图片",
"/api/all": "获取所有数据"
}
})
@app.route('/admin')
def admin():
"""服务管理员页面(也是前端)"""
if RUN_MODE == 'production' and app.static_folder:
return send_from_directory(app.static_folder, 'index.html')
else:
return jsonify({
"error": "开发模式",
"note": "请访问 http://localhost:3000/admin?token=shumengya520"
}), 404
@app.route('/api')
def api_info():
"""API信息"""
return jsonify({
"message": "萌芽主页 后端API",
"author":"树萌芽",
"version": "1.0.0",
"endpoints": {
"/api/profile": "获取个人信息",
"/api/techstack": "获取技术栈",
"/api/projects": "获取项目列表",
"/api/contacts": "获取联系方式",
"/api/random-background": "获取随机背景图片",
"/api/all": "获取所有数据"
}
})
# 处理前端路由 - 所有非API请求都返回 index.html
@app.errorhandler(404)
def not_found(e):
"""处理404错误"""
# 检查是否为API请求
if request.path.startswith('/api'):
return jsonify({"error": "API endpoint not found"}), 404
# 非API请求
if RUN_MODE == 'production' and app.static_folder:
# 生产环境返回前端页面(支持前端路由)
return send_from_directory(app.static_folder, 'index.html')
# 开发环境
return jsonify({
"error": "页面未找到",
"mode": "development",
"note": "开发环境请访问 http://localhost:3000"
}), 404
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)

View File

@@ -0,0 +1,39 @@
{
"contacts": [
{
"type": "qq",
"label": "QQ",
"value": "3205788256",
"link": "tencent://message/?uin=123456789",
"icon": "https://img.shumengya.top/i/2025/11/02/69076687211f9.webp"
},
{
"type": "email",
"label": "QQ邮箱",
"value": "3205788256@qq.com",
"link": "mailto:3205788256@qq.com",
"icon": "https://img.shumengya.top/i/2025/11/02/690766903514e.webp"
},
{
"type": "email",
"label": "谷歌邮箱",
"value": "shumengya666@gmail.com",
"link": "mailto:shumengya666@gmail.com",
"icon": "https://img.shumengya.top/i/2025/11/03/6908321840ea6.webp"
},
{
"type": "personprofile",
"label": "个人主页",
"value": "shumengya.top",
"link": "https://shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/03/690836f3c87b2.png"
},
{
"type": "github",
"label": "GitHub",
"value": "github.com/shumengya",
"link": "https://github.com/shumengya",
"icon": "https://img.shumengya.top/i/2025/11/03/69083414ceb01.webp"
}
]
}

View File

@@ -0,0 +1,8 @@
{
"favicon":"https://img.shumengya.top/i/2025/11/03/690836f3c87b2.png",
"nickname": "树萌芽吖",
"avatar": "https://img.shumengya.top/i/2025/11/02/69073c018174e.webp",
"introduction": "热爱编程,享受创造的过程。持续学习新技术,用代码实现想法。",
"footer":"© 2025 萌芽主页-蜀ICP备2025151694号",
"showlocalbackground":true
}

View File

@@ -0,0 +1,170 @@
{
"projects": [
{
"id": 1,
"title": "萌芽盘",
"description": "一个轻量级在线网盘,支持文件上传、下载、分享等功能",
"link": "https://pan.shumengya.top",
"icon": "https://image.shumengya.top/i/2025/11/02/openlist.png",
"tags": ["网盘","OpenList"],
"admin":false,
"show":true,
"develop":false
},
{
"id": 2,
"title": "萌芽主页",
"description": "一个简洁美观的个人主页,展示个人信息和项目",
"link": "https://shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/03/690836f3c87b2.png",
"tags": ["个人主页"],
"admin":false,
"show":true,
"develop":true
},
{
"id": 3,
"title": "萌芽Git仓库",
"description": "自部署私有化Git仓库",
"link": "https://repo.shumengya.top",
"icon": "https://image.shumengya.top/i/2025/11/02/gitea.png",
"tags": ["Gitea", "GitHub"],
"admin":false,
"show":true,
"develop":false
},
{
"id": 4,
"title": "萌芽快传",
"description": "像取快递一样方便的寄送文件",
"link": "https://send.shumengya.top",
"icon": "https://image.shumengya.top/i/2025/11/02/filecodebox.png",
"tags": ["FileCodeBox", "文件快传"],
"admin":false,
"show":true,
"develop":false
},
{
"id": 5,
"title": "萌芽图床",
"description": "简单易用的图床,将您的图片转化为一段网页链接",
"link": "https://img.shumengya.top",
"icon": "https://image.shumengya.top/i/2025/11/02/mengyaimgbed.png",
"tags": [ "图床"],
"admin":false,
"show":true,
"develop":false
},
{
"id": 6,
"title": "萌芽笔记",
"description": "展示自己学习过程中的一些MarkDown笔记",
"link": "https://note.shumengya.top",
"icon": "https://image.shumengya.top/i/2025/11/02/mengyanote.png",
"tags": [ "笔记","Obsidion"],
"admin":false,
"show":true,
"develop":true
},
{
"id": 7,
"title": "萌芽作品集",
"description": "展示个人制作的一些小创意和小项目",
"link": "https://work.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/02/69074f8f5ed5e.png",
"tags": [ "作品集"],
"admin":false,
"show":true,
"develop":true
},
{
"id": 8,
"title": "万象口袋",
"description": "一款跨平台的聚合式软件",
"link": "https://infogenie.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/02/6907516fb77d5.png",
"tags": [ "聚合","工具"],
"admin":false,
"show":true,
"develop":true
},
{
"id": 9,
"title": "萌芽农场",
"description": "一款2D平台联机农场经营游戏",
"link": "https://work.shumengya.top/#/work/mengyafarm",
"icon": "https://img.shumengya.top/i/2025/11/02/6907599cbaf10.png",
"tags": [ "农场","游戏","联机"],
"admin":false,
"show":true,
"develop":true
},
{
"id": 10,
"title": "1Panel面板",
"description": "大萌芽1panel面板后台",
"link": "https://1panel.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/02/69076213d9200.webp",
"tags": [ "1Panel","面板"],
"admin":true,
"show":true,
"develop":false
},
{
"id": 11,
"title": "DPanel面板",
"description": "大萌芽dpanel面板后台",
"link": "https://dpanel.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/02/6907621448bac.png",
"tags": [ "Docker","面板"],
"admin":true,
"show":true,
"develop":false
},
{
"id": 12,
"title": "Frps管理后台",
"description": "成都公网内网穿透服务端",
"link": "https://frps.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/02/6907621475130.png",
"tags": [ "内网穿透","Frp"],
"admin":true,
"show":true,
"develop":false
},
{
"id": 13,
"title": "Frpc管理后台",
"description": "大萌芽内网穿透客户端",
"link": "https://frpc.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/02/6907621475130.png",
"tags": [ "内网穿透","Frp"],
"admin":true,
"show":true,
"develop":false
},
{
"id": 13,
"title": "萌芽问卷",
"description": "一个轻量简单的问卷系统",
"link": "https://survey.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/02/690762865166c.png",
"tags": [ "问卷","调查","SurveyKing"],
"admin":false,
"show":true,
"develop":false
},
{
"id": 14,
"title": "HeadScale管理后台",
"description": "一个自建tailscale管理后台",
"link": "https://headscale.shumengya.top",
"icon": "https://img.shumengya.top/i/2025/11/03/6908327149dce.png",
"tags": [ "TailScale","HeadScale"],
"admin":true,
"show":true,
"develop":false
}
]
}

View File

@@ -0,0 +1,115 @@
{
"title": "技术栈",
"items": [
{
"name": "Python",
"icon": "https://img.shields.io/badge/-Python-3776AB?style=flat&logo=python&logoColor=white",
"link": "https://www.python.org/"
},
{
"name": "JavaScript",
"icon": "https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black",
"link": "https://developer.mozilla.org/en-US/docs/Web/JavaScript"
},
{
"name": "Java",
"icon": "https://img.shields.io/badge/-Java-007396?style=flat&logo=java&logoColor=white",
"link": "https://www.oracle.com/java/"
},
{
"name": "C#",
"icon": "https://img.shields.io/badge/-C%23-512BD4?style=flat&logo=csharp&logoColor=white",
"link": "https://learn.microsoft.com/en-us/dotnet/csharp/"
},
{
"name": "Golang",
"icon": "https://img.shields.io/badge/-Golang-00ADD8?style=flat&logo=go&logoColor=white",
"link": "https://go.dev/"
},
{
"name": "React",
"icon": "https://img.shields.io/badge/-React-20232A?style=flat&logo=react&logoColor=61DAFB",
"link": "https://react.dev/"
},
{
"name": "Node.js",
"icon": "https://img.shields.io/badge/-Node.js-339933?style=flat&logo=nodedotjs&logoColor=white",
"link": "https://nodejs.org/"
},
{
"name": "Docker",
"icon": "https://img.shields.io/badge/-Docker-2496ED?style=flat&logo=docker&logoColor=white",
"link": "https://www.docker.com/"
},
{
"name": "Linux",
"icon": "https://img.shields.io/badge/-Linux-000000?style=flat&logo=linux&logoColor=white",
"link": "https://www.linux.org/"
},
{
"name": "Git",
"icon": "https://img.shields.io/badge/-Git-F05032?style=flat&logo=git&logoColor=white",
"link": "https://git-scm.com/"
},
{
"name": "Flask",
"icon": "https://img.shields.io/badge/-Flask-000000?style=flat&logo=flask&logoColor=white",
"link": "https://flask.palletsprojects.com/"
},
{
"name": "MongoDB",
"icon": "https://img.shields.io/badge/-MongoDB-47A248?style=flat&logo=mongodb&logoColor=white",
"link": "https://www.mongodb.com/"
},
{
"name": "PostgreSQL",
"icon": "https://img.shields.io/badge/-PostgreSQL-4169E1?style=flat&logo=postgresql&logoColor=white",
"link": "https://www.postgresql.org/"
},
{
"name": "MySQL",
"icon": "https://img.shields.io/badge/-MySQL-00758F?style=flat&logo=mysql&logoColor=white",
"link": "https://www.mysql.com/"
},
{
"name": "Redis",
"icon": "https://img.shields.io/badge/-Redis-DC382D?style=flat&logo=redis&logoColor=white",
"link": "https://redis.io/"
},
{
"name": "Android",
"icon": "https://img.shields.io/badge/-Android-3DDC84?style=flat&logo=android&logoColor=white",
"link": "https://developer.android.com/"
},
{
"name": "Flutter",
"icon": "https://img.shields.io/badge/-Flutter-02569B?style=flat&logo=flutter&logoColor=white",
"link": "https://flutter.dev/"
},
{
"name": "Godot",
"icon": "https://img.shields.io/badge/-Godot-478CBF?style=flat&logo=godot&logoColor=white",
"link": "https://godotengine.org/"
},
{
"name": "Unity",
"icon": "https://img.shields.io/badge/-Unity-000000?style=flat&logo=unity&logoColor=white",
"link": "https://unity.com/"
},
{
"name": "JSON",
"icon": "https://img.shields.io/badge/-JSON-000000?style=flat&logo=json&logoColor=white",
"link": "https://www.json.org/"
},
{
"name": "Markdown",
"icon": "https://img.shields.io/badge/-Markdown-083fa1?style=flat&logo=markdown&logoColor=white",
"link": "https://daringfireball.net/projects/markdown/"
},
{
"name": "Minecraft",
"icon": "https://img.shields.io/badge/-Minecraft-62B34A?style=flat&logo=minecraft&logoColor=white",
"link": "https://www.minecraft.net/"
}
]
}

View File

@@ -0,0 +1,120 @@
{
"title": "技术栈",
"items": [
{
"name": "Python",
"icon": "https://img.shields.io/badge/-Python-3776AB?style=flat&logo=python&logoColor=white",
"link": "https://www.python.org/"
},
{
"name": "JavaScript",
"icon": "https://img.shields.io/badge/-JavaScript-F7DF1E?style=flat&logo=javascript&logoColor=black",
"link": ""
},
{
"name": "Java",
"icon": "https://img.shields.io/badge/-Java-007396?style=flat&logo=java&logoColor=white",
"link": ""
},
{
"name": "C#",
"icon": "https://img.shields.io/badge/-C%23-512BD4?style=flat&logo=csharp&logoColor=white",
"link": ""
},
{
"name": "Golang",
"icon": "https://img.shields.io/badge/-Golang-00ADD8?style=flat&logo=go&logoColor=white",
"link": ""
},
{
"name": "React",
"icon": "https://img.shields.io/badge/-React-20232A?style=flat&logo=react&logoColor=61DAFB",
"link": ""
},
{
"name": "Node.js",
"icon": "https://img.shields.io/badge/-Node.js-339933?style=flat&logo=nodedotjs&logoColor=white",
"link": ""
},
{
"name": "Docker",
"icon": "https://img.shields.io/badge/-Docker-2496ED?style=flat&logo=docker&logoColor=white",
"link": ""
},
{
"name": "Linux",
"icon": "https://img.shields.io/badge/-Linux-000000?style=flat&logo=linux&logoColor=white",
"link": ""
},
{
"name": "Git",
"icon": "https://img.shields.io/badge/-Git-F05032?style=flat&logo=git&logoColor=white",
"link": ""
},
{
"name": "Flask",
"icon": "https://img.shields.io/badge/-Flask-000000?style=flat&logo=flask&logoColor=white",
"link": ""
},
{
"name": "MongoDB",
"icon": "https://img.shields.io/badge/-MongoDB-47A248?style=flat&logo=mongodb&logoColor=white",
"link": ""
},
{
"name": "PostgreSQL",
"icon": "https://img.shields.io/badge/-PostgreSQL-4169E1?style=flat&logo=postgresql&logoColor=white",
"link": ""
},
{
"name": "MySQL",
"icon": "https://img.shields.io/badge/-MySQL-00758F?style=flat&logo=mysql&logoColor=white",
"link": ""
},
{
"name": "Redis",
"icon": "https://img.shields.io/badge/-Redis-DC382D?style=flat&logo=redis&logoColor=white",
"link": ""
},
{
"name": "Android",
"icon": "https://img.shields.io/badge/-Android-3DDC84?style=flat&logo=android&logoColor=white",
"link": ""
},
{
"name": "Flutter",
"icon": "https://img.shields.io/badge/-Flutter-02569B?style=flat&logo=flutter&logoColor=white",
"link": ""
},
{
"name": "Godot",
"icon": "https://img.shields.io/badge/-Godot-478CBF?style=flat&logo=godot&logoColor=white",
"link": ""
},
{
"name": "Unity",
"icon": "https://img.shields.io/badge/-Unity-000000?style=flat&logo=unity&logoColor=white",
"link": ""
},
{
"name": "JSON",
"icon": "https://img.shields.io/badge/-JSON-000000?style=flat&logo=json&logoColor=white",
"link": ""
},
{
"name": "Markdown",
"icon": "https://img.shields.io/badge/-Markdown-083fa1?style=flat&logo=markdown&logoColor=white",
"link": ""
},
{
"name": "Minecraft",
"icon": "https://img.shields.io/badge/-Minecraft-62B34A?style=flat&logo=minecraft&logoColor=white",
"link": ""
}
]
}

View File

@@ -0,0 +1,2 @@
Flask==3.0.0
flask-cors==4.0.0