[fix] 修复图片存储的跨域问题

This commit is contained in:
Wizerd
2023-12-14 11:45:00 +08:00
parent 765c5c06c7
commit 2a0e23bd0b
3 changed files with 10 additions and 5 deletions

View File

@@ -13,7 +13,7 @@ ENV PYTHONUNBUFFERED=1
RUN chmod +x /app/start.sh
# 安装任何所需的依赖项
RUN pip install --no-cache-dir flask gunicorn requests Pillow
RUN pip install --no-cache-dir flask gunicorn requests Pillow flask-cors
# 在容器启动时运行 Flask 应用
CMD ["/app/start.sh"]

View File

@@ -2,7 +2,8 @@ version: '3'
services:
backend-to-api:
image: wizerd/pandora-to-api:0.0.1
image: wizerd/pandora-to-api:0.0.4
restart: always
ports:
- "50011:33333"
environment:
@@ -10,13 +11,14 @@ services:
- PROXY_API_PREFIX=<Pandora-Next的PROXY_API_PREFIX>
- UPLOAD_BASE_URL=<Uploader 容器可以访问到的地址http://127.0.0.1:50012>
volumes:
- .:/app
- ./log:/app/log
uploader:
image: wizerd/pandora-to-api:0.0.1
image: wizerd/pandora-to-api:0.0.4
restart: always
entrypoint: ["python3", "/app/upload.py"]
volumes:
- .:/app
- ./images:/app/images
ports:
- "50012:23333"

View File

@@ -1,12 +1,15 @@
from flask import Flask, send_from_directory
import os
from flask_cors import CORS, cross_origin # 导入 CORS 和 cross_origin
app = Flask(__name__)
CORS(app, resources={r"/images/*": {"origins": "*"}}) # 为特定路由配置 CORS
# 确保 images 文件夹存在
os.makedirs('images', exist_ok=True)
@app.route('/images/<filename>')
@cross_origin() # 使用装饰器来允许跨域请求
def get_image(filename):
# 检查文件是否存在
if not os.path.isfile(os.path.join('images', filename)):