Skip to content

Commit

Permalink
fix: 修复编译问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jul 14, 2024
1 parent d8a66ca commit 76c1a89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}
- name: Docker Hub Description
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM python:3.10 AS builder
ENV DEBIAN_FRONTEND=noninteractive
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 .
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 .
RUN bash install_dependencies.sh

Expand Down
17 changes: 8 additions & 9 deletions xiaomusic/httpserver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import json
from pathlib import Path
import os
import secrets
from contextlib import asynccontextmanager
from dataclasses import asdict
from pathlib import Path
from typing import Annotated

from fastapi import Depends, FastAPI, HTTPException, Request, status
Expand Down Expand Up @@ -88,19 +88,18 @@ def HttpInit(_xiaomusic):

@app.get("/music/{file_path:path}")
async def read_music_file(file_path: str):
base_dir = Path(config.music_path).resolve()
real_path = os.path.join(base_dir, file_path)
file_location = Path(real_path).resolve()
base_dir = os.path.abspath(config.music_path)
real_path = os.path.normpath(os.path.join(base_dir, file_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():
raise HTTPException(status_code=404, detail="File not found")

# 确保请求的文件在我们的基础目录下
if base_dir not in file_location.parents:
if not real_path.startswith(base_dir):
raise HTTPException(
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)


Expand Down

0 comments on commit 76c1a89

Please sign in to comment.