Skip to content

Commit

Permalink
fix: remove hash substring in exported filename
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-Shen committed Apr 17, 2024
1 parent 569ebe4 commit 98069d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions labelu/internal/common/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def convert_to_json(
"id": sample.get("id"),
"result": annotated_result_str,
"url": file.get("url"),
"fileName": file.get("filename"),
"fileName": file.get("filename", "")[9:],
}
)

Expand Down Expand Up @@ -166,7 +166,7 @@ def convert_to_coco(
# coco image
image = {
"id": sample.get("id"),
"fileName": file.get("filename"),
"fileName": file.get("filename", "")[9:],
"width": annotation_result.get("width", 0),
"height": annotation_result.get("height", 0),
"valid": False
Expand Down Expand Up @@ -266,7 +266,7 @@ def convert_to_mask(
logger.info("data is: {}", sample)
filename = file.get("filename")
if filename and filename.split("/")[-1]:
file_relative_path_base_name = filename.split("/")[-1].split(".")[0]
file_relative_path_base_name = filename.split("/")[-1].split(".")[0][9:]
else:
file_relative_path_base_name = "result"

Expand Down
20 changes: 18 additions & 2 deletions labelu/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any
import uvicorn
from typer import Typer
from fastapi import FastAPI, Request
from fastapi import FastAPI, Request, Response
from fastapi.staticfiles import StaticFiles

from labelu.internal.adapter.routers import add_router
Expand Down Expand Up @@ -93,12 +94,27 @@
add_router(app=app)
add_middleware(app=app)

app.mount("", StaticFiles(packages=["labelu.internal"], html=True))
class NoCacheStaticFiles(StaticFiles):
def __init__(self, *args: Any, **kwargs: Any):
self.cachecontrol = "max-age=0, no-cache, no-store, , must-revalidate"
self.pragma = "no-cache"
self.expires = "0"
super().__init__(*args, **kwargs)

def file_response(self, *args: Any, **kwargs: Any) -> Response:
resp = super().file_response(*args, **kwargs)
resp.headers.setdefault("Cache-Control", self.cachecontrol)
resp.headers.setdefault("Pragma", self.pragma)
resp.headers.setdefault("Expires", self.expires)
return resp

app.mount("", NoCacheStaticFiles(packages=["labelu.internal"], html=True))


@app.middleware("http")
async def add_correct_content_type(request: Request, call_next):
response = await call_next(request)

if request.url.path.endswith(".js"):
response.headers["content-type"] = "application/javascript"
return response
Expand Down

0 comments on commit 98069d1

Please sign in to comment.