mirror of
https://github.com/flibusta-apps/telegram_files_cache_server.git
synced 2025-12-06 06:35:38 +01:00
Fix
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
from fastapi import HTTPException, Request, status
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
from redis.asyncio import ConnectionPool
|
||||
|
||||
from app.models import CachedFile as CachedFileDB
|
||||
from app.services.cache_updater import cache_file_by_book_id
|
||||
|
||||
|
||||
async def get_cached_file_or_cache(
|
||||
request: Request, object_id: int, object_type: str
|
||||
object_id: int, object_type: str, connection_pool: ConnectionPool
|
||||
) -> CachedFileDB:
|
||||
cached_file = await CachedFileDB.objects.get_or_none(
|
||||
object_id=object_id, object_type=object_type
|
||||
@@ -13,7 +15,7 @@ async def get_cached_file_or_cache(
|
||||
|
||||
if not cached_file:
|
||||
cached_file = await cache_file_by_book_id(
|
||||
{"redis": request.app.state.redis_client}, object_id, object_type
|
||||
object_id, object_type, redis_pool=connection_pool
|
||||
)
|
||||
|
||||
if not cached_file:
|
||||
|
||||
@@ -40,7 +40,9 @@ async def get_cached_file(request: Request, object_id: int, object_type: str):
|
||||
|
||||
@router.get("/download/{object_id}/{object_type}")
|
||||
async def download_cached_file(request: Request, object_id: int, object_type: str):
|
||||
cached_file = await get_cached_file_or_cache(request, object_id, object_type)
|
||||
cached_file = await get_cached_file_or_cache(
|
||||
object_id, object_type, request.app.state.redis_pool
|
||||
)
|
||||
cache_data: dict = cached_file.data # type: ignore
|
||||
|
||||
data = await download_file_from_cache(
|
||||
@@ -49,7 +51,9 @@ async def download_cached_file(request: Request, object_id: int, object_type: st
|
||||
if data is None:
|
||||
await CachedFileDB.objects.filter(id=cached_file.id).delete()
|
||||
|
||||
cached_file = await get_cached_file_or_cache(request, object_id, object_type)
|
||||
cached_file = await get_cached_file_or_cache(
|
||||
object_id, object_type, request.app.state.redis_pool
|
||||
)
|
||||
cache_data: dict = cached_file.data # type: ignore
|
||||
|
||||
data = await download_file_from_cache(
|
||||
|
||||
Reference in New Issue
Block a user