Skip to content

Migrate XMOJ-Script backend endpoints to /v1/* routes - #968

Closed
PythonSmall-Q with Copilot wants to merge 1 commit into
masterfrom
copilot/change-apis-to-v1
Closed

Migrate XMOJ-Script backend endpoints to /v1/* routes#968
PythonSmall-Q with Copilot wants to merge 1 commit into
masterfrom
copilot/change-apis-to-v1

Conversation

Copilot AI commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Backend routing now supports versioned endpoints under /v1/*, and this change aligns client-side calls with that contract across the userscript and messages UI.

  • HTTP API routing updates

    • Switched action API base URLs from unversioned paths to /v1/:
      • https://api.xmoj-bbs.me/v1/
      • http://127.0.0.1:8787/v1/ (SuperDebug)
  • WebSocket notification routing updates

    • Updated notification socket path to the versioned route:
      • /v1/ws/notifications?SessionID=...
  • Asset/image API routing updates

    • Updated image fetch/upload-render URLs to use:
      • https://assets.xmoj-bbs.me/v1/GetImage?ImageID=...
    • Applied in both XMOJ.user.js and messages.html.
// Before
const API_BASE = 'https://api.xmoj-bbs.me/';
const ASSET_BASE = 'https://assets.xmoj-bbs.me/GetImage?ImageID=';

// After
const API_BASE = 'https://api.xmoj-bbs.me/v1/';
const ASSET_BASE = 'https://assets.xmoj-bbs.me/v1/GetImage?ImageID=';

Summary by Sourcery

Align client-side API, WebSocket, and image asset calls with the backend’s new versioned /v1 routing.

Enhancements:

  • Update userscript HTTP API requests to target /v1 endpoints in both production and SuperDebug environments.
  • Route notification WebSocket connections through the /v1/ws/notifications path.
  • Use versioned /v1/GetImage asset URLs for uploaded images in both the userscript and messages UI.

Summary by cubic

Migrates all client calls to versioned /v1 routes to match the new backend contract. Applies to HTTP, WebSocket, and asset image endpoints in XMOJ.user.js and the messages UI.

  • Refactors
    • HTTP base URLs now use https://api.xmoj-bbs.me/v1/ and http://127.0.0.1:8787/v1/ (SuperDebug).
    • WebSocket notifications moved to /v1/ws/notifications?SessionID=....
    • Asset image fetch URLs use https://assets.xmoj-bbs.me/v1/GetImage?ImageID=....

Written for commit bb42d55. Summary will update on new commits.

Agent-Logs-Url: https://github.com/XMOJ-Script-dev/XMOJ-Script/sessions/f076c6b7-9c17-4102-bba3-850043d58906

Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
@sourcery-ai

sourcery-ai Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Aligns all client-side HTTP, WebSocket, and asset/image requests with the new versioned backend contract by switching them from unversioned root paths to /v1/* routes in the userscript and messages UI.

Sequence diagram for versioned API and WebSocket interactions

sequenceDiagram
    actor User
    participant Browser
    participant XMOJ_UserScript
    participant Messages_UI
    participant API_Server_v1
    participant Asset_Server_v1
    participant WS_Endpoint_v1

    User->>Browser: Load forum page
    Browser->>XMOJ_UserScript: Execute userscript

    User->>XMOJ_UserScript: Trigger API action
    XMOJ_UserScript->>API_Server_v1: POST /v1/Action
    API_Server_v1-->>XMOJ_UserScript: JSON response

    User->>XMOJ_UserScript: Upload image
    XMOJ_UserScript->>API_Server_v1: POST /v1/UploadImage
    API_Server_v1-->>XMOJ_UserScript: ImageID
    XMOJ_UserScript->>Browser: Insert markdown ![](https://assets.xmoj-bbs.me/v1/GetImage?ImageID=ImageID)
    Browser->>Asset_Server_v1: GET /v1/GetImage?ImageID=ImageID
    Asset_Server_v1-->>Browser: Image bytes

    User->>Messages_UI: Open messages.html
    Browser->>Messages_UI: Run UI JS with API_BASE=https://api.xmoj-bbs.me/v1/
    Messages_UI->>API_Server_v1: POST /v1/ListMessages
    API_Server_v1-->>Messages_UI: Messages data

    User->>XMOJ_UserScript: Enable notifications
    XMOJ_UserScript->>WS_Endpoint_v1: CONNECT /v1/ws/notifications?SessionID=Session
    WS_Endpoint_v1-->>XMOJ_UserScript: Push notifications
Loading

File-Level Changes

Change Details Files
Update HTTP API base URLs to use versioned /v1/ endpoints for both production and SuperDebug environments.
  • Change the GM_xmlhttpRequest API base URL from https://api.xmoj-bbs.me/ to https://api.xmoj-bbs.me/v1/ in the userscript.
  • Change the SuperDebug local API base URL from http://127.0.0.1:8787/ to http://127.0.0.1:8787/v1/ in the userscript.
  • Update API_BASE constant in messages.html to point to https://api.xmoj-bbs.me/v1/.
XMOJ.user.js
messages.html
Version WebSocket notification endpoint to /v1/ws/notifications while preserving existing query parameters and environment switching.
  • Adjust WebSocket URL construction to append /v1/ws/notifications instead of /ws/notifications while keeping SessionID query parameter and ws/wss selection logic intact.
XMOJ.user.js
Version asset/image retrieval URLs to /v1/GetImage across all image upload/render paths.
  • Update all Markdown image insertion templates to use https://assets.xmoj-bbs.me/v1/GetImage?ImageID=${...} instead of the unversioned GetImage path in the userscript.
  • Update ASSET_BASE constant in messages.html to include /v1/ in the image retrieval URL.
XMOJ.user.js
messages.html

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown
Contributor

请向dev分支提交pull request, 本pull request将被自动关闭

@github-actions github-actions Bot closed this Apr 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

请向dev分支提交pull request, 本pull request将被自动关闭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants