Skip to content

Feature/qiniu prefetch - #16

Merged
LancerComet merged 2 commits into
masterfrom
feature/qiniu-prefetch
Apr 15, 2026
Merged

LancerComet merged 2 commits into
masterfrom
feature/qiniu-prefetch

Conversation

@LancerComet

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings April 15, 2026 11:58
@LancerComet
LancerComet merged commit 205e2f6 into master Apr 15, 2026
5 checks passed
@LancerComet
LancerComet deleted the feature/qiniu-prefetch branch April 15, 2026 12:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an optional “prefetch after upload” workflow to the @lancercomet/qiniu-uploader CLI so that successfully uploaded assets can be cache-warmed via Qiniu Fusion CDN.

Changes:

  • Add --prefetch, --prefetch-domain, and --prefetch-product CLI options and implement post-upload prefetch batching/retry logic.
  • Update README with prefetch usage and behavior notes.
  • Bump package version metadata.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
QiniuUploader/package.json Updates package version.
QiniuUploader/package-lock.json Updates lockfile package version fields accordingly.
QiniuUploader/index.mjs Implements upload key collection + Qiniu Fusion CDN prefetch request flow.
QiniuUploader/README.md Documents prefetch options and behavior.
Files not reviewed (1)
  • QiniuUploader/package-lock.json: Language not supported

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

Comment on lines 8 to +9
"name": "@lancercomet/qiniu-uploader",
"version": "0.1.2",
"version": "0.2.1-test",

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

package-lock.json also records the package version as "0.2.1-test". If the prerelease suffix is not meant to be published, revert both version fields here to the release version to avoid lockfile churn and unexpected published metadata.

Copilot uses AI. Check for mistakes.
Comment thread QiniuUploader/index.mjs
Comment on lines +155 to +161
let data = ''
res.on('data', (chunk) => { data += chunk })
res.on('end', () => {
try {
resolve(JSON.parse(data))
} catch {
reject(new Error(`Failed to parse prefetch response: ${data}`))

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

Prefetch response handling can crash the whole CLI: if Qiniu returns a non-JSON body (e.g. HTML error page, empty body, proxy error), JSON.parse will throw and reject, and callers don't catch it. Consider checking res.statusCode, buffering only on expected content-types, and returning a structured error (or catching the rejection in prefetchAllUrls and treating it as retryable/failed batch) so uploads don't fail due to a transient prefetch error.

Suggested change
let data = ''
res.on('data', (chunk) => { data += chunk })
res.on('end', () => {
try {
resolve(JSON.parse(data))
} catch {
reject(new Error(`Failed to parse prefetch response: ${data}`))
const statusCode = res.statusCode || 0
const contentType = String(res.headers['content-type'] || '').toLowerCase()
const isJsonResponse = contentType.includes('application/json')
let data = ''
res.on('data', (chunk) => { data += chunk })
res.on('end', () => {
if (!data) {
resolve({
code: statusCode,
error: `Prefetch API returned an empty response${statusCode ? ` (HTTP ${statusCode})` : ''}`
})
return
}
if (!isJsonResponse) {
resolve({
code: statusCode,
error: `Prefetch API returned a non-JSON response${statusCode ? ` (HTTP ${statusCode})` : ''}: ${data}`
})
return
}
try {
resolve(JSON.parse(data))
} catch {
resolve({
code: statusCode,
error: `Failed to parse prefetch response${statusCode ? ` (HTTP ${statusCode})` : ''}: ${data}`
})

Copilot uses AI. Check for mistakes.
Comment thread QiniuUploader/index.mjs
Comment on lines 197 to +200

while (retries <= maxRetries && !success) {
if (retries > 0) {
const delay = retries * 2000

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

The comment says "exponential backoff", but the retry delay is currently linear (retries * 2000). Either update the delay calculation to be exponential (e.g. baseDelay * 2^(retries-1)) or adjust the comment to match the actual behavior.

Suggested change
while (retries <= maxRetries && !success) {
if (retries > 0) {
const delay = retries * 2000
const baseDelay = 2000
while (retries <= maxRetries && !success) {
if (retries > 0) {
const delay = baseDelay * Math.pow(2, retries - 1)

Copilot uses AI. Check for mistakes.
Comment thread QiniuUploader/README.md

- URLs are submitted in batches of 20 (Qiniu Fusion CDN API limit).
- A 1-second interval is applied between batches to respect the rate limit.
- On QPS throttling (403024) or server errors (500000), the batch will be retried up to 3 times with exponential backoff.

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

The README says retries use "exponential backoff", but the implementation uses a linear delay (retries * 2000). Please update either the documentation or the retry logic so they match.

Suggested change
- On QPS throttling (403024) or server errors (500000), the batch will be retried up to 3 times with exponential backoff.
- On QPS throttling (403024) or server errors (500000), the batch will be retried up to 3 times with a linearly increasing delay (2s, 4s, 6s).

Copilot uses AI. Check for mistakes.
{
"name": "@lancercomet/qiniu-uploader",
"version": "0.1.2",
"version": "0.2.1-test",

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

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

The package version was changed to a prerelease string ("0.2.1-test"). If this is intended only for local testing, consider keeping the real semver version here (e.g. 0.2.1) and publish the prerelease via npm dist-tags or a separate prerelease versioning strategy, otherwise consumers may accidentally depend on the test build.

Suggested change
"version": "0.2.1-test",
"version": "0.2.1",

Copilot uses AI. Check for mistakes.
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