mirror of
https://github.com/hanxi/xiaomusic.git
synced 2025-12-06 14:52:50 +08:00
refactor: 更新接口修改
This commit is contained in:
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -76,7 +76,7 @@ jobs:
|
||||
- name: Package /app (lite) for amd64
|
||||
run: |
|
||||
docker run --rm -v $PWD:/workspace ${TEST_TAG}-linux-amd64 bash -c \
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-amd64-lite.tar.gz *"
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-amd64-lite.tar.gz .[!.]* *"
|
||||
|
||||
- name: Package /app for arm64
|
||||
run: |
|
||||
@@ -85,7 +85,7 @@ jobs:
|
||||
- name: Package /app (lite) for arm64
|
||||
run: |
|
||||
docker run --rm -v $PWD:/workspace ${TEST_TAG}-linux-arm64 bash -c \
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-arm64-lite.tar.gz *"
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-arm64-lite.tar.gz .[!.]* *"
|
||||
|
||||
- name: Package /app for arm/v7
|
||||
run: |
|
||||
@@ -94,7 +94,7 @@ jobs:
|
||||
- name: Package /app (lite) for arm/v7
|
||||
run: |
|
||||
docker run --rm -v $PWD:/workspace ${TEST_TAG}-linux-arm-v7 bash -c \
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-arm-v7-lite.tar.gz *"
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-arm-v7-lite.tar.gz .[!.]* *"
|
||||
|
||||
|
||||
# This will only push the previously built images.
|
||||
|
||||
@@ -15,6 +15,7 @@ COPY --from=builder /app/.venv ./.venv
|
||||
COPY --from=builder /app/xiaomusic/ ./xiaomusic/
|
||||
COPY --from=builder /app/plugins/ ./plugins/
|
||||
COPY --from=builder /app/xiaomusic.py .
|
||||
COPY --from=builder /app/xiaomusic/__init__.py /base_version.py
|
||||
RUN touch /app/.dockerenv
|
||||
|
||||
RUN mkdir -p /etc/supervisor/conf.d
|
||||
|
||||
@@ -45,6 +45,7 @@ from xiaomusic.utils import (
|
||||
is_mp3,
|
||||
remove_common_prefix,
|
||||
remove_id3_tags,
|
||||
restart_xiaomusic,
|
||||
try_add_access_control_param,
|
||||
update_version,
|
||||
)
|
||||
@@ -584,9 +585,22 @@ async def playlistdelmusic(data: PlayListMusicObj, Verifcation=Depends(verificat
|
||||
|
||||
# 更新版本
|
||||
@app.post("/updateversion")
|
||||
async def updateversion(version: str = "", Verifcation=Depends(verification)):
|
||||
ret = update_version(version)
|
||||
return {"ret": ret}
|
||||
async def updateversion(
|
||||
version: str = "", lite: bool = True, Verifcation=Depends(verification)
|
||||
):
|
||||
ret = update_version(version, lite)
|
||||
if ret != "OK":
|
||||
return {"ret": ret}
|
||||
|
||||
proc = restart_xiaomusic()
|
||||
|
||||
async def check_proc():
|
||||
# 等待子进程完成
|
||||
exit_code = await proc.wait()
|
||||
log.info(f"Restart completed with exit code {exit_code}")
|
||||
|
||||
asyncio.create_task(check_proc())
|
||||
return {"ret": "OK"}
|
||||
|
||||
|
||||
async def file_iterator(file_path, start, end):
|
||||
|
||||
@@ -1018,18 +1018,21 @@ def is_docker():
|
||||
return os.path.exists("/app/.dockerenv")
|
||||
|
||||
|
||||
def _restart_xiaomusic():
|
||||
try:
|
||||
# 重启 xiaomusic 程序
|
||||
subprocess.run(["supervisorctl", "restart", "xiaomusic"], check=True)
|
||||
log.info("xiaomusic 重启成功")
|
||||
except subprocess.CalledProcessError as e:
|
||||
log.info(f"xiaomusic 重启失败: {e}")
|
||||
return False, "xiaomusic 重启失败"
|
||||
return True
|
||||
async def restart_xiaomusic():
|
||||
# 重启 xiaomusic 程序
|
||||
sbp_args = (
|
||||
"supervisorctl",
|
||||
"restart",
|
||||
"xiaomusic",
|
||||
)
|
||||
|
||||
cmd = " ".join(sbp_args)
|
||||
log.info(f"restart_xiaomusic: {cmd}")
|
||||
proc = await asyncio.create_subprocess_exec(*sbp_args)
|
||||
return proc
|
||||
|
||||
|
||||
async def update_version(version: str, lite: bool):
|
||||
async def update_version(version: str, lite: bool = True):
|
||||
if not is_docker():
|
||||
ret = "xiaomusic 更新只能在 docker 中进行"
|
||||
log.info(ret)
|
||||
@@ -1046,9 +1049,7 @@ async def update_version(version: str, lite: bool):
|
||||
target_directory = "/app"
|
||||
await download_and_extract(url, target_directory)
|
||||
|
||||
ok, ret = _restart_xiaomusic()
|
||||
if not ok:
|
||||
return ret
|
||||
return "OK"
|
||||
|
||||
|
||||
def get_os_architecture():
|
||||
|
||||
Reference in New Issue
Block a user