Migrate XMOJ-BBS client endpoints to /v1 routes#969
Conversation
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>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideMigrates 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 APIsequenceDiagram
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
Sequence diagram for WebSocket notifications via v1 routesequenceDiagram
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
Sequence diagram for image upload and rendering via v1 asset endpointsequenceDiagram
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 
User->>Assets_CDN_v1: Request /v1/GetImage?ImageID=ImageID
Assets_CDN_v1-->>User: Return image content
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
/v1API 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 theURL/URLSearchParamsAPIs 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 + `` + After;
+ Content.value = Before + `` + 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 + `` + After;
```
```javascript
ContentElement.value = Before + `` + 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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
RequestAPIto callhttps://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/GetImageand/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.
Deploying xmoj-script-dev-channel with
|
| 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 |
There was a problem hiding this comment.
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.
Signed-off-by: zsTree <wa2025666@gmail.com>
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>
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
RequestAPIbase URLs to target/v1/in both normal andSuperDebugmodes..../v1/<Action>.WebSocket notification routing
/ws/notificationsto/v1/ws/notifications.Image asset endpoint routing
.../v1/GetImage?ImageID=...in userscript editors.messages.htmlASSET_BASEsimilarly.Messages WebUI API base
messages.htmlAPI_BASEfrom root API path to/v1/.Summary by Sourcery
Migrate all client-side API, WebSocket, and image asset calls to the backend's versioned /v1 endpoints.
Enhancements:
Summary by cubic
Migrate all client HTTP, WebSocket, and image endpoints to the
/v1API to match backend routing. Also bump the client to 3.4.3 (prerelease) and refresh theUpdate.jsonentry.RequestAPIbase now/v1/(normal +SuperDebug)./v1/ws/notifications./v1/GetImage.API_BASEandASSET_BASEnow/v1.3.4.3in userscript andpackage.json; updateUpdate.json3.4.3 metadata (timestamp and description).Written for commit 5c6e3c5. Summary will update on new commits.