Skip to content

Commit

Permalink
fix: handle optional byFile endpoint and improve type safety in uploader
Browse files Browse the repository at this point in the history
- Add null coalescing for byFile endpoint URL
- Improve type casting for additional request data
- Ensure type safety when appending form data
  • Loading branch information
amriksingh0786 committed Feb 14, 2025
1 parent d4ac8e5 commit b332040
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/uploader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ajax from '@codexteam/ajax';
import ajax from "@codexteam/ajax";
import type { AjaxResponse } from "@codexteam/ajax";
import isPromise from "./utils/isPromise";
import type { UploadOptions } from "./types/types";
Expand Down Expand Up @@ -98,7 +98,7 @@ export default class Uploader {
} else {
upload = ajax
.transport({
url: this.config.endpoints.byFile,
url: this.config.endpoints.byFile ?? "",
data: this.config.additionalRequestData,
accept: this.config.types ?? "image/*",
headers: this.config.additionalRequestHeaders as Record<
Expand Down Expand Up @@ -229,15 +229,15 @@ export default class Uploader {
Object.keys(this.config.additionalRequestData).length
) {
Object.entries(this.config.additionalRequestData).forEach(
([name, value]: [string, string | Blob]) => {
formData.append(name, value);
([name, value]) => {
formData.append(name, value as string | Blob);
}
);
}

upload = ajax
.post({
url: this.config.endpoints.byFile,
url: this.config.endpoints.byFile ?? "",
data: formData,
type: ajax.contentType.JSON,
headers: this.config.additionalRequestHeaders as Record<
Expand Down

0 comments on commit b332040

Please sign in to comment.