Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,12 +1536,16 @@ class ServiceRenderer extends base_1.BaseRenderer {
if (!cached) {
return (0, base_1.createErrorResult)(frame, penFilePath, `Frame ${frame.id} not found in API response`);
}
// Write the image to disk
// Download image from service and write to disk
const dir = path.dirname(outputPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
const buffer = Buffer.from(cached.imageBase64, 'base64');
const imgResp = await fetch(cached.imageUrl);
if (!imgResp.ok) {
return (0, base_1.createErrorResult)(frame, penFilePath, `Failed to download image: ${imgResp.status}`);
}
const buffer = Buffer.from(await imgResp.arrayBuffer());
fs.writeFileSync(outputPath, buffer);
const result = (0, base_1.createSuccessResult)(frame, penFilePath, outputPath);
result.imageUrl = cached.imageUrl;
Expand Down Expand Up @@ -1626,7 +1630,6 @@ class ServiceRenderer extends base_1.BaseRenderer {
const frameMap = new Map();
for (const screenshot of data.screenshots) {
frameMap.set(screenshot.frameId, {
imageBase64: screenshot.imageBase64,
format: screenshot.format,
width: screenshot.width,
height: screenshot.height,
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/renderers/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ interface ServiceScreenshot {
frameName: string;
width: number;
height: number;
imageBase64: string;
format: string;
scale: number;
imageUrl?: string;
imageUrl: string;
}

interface ServiceResponse {
Expand Down Expand Up @@ -66,11 +65,10 @@ interface JobStatusResponse {

/** Cached result for a single frame from the API */
interface CachedFrame {
imageBase64: string;
format: string;
width: number;
height: number;
imageUrl?: string;
imageUrl: string;
}

const POLL_INITIAL_INTERVAL_MS = 2000;
Expand Down Expand Up @@ -165,13 +163,17 @@ export class ServiceRenderer extends BaseRenderer {
);
}

// Write the image to disk
// Download image from service and write to disk
const dir = path.dirname(outputPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}

const buffer = Buffer.from(cached.imageBase64, 'base64');
const imgResp = await fetch(cached.imageUrl);
if (!imgResp.ok) {
return createErrorResult(frame, penFilePath, `Failed to download image: ${imgResp.status}`);
}
const buffer = Buffer.from(await imgResp.arrayBuffer());
fs.writeFileSync(outputPath, buffer);

const result = createSuccessResult(frame, penFilePath, outputPath);
Expand Down Expand Up @@ -276,7 +278,6 @@ export class ServiceRenderer extends BaseRenderer {
const frameMap = new Map<string, CachedFrame>();
for (const screenshot of data.screenshots) {
frameMap.set(screenshot.frameId, {
imageBase64: screenshot.imageBase64,
format: screenshot.format,
width: screenshot.width,
height: screenshot.height,
Expand Down
6 changes: 3 additions & 3 deletions test-fixtures/designs/random.pen
Original file line number Diff line number Diff line change
Expand Up @@ -6478,7 +6478,7 @@
},
"--terracotta": {
"type": "color",
"value": "#C05A3C"
"value": "#C05A3D"
},
"--text-light": {
"type": "color",
Expand All @@ -6494,7 +6494,7 @@
},
"--warning": {
"type": "color",
"value": "#C05A3C"
"value": "#C05A3D"
}
}
}
}