Skip to content

Commit

Permalink
Merge pull request #721 from zanllp/fix/cache-issues
Browse files Browse the repository at this point in the history
Handle cache issues for video cover and file responses
  • Loading branch information
zanllp authored Aug 18, 2024
2 parents 6d511fb + 4757640 commit 5397a98
Show file tree
Hide file tree
Showing 30 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Promise.resolve().then(async () => {
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Infinite Image Browsing</title>
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-0a648427.js"></script>
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-93a218ca.js"></script>
<link rel="stylesheet" href="/infinite_image_browsing/fe-static/assets/index-c05ac913.css">
</head>
Expand Down
12 changes: 8 additions & 4 deletions scripts/iib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ async def stream_video(path: str, request: Request):
)

@app.get(api_base + "/video_cover", dependencies=[Depends(verify_secret)])
async def video_cover(path: str, t: str):
async def video_cover(path: str, mt: str):
check_path_trust(path)
if not cache_base_dir:
return
Expand All @@ -627,7 +627,7 @@ async def video_cover(path: str, t: str):
if not os.path.isfile(path) and get_video_type(path):
raise HTTPException(status_code=400, detail=f"{path} is not a video file")
# 生成缓存文件的路径
hash_dir = hashlib.md5((path + t).encode("utf-8")).hexdigest()
hash_dir = hashlib.md5((path + mt).encode("utf-8")).hexdigest()
hash = hash_dir
cache_dir = os.path.join(cache_base_dir, "iib_cache", "video_cover", hash_dir)
cache_path = os.path.join(cache_dir, "cover.webp")
Expand All @@ -636,7 +636,9 @@ async def video_cover(path: str, t: str):
return FileResponse(
cache_path,
media_type="image/webp",
headers={"ETag": hash},
headers={
"Cache-Control": "no-store",
},
)
# 如果缓存文件不存在,则生成缩略图并保存

Expand All @@ -654,7 +656,9 @@ async def video_cover(path: str, t: str):
return FileResponse(
cache_path,
media_type="image/webp",
headers={"ETag": hash},
headers={
"Cache-Control": "no-store",
},
)

class SetTargetFrameAsCoverReq(BaseModel):
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Loading

0 comments on commit 5397a98

Please sign in to comment.