Skip to content

Commit

Permalink
change redirect status code from 302 to 301
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterain98 committed Feb 27, 2025
1 parent 8a3512e commit d8a8b8f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
12 changes: 6 additions & 6 deletions routers/client_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ async def china_client_feature_request_handler(request: Request, file_path: str)
:param file_path: Path to the metadata file
:return: HTTP 302 redirect to the file based on censorship status of the file
:return: HTTP 301 redirect to the file based on censorship status of the file
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

host_for_normal_files = await redis_client.get("url:china:client-feature")
host_for_normal_files = host_for_normal_files.decode("utf-8").format(file_path=file_path)

return RedirectResponse(host_for_normal_files, status_code=302)
return RedirectResponse(host_for_normal_files, status_code=301)


@global_router.get("/{file_path:path}")
Expand All @@ -36,14 +36,14 @@ async def global_client_feature_request_handler(request: Request, file_path: str
:param file_path: Path to the metadata file
:return: HTTP 302 redirect to the file based on censorship status of the file
:return: HTTP 301 redirect to the file based on censorship status of the file
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

host_for_normal_files = await redis_client.get("url:global:client-feature")
host_for_normal_files = host_for_normal_files.decode("utf-8").format(file_path=file_path)

return RedirectResponse(host_for_normal_files, status_code=302)
return RedirectResponse(host_for_normal_files, status_code=301)


@fujian_router.get("/{file_path:path}")
Expand All @@ -55,11 +55,11 @@ async def fujian_client_feature_request_handler(request: Request, file_path: str
:param file_path: Path to the metadata file
:return: HTTP 302 redirect to the file based on censorship status of the file
:return: HTTP 301 redirect to the file based on censorship status of the file
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

host_for_normal_files = await redis_client.get("url:fujian:client-feature")
host_for_normal_files = host_for_normal_files.decode("utf-8").format(file_path=file_path)

return RedirectResponse(host_for_normal_files, status_code=302)
return RedirectResponse(host_for_normal_files, status_code=301)
16 changes: 8 additions & 8 deletions routers/enka_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ async def cn_get_enka_raw_data(request: Request, uid: str) -> RedirectResponse:
:param uid: User's in-game UID
:return: HTTP 302 redirect to Enka-API
:return: HTTP 301 redirect to Enka-API
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

endpoint = await redis_client.get("url:china:enka-network")
endpoint = endpoint.decode("utf-8").format(uid=uid)

return RedirectResponse(endpoint, status_code=302)
return RedirectResponse(endpoint, status_code=301)


@global_router.get("/{uid}", dependencies=[Depends(validate_client_is_updated)])
Expand All @@ -38,14 +38,14 @@ async def global_get_enka_raw_data(request: Request, uid: str) -> RedirectRespon
:param uid: User's in-game UID
:return: HTTP 302 redirect to Enka-API (Origin Endpoint)
:return: HTTP 301 redirect to Enka-API (Origin Endpoint)
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

endpoint = await redis_client.get("url:global:enka-network")
endpoint = endpoint.decode("utf-8").format(uid=uid)

return RedirectResponse(endpoint, status_code=302)
return RedirectResponse(endpoint, status_code=301)


@china_router.get("/{uid}/info", dependencies=[Depends(validate_client_is_updated)])
Expand All @@ -58,14 +58,14 @@ async def cn_get_enka_info_data(request: Request, uid: str) -> RedirectResponse:
:param uid: User's in-game UID
:return: HTTP 302 redirect to Enka-API
:return: HTTP 301 redirect to Enka-API
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

endpoint = await redis_client.get("url:china:enka-network-info")
endpoint = endpoint.decode("utf-8").format(uid=uid)

return RedirectResponse(endpoint, status_code=302)
return RedirectResponse(endpoint, status_code=301)


@global_router.get("/{uid}/info", dependencies=[Depends(validate_client_is_updated)])
Expand All @@ -77,11 +77,11 @@ async def global_get_enka_info_data(request: Request, uid: str) -> RedirectRespo
:param uid: User's in-game UID
:return: HTTP 302 redirect to Enka-API (Origin Endpoint)
:return: HTTP 301 redirect to Enka-API (Origin Endpoint)
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

endpoint = await redis_client.get("url:global:enka-network-info")
endpoint = endpoint.decode("utf-8").format(uid=uid)

return RedirectResponse(endpoint, status_code=302)
return RedirectResponse(endpoint, status_code=301)
12 changes: 6 additions & 6 deletions routers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ async def china_metadata_request_handler(request: Request, file_path: str) -> Re
:param file_path: Path to the metadata file
:return: HTTP 302 redirect to the file based on censorship status of the file
:return: HTTP 301 redirect to the file based on censorship status of the file
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

china_metadata_endpoint = await redis_client.get("url:china:metadata")
china_metadata_endpoint = china_metadata_endpoint.decode("utf-8").format(file_path=file_path)

return RedirectResponse(china_metadata_endpoint, status_code=302)
return RedirectResponse(china_metadata_endpoint, status_code=301)


@global_router.get("/{file_path:path}", dependencies=[Depends(validate_client_is_updated)])
Expand All @@ -37,14 +37,14 @@ async def global_metadata_request_handler(request: Request, file_path: str) -> R
:param file_path: Path to the metadata file
:return: HTTP 302 redirect to the file based on censorship status of the file
:return: HTTP 301 redirect to the file based on censorship status of the file
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

global_metadata_endpoint = await redis_client.get("url:global:metadata")
global_metadata_endpoint = global_metadata_endpoint.decode("utf-8").format(file_path=file_path)

return RedirectResponse(global_metadata_endpoint, status_code=302)
return RedirectResponse(global_metadata_endpoint, status_code=301)


@fujian_router.get("/{file_path:path}", dependencies=[Depends(validate_client_is_updated)])
Expand All @@ -56,11 +56,11 @@ async def fujian_metadata_request_handler(request: Request, file_path: str) -> R
:param file_path: Path to the metadata file
:return: HTTP 302 redirect to the file based on censorship status of the file
:return: HTTP 301 redirect to the file based on censorship status of the file
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)

fujian_metadata_endpoint = await redis_client.get("url:fujian:metadata")
fujian_metadata_endpoint = fujian_metadata_endpoint.decode("utf-8").format(file_path=file_path)

return RedirectResponse(fujian_metadata_endpoint, status_code=302)
return RedirectResponse(fujian_metadata_endpoint, status_code=301)
16 changes: 8 additions & 8 deletions routers/patch_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def get_snap_hutao_latest_download_direct_china_endpoint(request: Request)
"""
Redirect to Snap Hutao latest download link in China endpoint (use first link in the list)
:return: 302 Redirect to the first download link
:return: 301 Redirect to the first download link
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)
snap_hutao_latest_version = await redis_client.get("snap-hutao:patch")
Expand All @@ -280,7 +280,7 @@ async def get_snap_hutao_latest_download_direct_china_endpoint(request: Request)
headers = {
"X-Checksum-Sha256": checksum_value
} if checksum_value else {}
return RedirectResponse(snap_hutao_latest_version["cn"]["mirrors"][-1]["url"], status_code=302, headers=headers)
return RedirectResponse(snap_hutao_latest_version["cn"]["mirrors"][-1]["url"], status_code=301, headers=headers)


@global_router.get("/hutao", response_model=StandardResponse, dependencies=[Depends(record_device_id)])
Expand Down Expand Up @@ -313,7 +313,7 @@ async def get_snap_hutao_latest_download_direct_china_endpoint(request: Request)
"""
Redirect to Snap Hutao latest download link in Global endpoint (use first link in the list)
:return: 302 Redirect to the first download link
:return: 301 Redirect to the first download link
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)
snap_hutao_latest_version = await redis_client.get("snap-hutao:patch")
Expand All @@ -322,7 +322,7 @@ async def get_snap_hutao_latest_download_direct_china_endpoint(request: Request)
headers = {
"X-Checksum-Sha256": checksum_value
} if checksum_value else {}
return RedirectResponse(snap_hutao_latest_version["global"]["mirrors"][-1]["url"], status_code=302, headers=headers)
return RedirectResponse(snap_hutao_latest_version["global"]["mirrors"][-1]["url"], status_code=301, headers=headers)


@china_router.get("/alpha", include_in_schema=True, response_model=StandardResponse)
Expand Down Expand Up @@ -378,12 +378,12 @@ async def get_snap_hutao_latest_download_direct_china_endpoint(request: Request)
"""
Redirect to Snap Hutao Deployment latest download link in China endpoint (use first link in the list)
:return: 302 Redirect to the first download link
:return: 301 Redirect to the first download link
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)
snap_hutao_deployment_latest_version = await redis_client.get("snap-hutao-deployment:patch")
snap_hutao_deployment_latest_version = json.loads(snap_hutao_deployment_latest_version)
return RedirectResponse(snap_hutao_deployment_latest_version["cn"]["mirrors"][-1]["url"], status_code=302)
return RedirectResponse(snap_hutao_deployment_latest_version["cn"]["mirrors"][-1]["url"], status_code=301)


@global_router.get("/hutao-deployment", response_model=StandardResponse)
Expand Down Expand Up @@ -413,12 +413,12 @@ async def get_snap_hutao_latest_download_direct_china_endpoint(request: Request)
"""
Redirect to Snap Hutao Deployment latest download link in Global endpoint (use first link in the list)
:return: 302 Redirect to the first download link
:return: 301 Redirect to the first download link
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)
snap_hutao_deployment_latest_version = await redis_client.get("snap-hutao-deployment:patch")
snap_hutao_deployment_latest_version = json.loads(snap_hutao_deployment_latest_version)
return RedirectResponse(snap_hutao_deployment_latest_version["global"]["mirrors"][-1]["url"], status_code=302)
return RedirectResponse(snap_hutao_deployment_latest_version["global"]["mirrors"][-1]["url"], status_code=301)


@china_router.patch("/{project}", include_in_schema=True, response_model=StandardResponse)
Expand Down
20 changes: 10 additions & 10 deletions routers/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def cn_get_zipped_file(file_path: str, request: Request) -> RedirectRespon
:param file_path: File relative path in Snap.Static.Zip
:return: 302 Redirect to the zip file
:return: 301 Redirect to the zip file
"""
redis_client = aioredis.Redis.from_pool(request.app.state.redis)
china_endpoint = await redis_client.get("url:china:static:zip")
Expand Down Expand Up @@ -61,7 +61,7 @@ async def cn_get_zipped_file(file_path: str, request: Request) -> RedirectRespon
case _:
raise HTTPException(status_code=404, detail="Invalid quality")
logging.debug(f"Redirecting to {china_endpoint.format(file_path=file_path)}")
return RedirectResponse(china_endpoint.format(file_path=file_path), status_code=302)
return RedirectResponse(china_endpoint.format(file_path=file_path), status_code=301)


@china_router.get("/raw/{file_path:path}")
Expand All @@ -74,7 +74,7 @@ async def cn_get_raw_file(file_path: str, request: Request) -> RedirectResponse:
:param file_path: Raw file relative path in Snap.Static
:return: 302 Redirect to the raw file
:return: 301 Redirect to the raw file
"""
quality = request.headers.get("x-hutao-quality", "high").lower()
redis_client = aioredis.Redis.from_pool(request.app.state.redis)
Expand All @@ -91,7 +91,7 @@ async def cn_get_raw_file(file_path: str, request: Request) -> RedirectResponse:
case _:
raise HTTPException(status_code=404, detail="Invalid quality")
logging.debug(f"Redirecting to {china_endpoint.format(file_path=file_path)}")
return RedirectResponse(china_endpoint.format(file_path=file_path), status_code=302)
return RedirectResponse(china_endpoint.format(file_path=file_path), status_code=301)


@global_router.get("/zip/{file_path:path}")
Expand Down Expand Up @@ -131,12 +131,12 @@ async def global_get_zipped_file(file_path: str, request: Request) -> RedirectRe
case "high":
return RedirectResponse(
global_tiny_quality_endpoint.format(file_path=file_path, file_type="zip"),
status_code=302
status_code=301
)
case "raw":
return RedirectResponse(
global_original_quality_endpoint.format(file_path=file_path),
status_code=302
status_code=301
)
case _:
raise HTTPException(status_code=404, detail="Invalid quality")
Expand All @@ -150,7 +150,7 @@ async def global_get_raw_file(file_path: str, request: Request) -> RedirectRespo
:param request: request object from FastAPI
:param file_path: Relative path in Snap.Static
:return: 302 Redirect to the raw file
:return: 301 Redirect to the raw file
"""
quality = request.headers.get("x-hutao-quality", "high").lower()
redis_client = aioredis.Redis.from_pool(request.app.state.redis)
Expand All @@ -163,17 +163,17 @@ async def global_get_raw_file(file_path: str, request: Request) -> RedirectRespo
case "high":
return RedirectResponse(
global_tiny_quality_endpoint.format(file_type="raw", file_path=file_path),
status_code=302
status_code=301
)
case "raw":
return RedirectResponse(
global_original_quality_endpoint.format(file_path=file_path),
status_code=302
status_code=301
)
case "original":
return RedirectResponse(
global_original_quality_endpoint.format(file_path=file_path),
status_code=302
status_code=301
)
case _:
raise HTTPException(status_code=404, detail="Invalid quality")
Expand Down

0 comments on commit d8a8b8f

Please sign in to comment.