Skip to content

Commit

Permalink
Fix ufbt --branch with nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Nov 2, 2024
1 parent 4ac0743 commit 6c825ca
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions indexer/src/directories.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import logging
import asyncio
from fastapi import APIRouter
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse, FileResponse

from .repository import indexes, RepositoryIndex, PacksCatalog
from .settings import settings


router = APIRouter()
Expand Down Expand Up @@ -123,30 +125,24 @@ async def reindex_request():
logging.exception(e)
return JSONResponse("Reindexing is failed!", status_code=500)

# if isinstance(index, RepositoryIndex):
if isinstance(index, RepositoryIndex):

# @router.get(prefix + "/{branch}")
# async def repository_branch_request(branch):
# """
# A method for retrieving the list of files from a specific branch
# Made for support of `ufbt update --index-url {base_url}/firmware --branch {branch}`
# Args:
# branch: Branch name
@router.get(prefix + "/{branch}")
async def repository_branch_request(branch):
"""
A method for retrieving the list of files from a specific branch
Made for support of `ufbt update --index-url {base_url}/firmware --branch {branch}`
Args:
branch: Branch name
# Returns:
# HTML links in format that ufbt understands
# """
# if len(index.index["channels"]) == 0:
# return JSONResponse("No channels found!", status_code=404)
# try:
# branch_files = index.get_branch_file_names(branch)
# response = "\n".join(f'<a href="{file}"></a>' for file in branch_files)
# return HTMLResponse(
# response,
# status_code=200,
# )
# except Exception as e:
# return JSONResponse(str(e), status_code=404)
Returns:
Redirect to directory listing
"""
if len(index.index["channels"]) == 0:
return JSONResponse("No channels found!", status_code=404)
return RedirectResponse(
os.path.join(settings.base_url, prefix, branch), status_code=303
)


for directory, index in indexes.items():
Expand Down

0 comments on commit 6c825ca

Please sign in to comment.