@reshotdev/screenshot 0.0.1-beta.14 → 0.0.1-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/publish.js +33 -1
package/package.json
CHANGED
package/src/commands/publish.js
CHANGED
|
@@ -629,6 +629,24 @@ function buildPublishMetadata({
|
|
|
629
629
|
};
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
+
/**
|
|
633
|
+
* Read pixel dimensions from a captured image so the platform can store and
|
|
634
|
+
* expose them (used by `reshot pull` for CLS-safe `<img width height>`
|
|
635
|
+
* embedding). Returns nulls for non-images or on any error — never throws.
|
|
636
|
+
*/
|
|
637
|
+
async function getImageDimensions(filePath, contentType) {
|
|
638
|
+
if (!filePath || !(contentType || "").startsWith("image/")) {
|
|
639
|
+
return { width: null, height: null };
|
|
640
|
+
}
|
|
641
|
+
try {
|
|
642
|
+
const sharp = require("sharp");
|
|
643
|
+
const meta = await sharp(filePath).metadata();
|
|
644
|
+
return { width: meta.width ?? null, height: meta.height ?? null };
|
|
645
|
+
} catch {
|
|
646
|
+
return { width: null, height: null };
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
632
650
|
/**
|
|
633
651
|
* Publish using transactional flow (direct R2 upload with presigned URLs)
|
|
634
652
|
*/
|
|
@@ -915,12 +933,18 @@ async function publishWithTransactionalFlow(
|
|
|
915
933
|
assets: [],
|
|
916
934
|
});
|
|
917
935
|
}
|
|
936
|
+
const dimensions = await getImageDimensions(
|
|
937
|
+
result.file.path,
|
|
938
|
+
result.file.contentType,
|
|
939
|
+
);
|
|
918
940
|
groupMap.get(groupKey).assets.push({
|
|
919
941
|
key: result.file.key,
|
|
920
942
|
s3Path: result.s3Path,
|
|
921
943
|
hash: result.file.hash,
|
|
922
944
|
visualKey: result.file.visualKey,
|
|
923
945
|
size: result.file.size,
|
|
946
|
+
width: dimensions.width,
|
|
947
|
+
height: dimensions.height,
|
|
924
948
|
contentType: result.file.contentType,
|
|
925
949
|
// Include diff data from CLI analysis
|
|
926
950
|
diffPercentage: result.file.diffData?.diffPercentage ?? null,
|
|
@@ -1014,7 +1038,15 @@ async function publishWithTransactionalFlow(
|
|
|
1014
1038
|
viewUrl = batchResult.viewUrl;
|
|
1015
1039
|
}
|
|
1016
1040
|
} catch (error) {
|
|
1017
|
-
|
|
1041
|
+
// Surface the server's descriptive error body (e.g. a validation
|
|
1042
|
+
// message) instead of just axios's opaque "Request failed with status
|
|
1043
|
+
// code 400" — otherwise a 1-line fix turns into a support ticket.
|
|
1044
|
+
const serverMsg =
|
|
1045
|
+
error.response?.data?.error || error.response?.data?.message;
|
|
1046
|
+
const detail = serverMsg
|
|
1047
|
+
? `${error.message} — ${serverMsg}`
|
|
1048
|
+
: error.message;
|
|
1049
|
+
console.log(chalk.red(` ✖ Batch request failed: ${detail}`));
|
|
1018
1050
|
failCount += chunk.length;
|
|
1019
1051
|
}
|
|
1020
1052
|
}
|