NextChat icon indicating copy to clipboard operation
NextChat copied to clipboard

hotfix: Cloud data sync upstash support for Tauri desktop app

Open Little-LittleProgrammer opened this issue 1 year ago • 1 comments

💻 变更类型 | Change Type

  • [ ] feat
  • [x] fix
  • [ ] refactor
  • [ ] perf
  • [ ] style
  • [ ] test
  • [ ] docs
  • [ ] ci
  • [ ] chore
  • [ ] build

🔀 变更说明 | Description of Change

目前的云端数据同步upstash 不支持 tauri app,所以进行了以下改动 fixes #5617

  1. 增加 fetch.rs 文件,支持 fetch 请求
  2. 更改 app/utils/cloud/upstash.ts 文件,当检测是 tauri app, 请求路径不再走代理,直接调用 rust 请求
  3. 修复 app/utils/cloud/upstash.ts:158 new URL 传参错误,导致永远进入 catch

Summary by CodeRabbit

  • New Features

    • Desktop (Tauri) builds now route network requests through a built-in HTTP bridge with unified fetch-like responses.
    • Bridge exposes text and JSON request/response handling with sensible defaults, redirects, and timeouts.
    • Upstash operations (check/get/set) use the bridge in desktop mode.
  • Bug Fixes

    • Fixed proxy URL construction to produce valid absolute request paths.
    • Improved header and body handling to prevent request failures and ensure consistent web/desktop routing.

Little-LittleProgrammer avatar Sep 09 '25 07:09 Little-LittleProgrammer

Walkthrough

Introduces a Tauri-aware HTTP bridge (Rust commands: http_fetch, http_fetch_text, http_fetch_json) and a TypeScript httpFetch wrapper. Upstash client now routes requests via this bridge when Tauri is present and adjusts URL/path handling accordingly. Tauri main registers the new commands.

Changes

Cohort / File(s) Summary
TS Upstash client + HTTP wrapper
app/utils/cloud/upstash.ts
Adds httpFetch that uses Tauri’s http_fetch when available; replaces direct fetch calls (check, redisGet, redisSet) to use httpFetch; adds Tauri-specific path resolution and adjusts proxied URL construction.
Tauri HTTP bridge (Rust)
src-tauri/src/fetch.rs
New module exposing tauri::command handlers: http_fetch, http_fetch_text, http_fetch_json; implements a reqwest-based client with timeouts, redirect limit, header/body handling; returns serializable FetchResponse (request_id, status, status_text, headers, body).
Tauri command registration
src-tauri/src/main.rs
Imports fetch module and registers new commands (fetch::http_fetch, fetch::http_fetch_text, fetch::http_fetch_json) in the Tauri invoke handler alongside existing stream handler.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UpstashTS as Upstash client (TS)
  participant httpFetchTS as httpFetch (TS)
  participant TauriWin as window.__TAURI__.invoke
  participant RustFetch as fetch::http_fetch (Rust)
  participant Remote as Remote Endpoint

  User->>UpstashTS: call check / redisGet / redisSet
  UpstashTS->>httpFetchTS: httpFetch(method, url, headers, body)
  alt Tauri environment
    httpFetchTS->>TauriWin: invoke("http_fetch", {method,url,headers,body})
    TauriWin->>RustFetch: http_fetch(...)
    RustFetch->>Remote: reqwest request
    Remote-->>RustFetch: HTTP response
    RustFetch-->>TauriWin: {status,status_text,headers,body(bytes)}
    TauriWin-->>httpFetchTS: response payload
    httpFetchTS-->>UpstashTS: Fetch-like Response
  else Browser environment
    httpFetchTS->>Remote: native fetch(...)
    Remote-->>httpFetchTS: response
    httpFetchTS-->>UpstashTS: response
  end
  UpstashTS-->>User: result

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • ChatGPTNextWeb/NextChat#5565 — Implements a Tauri HTTP bridge and frontend adapter similar to this PR (tauri commands + TS-side routing of fetches).

Suggested labels

enhancement

Suggested reviewers

  • lloydzhou
  • Dogtiti
  • Leizhenpeng

I twitch my ears at bridges new, Byte-carrots hop from Rust to UI glue. Through Tauri tunnels, packets dash, Headers rustle, bodies flash. Upstash burrows, keys in tow— 🥕🐇

Pre-merge checks (4 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly identifies the PR as a hotfix and clearly summarizes the core change of enabling Upstash cloud synchronization support in the Tauri desktop application, aligning directly with the primary modifications introduced.
Linked Issues Check ✅ Passed The pull request implements the Tauri HTTP bridge (fetch.rs) and updates upstash.ts to bypass the proxy and call Rust fetch commands, directly addressing the synchronization failure on the Windows/Tauri client described in issue #5617.
Out of Scope Changes Check ✅ Passed All introduced changes—addition of fetch.rs, adjustments in upstash.ts, and registration of Tauri commands—are focused on restoring Upstash sync support in the Tauri desktop application, with no extraneous or unrelated modifications present.
Description Check ✅ Passed The description specifies the change type (fix) and details the creation of fetch.rs, the conditional logic in upstash.ts for Tauri, and the correction of the URL argument error, all of which correspond precisely to the file changes in the PR.

[!TIP]

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

- Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more. - Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Sep 09 '25 07:09 coderabbitai[bot]