Upload 4 files
Browse files
config.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
|
| 4 |
+
# Load environment variables from .env file
|
| 5 |
+
load_dotenv()
|
| 6 |
+
|
| 7 |
+
class Config:
|
| 8 |
+
# Flask configuration
|
| 9 |
+
SECRET_KEY = os.getenv('FLASK_SECRET_KEY', 'default-secret-key')
|
| 10 |
+
|
| 11 |
+
# SQLite database configuration - 使用简单直接的路径
|
| 12 |
+
SQLALCHEMY_DATABASE_URI = 'sqlite:///blog.db'
|
| 13 |
+
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
| 14 |
+
|
| 15 |
+
# Upload configuration
|
| 16 |
+
UPLOAD_FOLDER = os.path.join('app', 'static', 'uploads')
|
| 17 |
+
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB max file size
|
| 18 |
+
|
| 19 |
+
# Admin authentication
|
| 20 |
+
ADMIN_USERNAME = os.getenv('ADMIN_USERNAME', 'admin')
|
| 21 |
+
ADMIN_PASSWORD = os.getenv('ADMIN_PASSWORD', 'password')
|
| 22 |
+
|
| 23 |
+
# AI service configuration
|
| 24 |
+
AI_API_KEY = os.getenv('AI_API_KEY')
|
| 25 |
+
AI_BASE_URL = os.getenv('AI_BASE_URL', 'https://api.deepseek.com')
|
| 26 |
+
|
| 27 |
+
# Allowed file extensions for uploads
|
| 28 |
+
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
new.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# setup_project.py
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def create_directory_structure():
|
| 5 |
+
# Define the project structure
|
| 6 |
+
structure = {
|
| 7 |
+
'app': {
|
| 8 |
+
'static': {
|
| 9 |
+
'css': {},
|
| 10 |
+
'js': {},
|
| 11 |
+
'img': {},
|
| 12 |
+
'uploads': {}
|
| 13 |
+
},
|
| 14 |
+
'templates': {
|
| 15 |
+
'admin': {},
|
| 16 |
+
'components': {}
|
| 17 |
+
},
|
| 18 |
+
'database': {},
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Define files to create
|
| 23 |
+
files = [
|
| 24 |
+
'app/__init__.py',
|
| 25 |
+
'app/routes.py',
|
| 26 |
+
'app/models.py',
|
| 27 |
+
'app/utils.py',
|
| 28 |
+
'app/ai_service.py',
|
| 29 |
+
'app/templates/base.html',
|
| 30 |
+
'app/templates/index.html',
|
| 31 |
+
'app/templates/article.html',
|
| 32 |
+
'app/templates/editor.html',
|
| 33 |
+
'app/templates/admin/login.html',
|
| 34 |
+
'app/templates/admin/dashboard.html',
|
| 35 |
+
'app/templates/components/header.html',
|
| 36 |
+
'app/templates/components/footer.html',
|
| 37 |
+
'app/static/css/style.css',
|
| 38 |
+
'app/static/js/editor.js',
|
| 39 |
+
'app/static/js/main.js',
|
| 40 |
+
'.env.example',
|
| 41 |
+
'config.py',
|
| 42 |
+
'run.py',
|
| 43 |
+
'requirements.txt'
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
def create_directories(base_path, structure):
|
| 47 |
+
for key, value in structure.items():
|
| 48 |
+
path = os.path.join(base_path, key)
|
| 49 |
+
os.makedirs(path, exist_ok=True)
|
| 50 |
+
if isinstance(value, dict):
|
| 51 |
+
create_directories(path, value)
|
| 52 |
+
|
| 53 |
+
# Create directories
|
| 54 |
+
create_directories('.', structure)
|
| 55 |
+
|
| 56 |
+
# Create empty files
|
| 57 |
+
for file_path in files:
|
| 58 |
+
open(file_path, 'a').close()
|
| 59 |
+
|
| 60 |
+
# Create .env.example with template content
|
| 61 |
+
env_content = """FLASK_ENV=development
|
| 62 |
+
FLASK_SECRET_KEY=your-secret-key
|
| 63 |
+
ADMIN_USERNAME=admin
|
| 64 |
+
ADMIN_PASSWORD=password
|
| 65 |
+
AI_API_KEY=your-api-key
|
| 66 |
+
AI_BASE_URL=https://api.deepseek.com"""
|
| 67 |
+
|
| 68 |
+
with open('.env.example', 'w') as f:
|
| 69 |
+
f.write(env_content)
|
| 70 |
+
|
| 71 |
+
print("Project structure created successfully!")
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
create_directory_structure()
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask==3.0.0
|
| 2 |
+
Flask-SQLAlchemy==3.1.1
|
| 3 |
+
Flask-CORS==4.0.0
|
| 4 |
+
python-dotenv==1.0.0
|
| 5 |
+
openai==1.3.0
|
| 6 |
+
Markdown==3.5.1
|
| 7 |
+
Pillow==10.1.0
|
| 8 |
+
python-slugify==8.0.1
|
| 9 |
+
MarkupSafe==2.1.3
|
run.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from app import create_app, db
|
| 2 |
+
from app.models import Article, Image
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# 加载环境变量
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# 创建应用实例
|
| 10 |
+
app = create_app()
|
| 11 |
+
|
| 12 |
+
# 创建命令行上下文
|
| 13 |
+
@app.shell_context_processor
|
| 14 |
+
def make_shell_context():
|
| 15 |
+
return {
|
| 16 |
+
'db': db,
|
| 17 |
+
'Article': Article,
|
| 18 |
+
'Image': Image
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
if __name__ == '__main__':
|
| 22 |
+
# 在开发环境中启动应用
|
| 23 |
+
app.run(
|
| 24 |
+
host='0.0.0.0',
|
| 25 |
+
port=int(os.getenv('PORT', 5000)),
|
| 26 |
+
debug=os.getenv('FLASK_ENV') == 'development'
|
| 27 |
+
)
|