feat: improve error handling for video generation and update duration selection to dropdown
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"""Generate router: text, image, video, and image-to-video generation."""
|
"""Generate router: text, image, video, and image-to-video generation."""
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
import httpx
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
|
||||||
from ..db import get_conn, get_write_lock
|
from ..db import get_conn, get_write_lock
|
||||||
@@ -199,9 +200,16 @@ async def generate_video(
|
|||||||
aspect_ratio=body.aspect_ratio,
|
aspect_ratio=body.aspect_ratio,
|
||||||
resolution=body.resolution,
|
resolution=body.resolution,
|
||||||
)
|
)
|
||||||
|
except httpx.HTTPStatusError as exc:
|
||||||
|
detail = (
|
||||||
|
f"OpenRouter API error: {exc.response.status_code} - {exc.response.text}"
|
||||||
|
)
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_502_BAD_GATEWAY, detail=detail)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_502_BAD_GATEWAY, detail=f"OpenRouter error: {exc}")
|
status_code=status.HTTP_502_BAD_GATEWAY, detail=f"OpenRouter error: {exc}"
|
||||||
|
)
|
||||||
|
|
||||||
user_id = current_user.get("id") or current_user.get("sub")
|
user_id = current_user.get("id") or current_user.get("sub")
|
||||||
job_id = result.get("id", "")
|
job_id = result.get("id", "")
|
||||||
@@ -245,9 +253,16 @@ async def generate_video_from_image(
|
|||||||
aspect_ratio=body.aspect_ratio,
|
aspect_ratio=body.aspect_ratio,
|
||||||
resolution=body.resolution,
|
resolution=body.resolution,
|
||||||
)
|
)
|
||||||
|
except httpx.HTTPStatusError as exc:
|
||||||
|
detail = (
|
||||||
|
f"OpenRouter API error: {exc.response.status_code} - {exc.response.text}"
|
||||||
|
)
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_502_BAD_GATEWAY, detail=detail)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_502_BAD_GATEWAY, detail=f"OpenRouter error: {exc}")
|
status_code=status.HTTP_502_BAD_GATEWAY, detail=f"OpenRouter error: {exc}"
|
||||||
|
)
|
||||||
|
|
||||||
user_id = current_user.get("id") or current_user.get("sub")
|
user_id = current_user.get("id") or current_user.get("sub")
|
||||||
job_id = result.get("id", "")
|
job_id = result.get("id", "")
|
||||||
|
|||||||
@@ -63,21 +63,14 @@ AI{% endblock %} {% block content %}
|
|||||||
<option value="1080p">1080p</option>
|
<option value="1080p">1080p</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="duration-t"
|
<label for="duration-t">Duration (seconds)</label>
|
||||||
>Duration: <span id="duration-t-val">5</span>s</label
|
<select id="duration-t" name="duration_seconds">
|
||||||
>
|
<option value="4">4s</option>
|
||||||
<input
|
<option value="8">8s</option>
|
||||||
type="range"
|
<option value="12" selected>12s</option>
|
||||||
id="duration-t"
|
<option value="16">16s</option>
|
||||||
name="duration_seconds"
|
<option value="20">20s</option>
|
||||||
min="5"
|
</select>
|
||||||
max="60"
|
|
||||||
step="1"
|
|
||||||
value="5"
|
|
||||||
oninput="
|
|
||||||
document.getElementById('duration-t-val').textContent = this.value
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<button type="submit">Generate video</button>
|
<button type="submit">Generate video</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -143,21 +136,14 @@ AI{% endblock %} {% block content %}
|
|||||||
<option value="1080p">1080p</option>
|
<option value="1080p">1080p</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="duration-i"
|
<label for="duration-i">Duration (seconds)</label>
|
||||||
>Duration: <span id="duration-i-val">5</span>s</label
|
<select id="duration-i" name="duration_seconds">
|
||||||
>
|
<option value="4">4s</option>
|
||||||
<input
|
<option value="8">8s</option>
|
||||||
type="range"
|
<option value="12" selected>12s</option>
|
||||||
id="duration-i"
|
<option value="16">16s</option>
|
||||||
name="duration_seconds"
|
<option value="20">20s</option>
|
||||||
min="5"
|
</select>
|
||||||
max="60"
|
|
||||||
step="1"
|
|
||||||
value="5"
|
|
||||||
oninput="
|
|
||||||
document.getElementById('duration-i-val').textContent = this.value
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<button type="submit">Generate video from image</button>
|
<button type="submit">Generate video from image</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user