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
|
- name: Package /app (lite) for amd64
|
||||||
run: |
|
run: |
|
||||||
docker run --rm -v $PWD:/workspace ${TEST_TAG}-linux-amd64 bash -c \
|
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
|
- name: Package /app for arm64
|
||||||
run: |
|
run: |
|
||||||
@@ -85,7 +85,7 @@ jobs:
|
|||||||
- name: Package /app (lite) for arm64
|
- name: Package /app (lite) for arm64
|
||||||
run: |
|
run: |
|
||||||
docker run --rm -v $PWD:/workspace ${TEST_TAG}-linux-arm64 bash -c \
|
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
|
- name: Package /app for arm/v7
|
||||||
run: |
|
run: |
|
||||||
@@ -94,7 +94,7 @@ jobs:
|
|||||||
- name: Package /app (lite) for arm/v7
|
- name: Package /app (lite) for arm/v7
|
||||||
run: |
|
run: |
|
||||||
docker run --rm -v $PWD:/workspace ${TEST_TAG}-linux-arm-v7 bash -c \
|
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.
|
# 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/xiaomusic/ ./xiaomusic/
|
||||||
COPY --from=builder /app/plugins/ ./plugins/
|
COPY --from=builder /app/plugins/ ./plugins/
|
||||||
COPY --from=builder /app/xiaomusic.py .
|
COPY --from=builder /app/xiaomusic.py .
|
||||||
|
COPY --from=builder /app/xiaomusic/__init__.py /base_version.py
|
||||||
RUN touch /app/.dockerenv
|
RUN touch /app/.dockerenv
|
||||||
|
|
||||||
RUN mkdir -p /etc/supervisor/conf.d
|
RUN mkdir -p /etc/supervisor/conf.d
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ from xiaomusic.utils import (
|
|||||||
is_mp3,
|
is_mp3,
|
||||||
remove_common_prefix,
|
remove_common_prefix,
|
||||||
remove_id3_tags,
|
remove_id3_tags,
|
||||||
|
restart_xiaomusic,
|
||||||
try_add_access_control_param,
|
try_add_access_control_param,
|
||||||
update_version,
|
update_version,
|
||||||
)
|
)
|
||||||
@@ -584,9 +585,22 @@ async def playlistdelmusic(data: PlayListMusicObj, Verifcation=Depends(verificat
|
|||||||
|
|
||||||
# 更新版本
|
# 更新版本
|
||||||
@app.post("/updateversion")
|
@app.post("/updateversion")
|
||||||
async def updateversion(version: str = "", Verifcation=Depends(verification)):
|
async def updateversion(
|
||||||
ret = update_version(version)
|
version: str = "", lite: bool = True, Verifcation=Depends(verification)
|
||||||
return {"ret": ret}
|
):
|
||||||
|
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):
|
async def file_iterator(file_path, start, end):
|
||||||
|
|||||||
@@ -1018,18 +1018,21 @@ def is_docker():
|
|||||||
return os.path.exists("/app/.dockerenv")
|
return os.path.exists("/app/.dockerenv")
|
||||||
|
|
||||||
|
|
||||||
def _restart_xiaomusic():
|
async def restart_xiaomusic():
|
||||||
try:
|
# 重启 xiaomusic 程序
|
||||||
# 重启 xiaomusic 程序
|
sbp_args = (
|
||||||
subprocess.run(["supervisorctl", "restart", "xiaomusic"], check=True)
|
"supervisorctl",
|
||||||
log.info("xiaomusic 重启成功")
|
"restart",
|
||||||
except subprocess.CalledProcessError as e:
|
"xiaomusic",
|
||||||
log.info(f"xiaomusic 重启失败: {e}")
|
)
|
||||||
return False, "xiaomusic 重启失败"
|
|
||||||
return True
|
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():
|
if not is_docker():
|
||||||
ret = "xiaomusic 更新只能在 docker 中进行"
|
ret = "xiaomusic 更新只能在 docker 中进行"
|
||||||
log.info(ret)
|
log.info(ret)
|
||||||
@@ -1046,9 +1049,7 @@ async def update_version(version: str, lite: bool):
|
|||||||
target_directory = "/app"
|
target_directory = "/app"
|
||||||
await download_and_extract(url, target_directory)
|
await download_and_extract(url, target_directory)
|
||||||
|
|
||||||
ok, ret = _restart_xiaomusic()
|
return "OK"
|
||||||
if not ok:
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def get_os_architecture():
|
def get_os_architecture():
|
||||||
|
|||||||
Reference in New Issue
Block a user