Skip to content

Conversation

Copy link

Copilot AI commented Oct 14, 2025

Problem

The examschedule button's openConfig() function was using the website token (server.siteKey) instead of the KV authorization token (server.kvToken) when constructing cloud data URLs. This was inconsistent with how other parts of the codebase handle KV authentication (e.g., kvServerProvider.js already prioritizes kvToken for HTTP headers).

Solution

Modified src/utils/dataProvider.js to prioritize kvToken over siteKey when adding the token parameter to cloud URLs. The implementation maintains full backward compatibility by falling back to siteKey if kvToken is not available.

Changes Made

In the getKeyCloudUrl() function:

  1. Added retrieval of the KV authorization token:

    let kvToken = getSetting("server.kvToken");
  2. Updated token selection logic with priority fallback:

    // 优先使用kvToken,若不存在则使用siteKey
    const token = kvToken || siteKey;
    if (accessType === 'private' && token) {
      const urlObj = new URL(url);
      urlObj.searchParams.set('token', token);
      url = urlObj.toString();
    }
  3. Updated JSDoc documentation to reflect the token priority behavior

Backward Compatibility

The change is fully backward compatible:

  • If kvToken is set → uses kvToken
  • If kvToken is empty/null → falls back to siteKey
  • If both are empty → no token parameter (existing behavior)

Example URLs Generated

With kvToken set:

https://kv.wuyuan.dev/device-uuid/es_12345?token=<kvToken_value>

With only siteKey (legacy):

https://kv.wuyuan.dev/device-uuid/es_12345?token=<siteKey_value>

Public access (no token needed):

https://kv.wuyuan.dev/device-uuid/es_12345

This change aligns the URL token parameter behavior with the HTTP header authentication pattern already established in kvServerProvider.js, providing consistent authentication handling across the application.

Original prompt

打开examshadule按钮所使用的获取数据云端地址的函数将kv授权令牌作为token传入query


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 14, 2025

Deploying classworks with  Cloudflare Pages  Cloudflare Pages

Latest commit: 92a2019
Status: ✅  Deploy successful!
Preview URL: https://c3b3a681.classworks.pages.dev
Branch Preview URL: https://copilot-update-exam-schedule.classworks.pages.dev

View logs

Copilot AI changed the title [WIP] Update function to include token in query for exam schedule Use kvToken instead of siteKey for examschedule cloud URL token parameter Oct 14, 2025
Copilot AI requested a review from Sunwuyuan October 14, 2025 10:25
Copilot finished work on behalf of Sunwuyuan October 14, 2025 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants