@inline-chat/realtime-sdk 0.0.4 → 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;
|
|
@@ -209,7 +209,7 @@ export class InlineSdkClient {
|
|
|
209
209
|
form.set("height", String(height));
|
|
210
210
|
form.set("duration", String(duration));
|
|
211
211
|
}
|
|
212
|
-
const response = await this.fetchImpl(
|
|
212
|
+
const response = await this.fetchImpl(resolveUploadFileUrl(this.httpBaseUrl), {
|
|
213
213
|
method: "POST",
|
|
214
214
|
headers: {
|
|
215
215
|
authorization: `Bearer ${this.options.token}`,
|
|
@@ -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;
|
|
@@ -754,5 +769,11 @@ const resolveRealtimeUrl = (baseUrl) => {
|
|
|
754
769
|
url.pathname = url.pathname.replace(/\/+$/, "") + "/realtime";
|
|
755
770
|
return url.toString();
|
|
756
771
|
};
|
|
772
|
+
const resolveUploadFileUrl = (baseUrl) => {
|
|
773
|
+
const url = new URL(baseUrl);
|
|
774
|
+
const basePath = url.pathname.replace(/\/+$/, "");
|
|
775
|
+
url.pathname = `${basePath}/v1/uploadFile`;
|
|
776
|
+
return url;
|
|
777
|
+
};
|
|
757
778
|
const hasMethodMapping = (method) => Object.prototype.hasOwnProperty.call(rpcInputKindByMethod, method) &&
|
|
758
779
|
Object.prototype.hasOwnProperty.call(rpcResultKindByMethod, method);
|