fix(web): load pull request images from private repositories #6601
Closedartieeg(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/6601/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/http.ts lines 266 to 266OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -219,0 +246,21 @@246+ .pipe(Effect.orElseSucceed(() => null));247+ if (!response || response.status < 200 || response.status >= 300) {248+ return HttpServerResponse.text("Not Found", { status: 404 });249+ }250+ const contentType = response.headers["content-type"]?.split(";", 1)[0] ?? "";251+ if (!contentType.startsWith("image/")) {252+ return HttpServerResponse.text("Not Found", { status: 404 });253+ }254+ const bytes = yield* response.arrayBuffer.pipe(255+ Effect.map((buffer) => new Uint8Array(buffer)),256+ Effect.orElseSucceed(() => null),257+ );258+ if (!bytes) {259+ return HttpServerResponse.text("Internal Server Error", {260+ status: 500,261+ });262+ }263+ return HttpServerResponse.uint8Array(bytes, {264+ status: 200,265+ headers: {266+ ...assetResponseHeaders(asset.url),
- apps/server/src/http.ts lines 277 to 273OutdatedResolvedby artieeg(GitHub profile, opens in a new tab)@@ -219,0 +253,21 @@253+ const contentType = response.headers["content-type"]?.split(";", 1)[0] ?? "";254+ if (!contentType.startsWith("image/")) {255+ return HttpServerResponse.text("Not Found", { status: 404 });256+ }257+ const bytes = yield* response.arrayBuffer.pipe(258+ Effect.map((buffer) => new Uint8Array(buffer)),259+ Effect.orElseSucceed(() => null),260+ );261+ if (!bytes) {262+ return HttpServerResponse.text("Internal Server Error", {263+ status: 500,264+ });265+ }266+ return HttpServerResponse.uint8Array(bytes, {267+ status: 200,268+ headers: {269+ ...assetResponseHeaders(asset.url, contentType),270+ "Content-Type": contentType,271+ },272+ });273+ }
- apps/web/src/components/pullRequest/PullRequestMarkdown.tsx lines 23 to 23OutdatedResolvedby artieeg(GitHub profile, opens in a new tab)@@ -2,6 +3,21 @@3+import { useMemo, type ComponentProps } from "react";245+import { useAssetUrl } from "~/assets/assetUrls";36 import { cn } from "~/lib/utils";4758 import ChatMarkdown from "../ChatMarkdown";69 import { splitPullRequestBody } from "./pullRequestMarkdown.logic";71011+const GITHUB_USER_ATTACHMENT_PREFIX = "https://github.com/user-attachments/assets/";12+13+function PullRequestImage({14+ environmentId,15+ src,16+ ...props17+}: ComponentProps<"img"> & { environmentId: EnvironmentId }) {18+ const resource = useMemo(19+ () => ({ _tag: "github-user-attachment" as const, url: src ?? "" }),20+ [src],21+ );22+ const authenticatedSrc = useAssetUrl(environmentId, resource);23+ return <img {...props} src={authenticatedSrc ?? undefined} />;@@ -219,0 +237,21 @@237+ );238+ if (token.length === 0) {239+ return HttpServerResponse.text("Not Found", { status: 404 });240+ }241+ const httpClient = yield* HttpClient.HttpClient;242+ const response = yield* httpClient243+ .execute(244+ HttpClientRequest.get(asset.url).pipe(245+ HttpClientRequest.setHeader("accept", "image/*"),246+ HttpClientRequest.bearerToken(token),247+ ),248+ )249+ .pipe(Effect.orElseSucceed(() => null));250+ if (!response || response.status < 200 || response.status >= 300) {251+ return HttpServerResponse.text("Not Found", { status: 404 });252+ }253+ const contentType = response.headers["content-type"]?.split(";", 1)[0] ?? "";254+ if (!contentType.startsWith("image/")) {255+ return HttpServerResponse.text("Not Found", { status: 404 });256+ }257+ const bytes = yield* response.arrayBuffer.pipe(
- apps/server/src/assets/AssetAccess.ts lines 399 to 402Resolvedby artieeg(GitHub profile, opens in a new tab)@@ -363,3 +394,8 @@363394 }364395 break;365396 }397+ case "github-user-attachment": {398+ if (!isGitHubUserAttachmentUrl(input.resource.url)) {399+ return yield* new AssetPreviewTypeValidationError({400+ resource: input.resource,401+ });
- @@ -81,4 +128,4 @@81128 allowedHeaders: browserApiCorsAllowedHeaders,82129 maxAge: 600,83130 });84- }),131+ }).pipe(Effect.provide(ProcessRunner.layer)),
- apps/server/src/http.ts line 131OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -81,4 +128,4 @@81128 allowedHeaders: browserApiCorsAllowedHeaders,82129 maxAge: 600,83130 });84- }),131+ }).pipe(Effect.provide(ProcessRunner.layer)),
- @@ -81,4 +128,4 @@81128 allowedHeaders: browserApiCorsAllowedHeaders,82129 maxAge: 600,83130 });84- }),131+ }).pipe(Effect.provide(ProcessRunner.layer)),
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
7f0b20df-0bf3-4d78-ade5-39d1aecbd59bYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share