@medialane/sdk 0.191.0 → 0.193.0
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/dist/index.cjs +29 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -497,7 +497,11 @@ function createImageProxyHandler(config) {
|
|
|
497
497
|
if ("error" in validated) return jsonError(validated.error, validated.status);
|
|
498
498
|
let upstream;
|
|
499
499
|
try {
|
|
500
|
-
|
|
500
|
+
const isBackendImage = backendOrigin && /^\/media\/[^/]+\/[^/]+\/[^/]+\/image$/.test(validated.url.pathname);
|
|
501
|
+
upstream = await safeFetch(
|
|
502
|
+
isBackendImage ? new URL(validated.url.pathname, backendOrigin) : validated.url,
|
|
503
|
+
MAX_IMAGE_REDIRECTS
|
|
504
|
+
);
|
|
501
505
|
} catch {
|
|
502
506
|
return jsonError("Failed to fetch image", 502);
|
|
503
507
|
}
|
|
@@ -823,9 +827,11 @@ var MAX_IPFS_GATEWAY_RESPONSE_BYTES = 25 * 1024 * 1024;
|
|
|
823
827
|
// src/uploads.ts
|
|
824
828
|
var MB = 1024 * 1024;
|
|
825
829
|
var MAX_UPLOAD_BYTES = 90 * MB;
|
|
830
|
+
var IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png", ".gif", ".svg", ".webp", ".avif"];
|
|
826
831
|
var UPLOAD_LIMITS = {
|
|
827
832
|
image: {
|
|
828
|
-
mimeTypes: ["image/jpeg", "image/png", "image/gif", "image/svg+xml", "image/webp"]
|
|
833
|
+
mimeTypes: ["image/jpeg", "image/png", "image/gif", "image/svg+xml", "image/webp", "image/avif"],
|
|
834
|
+
extensions: IMAGE_EXTENSIONS
|
|
829
835
|
},
|
|
830
836
|
document: {
|
|
831
837
|
mimeTypes: [
|
|
@@ -837,7 +843,8 @@ var UPLOAD_LIMITS = {
|
|
|
837
843
|
"text/plain",
|
|
838
844
|
"text/markdown",
|
|
839
845
|
"application/octet-stream"
|
|
840
|
-
]
|
|
846
|
+
],
|
|
847
|
+
extensions: [".pdf", ".doc", ".docx", ".odt", ".rtf", ".txt", ".md"]
|
|
841
848
|
},
|
|
842
849
|
media: {
|
|
843
850
|
mimeTypes: [
|
|
@@ -856,7 +863,8 @@ var UPLOAD_LIMITS = {
|
|
|
856
863
|
"audio/webm",
|
|
857
864
|
"audio/flac",
|
|
858
865
|
"application/pdf"
|
|
859
|
-
]
|
|
866
|
+
],
|
|
867
|
+
extensions: [...IMAGE_EXTENSIONS, ".mp4", ".webm", ".ogv", ".ogg", ".mp3", ".wav", ".flac", ".pdf"]
|
|
860
868
|
}
|
|
861
869
|
};
|
|
862
870
|
function formatFileSize(bytes) {
|
|
@@ -868,6 +876,21 @@ function uploadSizeError(file, kind = "image") {
|
|
|
868
876
|
const noun = kind === "image" ? "image" : "file";
|
|
869
877
|
return `That ${noun} is ${formatFileSize(file.size)}. Please choose one under ${formatFileSize(MAX_UPLOAD_BYTES)}.`;
|
|
870
878
|
}
|
|
879
|
+
function acceptFor(kind) {
|
|
880
|
+
const { mimeTypes, extensions } = UPLOAD_LIMITS[kind];
|
|
881
|
+
return [...mimeTypes, ...extensions].join(",");
|
|
882
|
+
}
|
|
883
|
+
function typeList(extensions) {
|
|
884
|
+
const names = extensions.map((ext) => ext.slice(1).toUpperCase());
|
|
885
|
+
return names.length > 1 ? `${names.slice(0, -1).join(", ")} or ${names[names.length - 1]}` : names.join("");
|
|
886
|
+
}
|
|
887
|
+
function uploadError(file, kind = "image") {
|
|
888
|
+
const { mimeTypes, extensions } = UPLOAD_LIMITS[kind];
|
|
889
|
+
const name = (file.name ?? "").toLowerCase();
|
|
890
|
+
const allowed = mimeTypes.includes(file.type) || file.type === "" && extensions.some((ext) => name.endsWith(ext));
|
|
891
|
+
if (!allowed) return `Choose ${kind === "image" ? "an image" : "a file"} in ${typeList(extensions)}.`;
|
|
892
|
+
return uploadSizeError(file, kind);
|
|
893
|
+
}
|
|
871
894
|
|
|
872
895
|
Object.defineProperty(exports, "ApiClient", {
|
|
873
896
|
enumerable: true,
|
|
@@ -1182,6 +1205,7 @@ exports.OPEN_LICENSES = OPEN_LICENSES;
|
|
|
1182
1205
|
exports.RESERVED_TRAITS = RESERVED_TRAITS;
|
|
1183
1206
|
exports.RunRequestError = RunRequestError;
|
|
1184
1207
|
exports.UPLOAD_LIMITS = UPLOAD_LIMITS;
|
|
1208
|
+
exports.acceptFor = acceptFor;
|
|
1185
1209
|
exports.buildAssetMetadata = buildAssetMetadata;
|
|
1186
1210
|
exports.buildCollectionMetadata = buildCollectionMetadata;
|
|
1187
1211
|
exports.createAppGateway = createAppGateway;
|
|
@@ -1205,6 +1229,7 @@ exports.readBodyWithCap = readBodyWithCap;
|
|
|
1205
1229
|
exports.resolveRemixPolicy = resolveRemixPolicy;
|
|
1206
1230
|
exports.resolveSafeImageContentType = resolveSafeImageContentType;
|
|
1207
1231
|
exports.uploadDirectoryToBackend = uploadDirectoryToBackend;
|
|
1232
|
+
exports.uploadError = uploadError;
|
|
1208
1233
|
exports.uploadFileToBackend = uploadFileToBackend;
|
|
1209
1234
|
exports.uploadJsonToBackend = uploadJsonToBackend;
|
|
1210
1235
|
exports.uploadSizeError = uploadSizeError;
|