11from typing import (
22 Any ,
33)
4+ from urllib .parse import urljoin
45
56from a2wsgi import WSGIMiddleware
67from fastapi import (
910)
1011from fastapi .openapi .constants import REF_TEMPLATE
1112from starlette .middleware .cors import CORSMiddleware
13+ from tuspyserver import create_tus_router
1214
1315from galaxy .schema .generics import CustomJsonSchema
1416from galaxy .version import VERSION
@@ -165,6 +167,23 @@ def get_openapi_schema() -> dict[str, Any]:
165167 )
166168
167169
170+ def include_tus (app : FastAPI , gx_app ):
171+ config = gx_app .config
172+ root_path = "" if config .galaxy_url_prefix == "/" else config .galaxy_url_prefix
173+ upload_tus_router = create_tus_router (
174+ prefix = urljoin (root_path , "api/upload/resumable_upload" ),
175+ files_dir = config .tus_upload_store or config .new_file_path ,
176+ max_size = config .maximum_upload_file_size ,
177+ )
178+ job_files_tus_router = create_tus_router (
179+ prefix = urljoin (root_path , "api/job_files/resumable_upload" ),
180+ files_dir = config .tus_upload_store_job_files or config .tus_upload_store or config .new_file_path ,
181+ max_size = config .maximum_upload_file_size ,
182+ )
183+ app .include_router (upload_tus_router )
184+ app .include_router (job_files_tus_router )
185+
186+
168187def initialize_fast_app (gx_wsgi_webapp , gx_app ):
169188 root_path = "" if gx_app .config .galaxy_url_prefix == "/" else gx_app .config .galaxy_url_prefix
170189 app = get_fastapi_instance (root_path = root_path )
@@ -178,6 +197,7 @@ def initialize_fast_app(gx_wsgi_webapp, gx_app):
178197 include_legacy_openapi (app , gx_app )
179198 wsgi_handler = WSGIMiddleware (gx_wsgi_webapp )
180199 gx_app .haltables .append (("WSGI Middleware threadpool" , wsgi_handler .executor .shutdown ))
200+ include_tus (app , gx_app )
181201 app .mount ("/" , wsgi_handler ) # type: ignore[arg-type]
182202 if gx_app .config .galaxy_url_prefix != "/" :
183203 parent_app = FastAPI ()
0 commit comments