@inline-chat/realtime-sdk 0.0.5 → 0.0.6
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.
|
@@ -195,11 +195,11 @@ export class InlineSdkClient {
|
|
|
195
195
|
form.set("type", params.type);
|
|
196
196
|
const fileName = normalizeUploadFileName(params.fileName, params.type);
|
|
197
197
|
const fileContentType = resolveUploadContentType(params.type, params.contentType);
|
|
198
|
-
form.set("file",
|
|
198
|
+
form.set("file", toUploadMultipartFile(params.file, fileName, fileContentType), fileName);
|
|
199
199
|
if (params.thumbnail != null) {
|
|
200
200
|
const thumbnailName = normalizeUploadFileName(params.thumbnailFileName, "photo");
|
|
201
201
|
const thumbnailContentType = resolveUploadContentType("photo", params.thumbnailContentType);
|
|
202
|
-
form.set("thumbnail",
|
|
202
|
+
form.set("thumbnail", toUploadMultipartFile(params.thumbnail, thumbnailName, thumbnailContentType), thumbnailName);
|
|
203
203
|
}
|
|
204
204
|
if (params.type === "video") {
|
|
205
205
|
const width = normalizePositiveInt(params.width, "width") ?? defaultVideoWidth;
|
|
@@ -653,7 +653,7 @@ function normalizeHttpBaseUrl(baseUrl) {
|
|
|
653
653
|
return url.toString().replace(/\/$/, "");
|
|
654
654
|
}
|
|
655
655
|
function normalizeUploadFileName(raw, type) {
|
|
656
|
-
const trimmed = raw
|
|
656
|
+
const trimmed = sanitizeUploadFileName(raw);
|
|
657
657
|
if (trimmed)
|
|
658
658
|
return trimmed;
|
|
659
659
|
switch (type) {
|
|
@@ -684,6 +684,21 @@ function toBlob(input, type) {
|
|
|
684
684
|
}
|
|
685
685
|
return new Blob([input], { type });
|
|
686
686
|
}
|
|
687
|
+
function toUploadMultipartFile(input, fileName, type) {
|
|
688
|
+
const blob = toBlob(input, type);
|
|
689
|
+
if (typeof File === "undefined")
|
|
690
|
+
return blob;
|
|
691
|
+
return new File([blob], fileName, { type });
|
|
692
|
+
}
|
|
693
|
+
function sanitizeUploadFileName(raw) {
|
|
694
|
+
const trimmed = raw?.trim();
|
|
695
|
+
if (!trimmed)
|
|
696
|
+
return "";
|
|
697
|
+
const normalized = trimmed.replace(/\\/g, "/");
|
|
698
|
+
const leaf = normalized.split("/").pop() ?? normalized;
|
|
699
|
+
const noQuery = leaf.split(/[?#]/, 1)[0] ?? leaf;
|
|
700
|
+
return noQuery.trim();
|
|
701
|
+
}
|
|
687
702
|
function normalizePositiveInt(value, field) {
|
|
688
703
|
if (value == null)
|
|
689
704
|
return undefined;
|