fix: 修复编译问题

This commit is contained in:
涵曦 2024-07-14 10:27:35 +00:00
parent d8a66ca152
commit 76c1a8952f
3 changed files with 11 additions and 11 deletions

View File

@ -26,7 +26,7 @@ jobs:
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }} tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}
- name: Docker Hub Description - name: Docker Hub Description

View File

@ -1,8 +1,9 @@
FROM python:3.10 AS builder FROM python:3.10 AS builder
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app WORKDIR /app
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sed 's#/proc/self/exe#\/bin\/sh#g' | sh -s -- -y
COPY requirements.txt . COPY requirements.txt .
RUN python3 -m venv .venv && .venv/bin/pip install --no-cache-dir -r requirements.txt RUN python3 -m venv .venv && .venv/bin/pip install --upgrade pip && .venv/bin/pip install --no-cache-dir -r requirements.txt
COPY install_dependencies.sh . COPY install_dependencies.sh .
RUN bash install_dependencies.sh RUN bash install_dependencies.sh

View File

@ -1,10 +1,10 @@
import asyncio import asyncio
import json import json
from pathlib import Path
import os import os
import secrets import secrets
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from dataclasses import asdict from dataclasses import asdict
from pathlib import Path
from typing import Annotated from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Request, status from fastapi import Depends, FastAPI, HTTPException, Request, status
@ -88,19 +88,18 @@ def HttpInit(_xiaomusic):
@app.get("/music/{file_path:path}") @app.get("/music/{file_path:path}")
async def read_music_file(file_path: str): async def read_music_file(file_path: str):
base_dir = Path(config.music_path).resolve() base_dir = os.path.abspath(config.music_path)
real_path = os.path.join(base_dir, file_path) real_path = os.path.normpath(os.path.join(base_dir, file_path))
file_location = Path(real_path).resolve()
log.info(f"read_music_file. file_path:{file_path} real_path:{real_path}") log.info(f"read_music_file. file_path:{file_path} real_path:{real_path}")
if not file_location.exists() or not file_location.is_file(): if not real_path.startswith(base_dir):
raise HTTPException(status_code=404, detail="File not found")
# 确保请求的文件在我们的基础目录下
if base_dir not in file_location.parents:
raise HTTPException( raise HTTPException(
status_code=403, detail="Access to this file is not permitted" status_code=403, detail="Access to this file is not permitted"
) )
file_location = Path(real_path).resolve()
if not file_location.exists() or not file_location.is_file():
raise HTTPException(status_code=404, detail="File not found")
return FileResponse(file_location) return FileResponse(file_location)