Skip to content

Commit

Permalink
update: some parameters are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dependentmadani committed Jul 17, 2024
1 parent 30294cc commit f491ecd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export default class ImageTool implements BlockTool {
endpoints: config.endpoints,
additionalRequestData: config.additionalRequestData,
additionalRequestHeaders: config.additionalRequestHeaders,
field: config.field || 'image',
types: config.types || 'image/*',
field: config.field,
types: config.types,
captionPlaceholder: this.api.i18n.t(config.captionPlaceholder ? config.captionPlaceholder: 'Caption'),
buttonContent: config.buttonContent,
uploader: config.uploader,
Expand Down
4 changes: 2 additions & 2 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ export interface ImageConfig {
/**
* Field name for the uploaded image.
*/
field: string;
field?: string;

/**
* Allowed mime-types for the uploaded image.
*/
types: string;
types?: string;

/**
* Placeholder text for the caption field.
Expand Down
8 changes: 4 additions & 4 deletions src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class Uploader {
// custom uploading
if (this.config.uploader && typeof this.config.uploader.uploadByFile === 'function') {
const uploadByFile = this.config.uploader.uploadByFile;
upload = ajax.selectFiles({ accept: this.config.types}).then((files: File[]) => {
upload = ajax.selectFiles({ accept: this.config.types || 'image/*'}).then((files: File[]) => {
preparePreview(files[0]);

const customUpload = uploadByFile(files[0]);
Expand All @@ -89,12 +89,12 @@ export default class Uploader {
upload = ajax.transport({
url: this.config.endpoints.byFile,
data: this.config.additionalRequestData,
accept: this.config.types,
accept: this.config.types || 'image/*',
headers: new Headers(this.config.additionalRequestHeaders as Record<string, string>),
beforeSend: (files: File[]) => {
preparePreview(files[0]);
},
fieldName: this.config.field,
fieldName: this.config.field || 'image',
}).then((response: any) => response.body);
}

Expand Down Expand Up @@ -181,7 +181,7 @@ export default class Uploader {
*/
const formData = new FormData();

formData.append(this.config.field, file);
formData.append(this.config.field || 'image', file);

if (this.config.additionalRequestData && Object.keys(this.config.additionalRequestData).length) {
Object.entries(this.config.additionalRequestData).forEach(([name, value]: [string, any]) => {
Expand Down

0 comments on commit f491ecd

Please sign in to comment.