Skip to content

Commit

Permalink
opting for less greedy base64
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanirion committed Dec 5, 2023
1 parent 9c1e78f commit e51eff5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions packages/open-next/src/adapters/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ export default class S3Cache {
kind: "ROUTE",
body: Buffer.from(
cacheData.body ?? Buffer.alloc(0),
meta?.headers?.["content-type"]?.includes("application/json")
? "utf8"
: "base64",
String(meta?.headers?.["content-type"]).startsWith("image")
? "base64"
: "utf8",
),
status: meta?.status,
headers: meta?.headers,
Expand Down Expand Up @@ -282,7 +282,9 @@ export default class S3Cache {
JSON.stringify({
type: "route",
body: body.toString(
headers["content-type"] === "application/json" ? "utf8" : "base64",
String(headers["content-type"]).startsWith("image")
? "base64"
: "utf8",
),
meta: {
status,
Expand Down
6 changes: 3 additions & 3 deletions packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ function createCacheAssets(monorepoRoot: string, disableDynamoDBCache = false) {
? fs
.readFileSync(files.body)
.toString(
cacheFileMeta.headers["content-type"] === "application/json"
? "utf8"
: "base64",
cacheFileMeta.headers["content-type"].startsWith("image")
? "base64"
: "utf8",
)
: undefined,
};
Expand Down

0 comments on commit e51eff5

Please sign in to comment.