Skip to content

Migrate Streams API #773

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

Merged
merged 19 commits into from
Jun 6, 2025
Merged

Migrate Streams API #773

merged 19 commits into from
Jun 6, 2025

Conversation

junhyr
Copy link
Collaborator

@junhyr junhyr commented Jun 5, 2025

PR Type

Enhancement, Bug fix


Description

  • Migrate Streams API to Next.js server routes

  • Replace client upsertStream with fetch calls

  • Add retry logic to Redis client operations

  • Improve error handling in websockets & prompt manager


Changes walkthrough 📝

Relevant files
Enhancement
7 files
useDreamshaper.tsx
Refactor upsert logic and remove getStreamUrl                       
+54/-95 
create.ts
Add createStream server action                                                     
+162/-0 
page.tsx
Migrate stream form to fetch-based API calls                         
+60/-5   
try.tsx
Use fetch POST for playground stream creation                       
+32/-9   
route.ts
Add PATCH route for stream updates                                             
+57/-0   
update.ts
Implement updateStream server action                                         
+59/-0   
route.ts
Replace upsert with createStream in POST route                     
+15/-4   
Bug fix
1 files
useStreamStatus.ts
Fix `usePrivy` import path                                                             
+1/-1     
Error handling
3 files
redis.rs
Add retry and reconnection logic to Redis client                 
+222/-37
prompt_manager.rs
Log Redis errors as warnings                                                         
+10/-2   
ws.rs
Catch broken pipe errors in WebSocket send                             
+10/-1   
Additional files
2 files
index.ts +0/-1     
pnpm-lock.yaml +700/-19

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    linear bot commented Jun 5, 2025

    Copy link

    vercel bot commented Jun 5, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    pipelines-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2025 9:51am

    Copy link

    github-actions bot commented Jun 5, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 Security concerns

    Authorization header spoofing:
    The PATCH /api/streams/[id] route relies solely on a client-provided x-user-id header for ownership checks, which can be easily spoofed. Ensure requests are authenticated (e.g., via a secure token or session) rather than trusting arbitrary headers.

    ⚡ Recommended focus areas for review

    Unused Import

    The new import Stream from @/app/api/streams/upsert is not used anywhere and should be removed.

    import { Stream } from "@/app/api/streams/upsert";
    Debug Logs

    There are multiple console.log(">>>>>>>>>>>>>>>>") statements in the effect fetching the pipeline; these appear to be leftover debug logs and should be cleaned up.

      const pipeline = await getPipeline(stream.pipeline_id!);
      console.log(">>>>>>>>>>>>>>>>");
      console.log(">>>>>>>>>>>>>>>>");
      console.log(">>>>>>>>>>>>>>>>");
      console.log(">>>>>>>>>>>>>>>>");
      console.log(pipeline);
      setPipeline(pipeline);
    } catch (error) {
      console.error("Error fetching pipeline:", error);
    Authorization Check

    The PATCH endpoint reads x-user-id from request headers without real authentication, allowing a client to spoof the header and update streams they don't own.

    const userId = request.headers.get("x-user-id");
    if (!userId) {
      return createErrorResponse(401, ERROR_MESSAGES.UNAUTHORIZED);
    }
    
    const streamId = params.id;

    Copy link

    github-actions bot commented Jun 5, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Define missing searchParams

    Define searchParams before using it in fetchData to avoid undefined variable errors.
    You can use the browser URL API to extract query parameters at the start of the
    function.

    apps/app/hooks/useDreamshaper.tsx [637-644]

    +const searchParams = new URL(window.location.href).searchParams;
     const relevantParams = ["whipServer", "orchestrator"];
     
     relevantParams.forEach(param => {
       const value = searchParams.get(param);
       if (value) {
         apiUrl.searchParams.set(param, value);
       }
     });
    Suggestion importance[1-10]: 8

    __

    Why: The searchParams variable is not defined in fetchData, causing a runtime error when forwarding search parameters for WHIP URL generation.

    Medium

    @thomshutt thomshutt merged commit 14e60a1 into main Jun 6, 2025
    5 of 6 checks passed
    @thomshutt thomshutt deleted the junhyoung/eng-2856-migrate-streams-api branch June 6, 2025 10:50
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants