Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1228 Configurable upload timeout #1236

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@ def str_to_bool(value: str) -> bool:
DISABLE_EMULATOR_JS = str_to_bool(os.environ.get("DISABLE_EMULATOR_JS", "false"))
DISABLE_RUFFLE_RS = str_to_bool(os.environ.get("DISABLE_RUFFLE_RS", "false"))

# FRONTEND
UPLOAD_TIMEOUT = int(os.environ.get("UPLOAD_TIMEOUT", 600))

# TESTING
IS_PYTEST_RUN: Final = bool(os.environ.get("PYTEST_VERSION", False))
2 changes: 2 additions & 0 deletions backend/endpoints/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
RESCAN_ON_FILESYSTEM_CHANGE_DELAY,
SCHEDULED_RESCAN_CRON,
SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON,
UPLOAD_TIMEOUT,
)
from endpoints.responses.heartbeat import HeartbeatResponse
from handler.database import db_user_handler
Expand Down Expand Up @@ -61,4 +62,5 @@ def heartbeat() -> HeartbeatResponse:
"DISABLE_EMULATOR_JS": DISABLE_EMULATOR_JS,
"DISABLE_RUFFLE_RS": DISABLE_RUFFLE_RS,
},
"FRONTEND": {"UPLOAD_TIMEOUT": UPLOAD_TIMEOUT},
}
5 changes: 5 additions & 0 deletions backend/endpoints/responses/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class EmulationDict(TypedDict):
DISABLE_RUFFLE_RS: bool


class FrontendDict(TypedDict):
UPLOAD_TIMEOUT: int


class HeartbeatResponse(TypedDict):
VERSION: str
SHOW_SETUP_WIZARD: bool
Expand All @@ -36,3 +40,4 @@ class HeartbeatResponse(TypedDict):
METADATA_SOURCES: MetadataSourcesDict
FS_PLATFORMS: list
EMULATION: EmulationDict
FRONTEND: FrontendDict
1 change: 1 addition & 0 deletions backend/endpoints/tests/test_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ def test_heartbeat(client):
heartbeat.get("SCHEDULER").get("SWITCH_TITLEDB").get("TITLE")
== "Scheduled Switch TitleDB update"
)
assert heartbeat.get("FRONTEND").get("UPLOAD_TIMEOUT") == 20
1 change: 1 addition & 0 deletions frontend/src/__generated__/index.ts

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

9 changes: 9 additions & 0 deletions frontend/src/__generated__/models/FrontendDict.ts

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

2 changes: 2 additions & 0 deletions frontend/src/__generated__/models/HeartbeatResponse.ts

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

5 changes: 3 additions & 2 deletions frontend/src/services/api/rom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import storeUpload from "@/stores/upload";
import type { DetailedRom, SimpleRom } from "@/stores/roms";
import { getDownloadLink } from "@/utils";
import type { AxiosProgressEvent } from "axios";
import storeHeartbeat from "@/stores/heartbeat";

const heartbeat = storeHeartbeat();
export const romApi = api;

async function uploadRoms({
Expand All @@ -27,7 +29,6 @@ async function uploadRoms({
formData.append(file.name, file);

uploadStore.start(file.name);

return new Promise((resolve, reject) => {
api
.post("/roms", formData, {
Expand All @@ -36,7 +37,7 @@ async function uploadRoms({
"X-Upload-Platform": platformId.toString(),
"X-Upload-Filename": file.name,
},
timeout: 600000,
timeout: heartbeat.value.FRONTEND.UPLOAD_TIMEOUT * 1000,
params: {},
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
uploadStore.update(file.name, progressEvent);
Expand Down
6 changes: 5 additions & 1 deletion frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { defineConfig, loadEnv } from "vite";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load ENV variables from the parent directory and the current directory.
const env = { ...loadEnv(mode, "../"), ...loadEnv(mode, "./") };
const envPrefixes = ["VITE", "DEV"];
const env = {
...loadEnv(mode, "../", envPrefixes),
...loadEnv(mode, "./", envPrefixes),
};
const backendPort = env.DEV_PORT ?? "5000";

return {
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ env =
RESCAN_ON_FILESYSTEM_CHANGE_DELAY=5
SCHEDULED_RESCAN_CRON=0 3 * * *
SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON=0 4 * * *
UPLOAD_TIMEOUT=20
Loading