From 333cb262e0ee35545bcf8cad497f0c1f1fd021b1 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Mon, 26 Jan 2026 00:08:27 -0800 Subject: [PATCH] Add voice profile import functionality with file size validation - Implemented a new endpoint to import voice profiles from ZIP archives. - Added file size validation to ensure uploads do not exceed 100MB. - Enhanced error handling for various exceptions during the import process. - Cleaned up the import function by removing the previous implementation. --- backend/main.py | 54 +++++++++++++------------- landing/src/app/api/releases/route.ts | 5 +-- landing/src/lib/releases.ts | 11 ++++-- tauri/src-tauri/gen/Assets.car | Bin 3847048 -> 3847048 bytes 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/backend/main.py b/backend/main.py index 152ddec3..44039c43 100644 --- a/backend/main.py +++ b/backend/main.py @@ -143,6 +143,33 @@ async def list_profiles(db: Session = Depends(get_db)): return await profiles.list_profiles(db) +@app.post("/profiles/import", response_model=models.VoiceProfileResponse) +async def import_profile( + file: UploadFile = File(...), + db: Session = Depends(get_db), +): + """Import a voice profile from a ZIP archive.""" + # Validate file size (max 100MB) + MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB + + # Read file content + content = await file.read() + + if len(content) > MAX_FILE_SIZE: + raise HTTPException( + status_code=400, + detail=f"File too large. Maximum size is {MAX_FILE_SIZE / (1024 * 1024)}MB" + ) + + try: + profile = await export_import.import_profile_from_zip(content, db) + return profile + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + + @app.get("/profiles/{profile_id}", response_model=models.VoiceProfileResponse) async def get_profile( profile_id: str, @@ -265,33 +292,6 @@ async def export_profile( raise HTTPException(status_code=500, detail=str(e)) -@app.post("/profiles/import", response_model=models.VoiceProfileResponse) -async def import_profile( - file: UploadFile = File(...), - db: Session = Depends(get_db), -): - """Import a voice profile from a ZIP archive.""" - # Validate file size (max 100MB) - MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB - - # Read file content - content = await file.read() - - if len(content) > MAX_FILE_SIZE: - raise HTTPException( - status_code=400, - detail=f"File too large. Maximum size is {MAX_FILE_SIZE / (1024 * 1024)}MB" - ) - - try: - profile = await export_import.import_profile_from_zip(content, db) - return profile - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) - - # ============================================ # GENERATION ENDPOINTS # ============================================ diff --git a/landing/src/app/api/releases/route.ts b/landing/src/app/api/releases/route.ts index 5b62672c..60689465 100644 --- a/landing/src/app/api/releases/route.ts +++ b/landing/src/app/api/releases/route.ts @@ -10,9 +10,6 @@ export async function GET() { return NextResponse.json(releaseInfo); } catch (error) { console.error('Error fetching release info:', error); - return NextResponse.json( - { error: 'Failed to fetch release information' }, - { status: 500 } - ); + return NextResponse.json({ error: 'Failed to fetch release information' }, { status: 500 }); } } diff --git a/landing/src/lib/releases.ts b/landing/src/lib/releases.ts index e51e5306..180c0b53 100644 --- a/landing/src/lib/releases.ts +++ b/landing/src/lib/releases.ts @@ -65,13 +65,16 @@ export async function getLatestRelease(): Promise { // Fallback: construct URLs if not found in assets const baseUrl = `https://github.com/${GITHUB_REPO}/releases/download/${version}`; - + const releaseInfo: ReleaseInfo = { version, downloadLinks: { - macArm: downloadLinks.macArm || `${baseUrl}/voicebox_${version.replace('v', '')}_aarch64.dmg`, - macIntel: downloadLinks.macIntel || `${baseUrl}/voicebox_${version.replace('v', '')}_x64.dmg`, - windows: downloadLinks.windows || `${baseUrl}/voicebox_${version.replace('v', '')}_x64_en-US.msi`, + macArm: + downloadLinks.macArm || `${baseUrl}/voicebox_${version.replace('v', '')}_aarch64.dmg`, + macIntel: + downloadLinks.macIntel || `${baseUrl}/voicebox_${version.replace('v', '')}_x64.dmg`, + windows: + downloadLinks.windows || `${baseUrl}/voicebox_${version.replace('v', '')}_x64_en-US.msi`, linux: downloadLinks.linux || `${baseUrl}/voicebox_x86_64-unknown-linux-gnu.AppImage`, }, }; diff --git a/tauri/src-tauri/gen/Assets.car b/tauri/src-tauri/gen/Assets.car index e5667d52108b370f8fe53041e6d7f8cbf6c69911..532a829ef8272768faf7841c89e901ac8fd391e0 100644 GIT binary patch delta 745 zcmZwFIdW4$5C-59!XWn5fQ12@eQRr$o|zt!=hhdXc=mKhr`hWoGy58xp@ zf-TsF$M6K6!ZUadFW@D-g4gr?y*J0loy(k^_KnPPRV*n}EKQR$kz3M6ii)d`QWDai zM~$b4yKjMD2PU9Eg8>T+ZhpAy=f65r1EZ)S?}EZMxloMQjyQ=W1LnR`FjZFZ^hcZ? OO#%qS`O)Ov_k-UbTF|Ee delta 745 zcmZY7IdYRh5Cz~8!XWn5fQ4DizO^;`{7v$EmY(tvd;>CyklcZkQ3Tww2N2j z6}Qo2n(l&L_3X}P{piQAuce5pnaOzW$cah)4o+;sG)gx2)pnI9>WuO z3VZMjp2G`x39sNayn(myZhmz5{`9oB&iE!VQ)cbRDe0)g;3)!xF8drMW8GM=E&nf~PNm7Z Sa50I~#iRqCFD4&<9sdJ&AJB^c