Skip to content

Migrate XMOJ-BBS client endpoints to /v1 routes#969

Merged
def-WA2025 merged 5 commits into
devfrom
copilot/change-apis-to-v1-again
Apr 12, 2026
Merged

Migrate XMOJ-BBS client endpoints to /v1 routes#969
def-WA2025 merged 5 commits into
devfrom
copilot/change-apis-to-v1-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

This PR updates the script-side backend integration to use the new versioned API surface introduced by the backend /v1/* routing changes. It aligns HTTP, WebSocket, and image endpoint paths with the new contract.

  • HTTP API routing

    • Updated RequestAPI base URLs to target /v1/ in both normal and SuperDebug modes.
    • Effect: all action calls now resolve to .../v1/<Action>.
  • WebSocket notification routing

    • Updated notification socket endpoint from /ws/notifications to /v1/ws/notifications.
    • Keeps session query handling unchanged.
  • Image asset endpoint routing

    • Updated generated image markdown URLs to .../v1/GetImage?ImageID=... in userscript editors.
    • Updated messages.html ASSET_BASE similarly.
  • Messages WebUI API base

    • Updated messages.html API_BASE from root API path to /v1/.
// before
url: "https://api.xmoj-bbs.me/" + Action
ws:  "wss://api.xmoj-bbs.me/ws/notifications?SessionID=" + Session
img: "https://assets.xmoj-bbs.me/GetImage?ImageID=" + imageId

// after
url: "https://api.xmoj-bbs.me/v1/" + Action
ws:  "wss://api.xmoj-bbs.me/v1/ws/notifications?SessionID=" + Session
img: "https://assets.xmoj-bbs.me/v1/GetImage?ImageID=" + imageId

Summary by Sourcery

Migrate all client-side API, WebSocket, and image asset calls to the backend's versioned /v1 endpoints.

Enhancements:

  • Update HTTP RequestAPI base URLs, including SuperDebug mode, to target the /v1 API routes.
  • Point notification WebSocket connections to the /v1/ws/notifications endpoint while preserving session query handling.
  • Adjust generated markdown image URLs and the messages.html ASSET_BASE to use the /v1/GetImage asset endpoint.
  • Update messages.html API_BASE to use the versioned /v1 API root.

Summary by cubic

Migrate all client HTTP, WebSocket, and image endpoints to the /v1 API to match backend routing. Also bump the client to 3.4.3 (prerelease) and refresh the Update.json entry.

  • Refactors
    • HTTP: RequestAPI base now /v1/ (normal + SuperDebug).
    • WebSocket: notifications at /v1/ws/notifications.
    • Images: markdown URLs use /v1/GetImage.
    • Messages WebUI: API_BASE and ASSET_BASE now /v1.
    • Versioning: bump to 3.4.3 in userscript and package.json; update Update.json 3.4.3 metadata (timestamp and description).

Written for commit 5c6e3c5. Summary will update on new commits.

Agent-Logs-Url: https://github.com/XMOJ-Script-dev/XMOJ-Script/sessions/606d7c42-f0ad-4d97-80ae-b8d92c2d6725

Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
@PythonSmall-Q PythonSmall-Q marked this pull request as ready for review April 11, 2026 02:41
Copilot AI review requested due to automatic review settings April 11, 2026 02:41
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 11, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Migrates the XMOJ-BBS userscript and messages web UI to use the new versioned /v1 HTTP, WebSocket, and image asset endpoints, updating all hard-coded base URLs accordingly.

Sequence diagram for HTTP requests migrated to v1 API

sequenceDiagram
    actor User
    participant BrowserUserscript
    participant XMOJ_API_v1 as XMOJ_API_v1

    User->>BrowserUserscript: Trigger backend action
    BrowserUserscript->>XMOJ_API_v1: POST /v1/Action
    XMOJ_API_v1-->>BrowserUserscript: JSON response
    BrowserUserscript-->>User: Update page with results
Loading

Sequence diagram for WebSocket notifications via v1 route

sequenceDiagram
    actor User
    participant BrowserUserscript
    participant XMOJ_Notification_WS_v1 as XMOJ_Notification_WS_v1

    User->>BrowserUserscript: Open notifications feature
    BrowserUserscript->>XMOJ_Notification_WS_v1: CONNECT /v1/ws/notifications?SessionID=Session
    XMOJ_Notification_WS_v1-->>BrowserUserscript: Notification message stream
    BrowserUserscript-->>User: Display real-time notifications
Loading

Sequence diagram for image upload and rendering via v1 asset endpoint

sequenceDiagram
    actor User
    participant BrowserEditor
    participant XMOJ_API_v1 as XMOJ_API_v1
    participant Assets_CDN_v1 as Assets_CDN_v1

    User->>BrowserEditor: Select image to insert
    BrowserEditor->>XMOJ_API_v1: POST /v1/UploadImage with image data
    XMOJ_API_v1-->>BrowserEditor: { Success, Data.ImageID }
    BrowserEditor->>BrowserEditor: Insert markdown ![](https://assets.xmoj-bbs.me/v1/GetImage?ImageID=ImageID)
    User->>Assets_CDN_v1: Request /v1/GetImage?ImageID=ImageID
    Assets_CDN_v1-->>User: Return image content
Loading

File-Level Changes

Change Details Files
Point all userscript HTTP API calls to the versioned /v1 backend routes, including SuperDebug mode. XMOJ.user.js
Update WebSocket notification endpoint to the /v1 namespace while preserving existing debug handling and query parameters.
  • Change notification WebSocket path from /ws/notifications to /v1/ws/notifications for both SuperDebug and production hosts.
XMOJ.user.js
Update all generated image markdown URLs in the userscript to use the versioned /v1 image asset route. XMOJ.user.js
Align messages web UI API and image asset bases with the /v1 backend API and asset endpoints. 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

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The /v1 API and asset base URLs are now hardcoded in several places (userscript RequestAPI, WebSocket, multiple markdown image builders, and messages.html); consider centralizing these into shared constants/helpers so a future version bump doesn’t require touching many call sites.
  • The repeated markdown image URL template construction (https://assets.xmoj-bbs.me/v1/GetImage?ImageID=...) appears in multiple upload handlers; extracting a small helper function for building image markdown would reduce duplication and the risk of inconsistent changes later.
  • Since query strings are now part of the versioned paths (e.g., /v1/ws/notifications?SessionID=...), you may want to consider using the URL/URLSearchParams APIs instead of manual string concatenation to make future additions of parameters safer and less error-prone.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `/v1` API and asset base URLs are now hardcoded in several places (userscript RequestAPI, WebSocket, multiple markdown image builders, and messages.html); consider centralizing these into shared constants/helpers so a future version bump doesn’t require touching many call sites.
- The repeated markdown image URL template construction (`https://assets.xmoj-bbs.me/v1/GetImage?ImageID=...`) appears in multiple upload handlers; extracting a small helper function for building image markdown would reduce duplication and the risk of inconsistent changes later.
- Since query strings are now part of the versioned paths (e.g., `/v1/ws/notifications?SessionID=...`), you may want to consider using the `URL`/`URLSearchParams` APIs instead of manual string concatenation to make future additions of parameters safer and less error-prone.

## Individual Comments

### Comment 1
<location path="XMOJ.user.js" line_range="5024-5027" />
<code_context>
                                             }, (ResponseData) => {
                                                 if (ResponseData.Success) {
-                                                    Content.value = Before + `![](https://assets.xmoj-bbs.me/GetImage?ImageID=${ResponseData.Data.ImageID})` + After;
+                                                    Content.value = Before + `![](https://assets.xmoj-bbs.me/v1/GetImage?ImageID=${ResponseData.Data.ImageID})` + After;
                                                     Content.dispatchEvent(new Event("input"));
                                                 } else {
</code_context>
<issue_to_address>
**suggestion:** These asset URLs are repeated multiple times and could benefit from a shared helper or constant.

This `https://assets.xmoj-bbs.me/v1/GetImage?ImageID=...` pattern is used in multiple places in this file. Consider extracting a shared constant or helper (similar to `ASSET_BASE` in `messages.html`) so future endpoint or version changes only need to be updated in one location.

Suggested implementation:

```javascript
        const ASSET_BASE = "https://assets.xmoj-bbs.me";

        let wsUrl = (UtilityEnabled("SuperDebug") ? "ws://127.0.0.1:8787" : "wss://api.xmoj-bbs.me") + "/v1/ws/notifications?SessionID=" + Session;

```

```javascript
                                                    Content.value = Before + `![](${ASSET_BASE}/v1/GetImage?ImageID=${ResponseData.Data.ImageID})` + After;

```

```javascript
                                                        ContentElement.value = Before + `![](${ASSET_BASE}/v1/GetImage?ImageID=${ResponseData.Data.ImageID})` + After;

```

1. If there are other occurrences of `https://assets.xmoj-bbs.me/...` in this file (e.g. for other asset types or older endpoints), they should be updated to use the same `ASSET_BASE` constant for consistency.
2. If the userscript is wrapped in an IIFE or module pattern, ensure `ASSET_BASE` is defined in a shared scope accessible to all the usages; adjust the insertion point accordingly (e.g. move the `const ASSET_BASE` definition near the top of the file with other constants).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread XMOJ.user.js
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the XMOJ-BBS userscript and the messages WebUI to the backend’s versioned /v1 API namespace, aligning HTTP actions, WebSocket notifications, and image asset URLs with the updated routing contract.

Changes:

  • Update userscript RequestAPI to call https://api.xmoj-bbs.me/v1/<Action> (and local SuperDebug equivalent).
  • Update userscript notification WebSocket endpoint to /v1/ws/notifications.
  • Update image URL generation and WebUI constants to use /v1/GetImage and /v1/ API base.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
XMOJ.user.js Switches HTTP API base, notification WS path, and generated asset image URLs to /v1 routes.
messages.html Updates API_BASE and ASSET_BASE constants to point to /v1 endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hendragon-bot hendragon-bot Bot added user-script This issue or pull request is related to the main user script website This issue or pull request is related to website related files labels Apr 11, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 11, 2026

Deploying xmoj-script-dev-channel with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5c6e3c5
Status: ✅  Deploy successful!
Preview URL: https://dc913d66.xmoj-script-dev-channel.pages.dev
Branch Preview URL: https://copilot-change-apis-to-v1-ag.xmoj-script-dev-channel.pages.dev

View logs

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Apr 11, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="Update.json">

<violation number="1" location="Update.json:3551">
P3: The changelog description is truncated and omits `/v1`, making this release entry misleading.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread Update.json
@def-WA2025 def-WA2025 merged commit bf3182f into dev Apr 12, 2026
8 checks passed
@def-WA2025 def-WA2025 deleted the copilot/change-apis-to-v1-again branch April 12, 2026 05:46
boomzero added a commit that referenced this pull request Apr 12, 2026
Reverts the API route changes from #969 that added /v1/ prefixes
to all backend endpoints, while preserving the 3.4.3 version bump.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@boomzero boomzero mentioned this pull request Apr 12, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M user-script This issue or pull request is related to the main user script website This issue or pull request is related to website related files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants