Fix Images docs code examples (7 files)#28396
Fix Images docs code examples (7 files)#28396ask-bonk[bot] wants to merge 4 commits intoproductionfrom
Conversation
Co-authored-by: elithrar <elithrar@users.noreply.github.com>
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
|
/bonk run a final review using the code-review skill, make any changes, and summarize your fixes. |
…r() for Images binding input env.IMAGES.input() expects ReadableStream<Uint8Array>, not ArrayBuffer. Changed all 4 code blocks to use file.stream() consistently.
Code Review SummaryReviewed all 7 changed files against the Issue found and fixed[HIGH]
Fix: Changed all 4 code blocks to use Files reviewed — no additional issues
|
Co-authored-by: elithrar <elithrar@users.noreply.github.com>
|
All changes pass validation. Here's a summary: Changes madeWrapped all Files changed
Files reviewed — no change needed
|
There was a problem hiding this comment.
/bonk all workers code should be typescript first.
Use to replace any “js” code fences too.
Run a code review pass to ensure you did not break the examples.
There was a problem hiding this comment.
/bonk all workers code should be typescript first.
Use to replace any “js” code fences too.
Run a code review pass to ensure you did not break the examples.
This comment was marked as outdated.
This comment was marked as outdated.
…first with TypeScriptExample
SummaryConverted all 5 Workers code blocks in Changes made
Code review findings (fixed)
|
Here is a summary of all fixes made across 7 files, organized by severity:
Summary of fixes
CRITICAL (would cause runtime errors)
serve-private-images.mdx:77—event.request.urlreferences undefinedeventvariable. Fixed torequest.url(the actual parameter name in thefetch(request, env, ctx)handler).upload-file-worker.mdx:47— Missing closing parenthesis innew File([bytes], 'image.jpg')— wasnew File([bytes], 'image.jpg';which is a syntax error.transform-via-workers.mdx:195—response.redirect(imageURL, 307)called as an instance method, butredirect()is a static method onResponse. Fixed toResponse.redirect(imageURL, 307).control-origin-access.mdx:45,88—requestURL.pathis not a property onURL. Fixed torequestURL.pathname.control-origin-access.mdx:124— Missing comma afterheaders: signedHeadersin the fetch options object literal. This is a syntax error.draw-overlays.mdx:117,131,144,158— Semicolons (;) used after array values inside object literals (draw: [...];) instead of commas. Syntax error in all 4 snippet examples.HIGH (type errors / wrong behavior)
transform-via-workers.mdx:235-239—url.searchParams.get("width")returnsstring | null, butoptions.cf.image.widthexpectsnumber. The string would be passed directly, causing either a type error or unexpected behavior. Fixed by wrapping inparseInt(..., 10).control-origin-access.mdx:65,69— Same issue:searchParams.get("width")returns a string, so> 1000performs string comparison (e.g.,"9" > "1000"istrue). Fixed by parsing to integer first. Also replacedthrow Error(...)withreturn new Response(...)for proper HTTP error handling.draw-overlays.mdx:82-86—.output()returnsPromise<ImageTransformationResult>, so chaining.response()directly on it (without await) calls.response()on the Promise object, not the result. Fixed to(await ...output()).response()pattern.watermark-from-kv.mdx:46—result.response()called twice: once to createresponse(line 42), then again on the return (line 46). Sinceresponse()creates a new Response each time, the second call may consume an already-read stream. Fixed to return the existingresponsevariable.MEDIUM (code quality / misleading patterns)
transform-via-workers.mdx:161-169— Used deprecated Service WorkeraddEventListener("fetch")syntax. Updated to modern ES moduleexport default { async fetch(request) { ... } }pattern, consistent with all other examples on the page.optimize-user-uploaded-image.mdx(3 code blocks) — Containedvar __defProp = Object.defineProperty; var __name = ...compiled JavaScript output (from esbuild/tsc). This is confusing build artifact boilerplate that readers would copy. Removed and replaced with clean source code.Files NOT changed (reviewed, no issues found)
transcode-from-workers-ai.mdx— Code is correctintegrate-with-frameworks.mdx— Code is correct (Next.js loader examples are valid)bindings.mdx— Code is correct (uses proper(await ...).response()pattern)Closes #28270
github run