Skip to content

Commit

Permalink
FS-8673 Add alt text to images
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Kolotinskiy committed Feb 5, 2024
1 parent f2cb04a commit ef373ee
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/lib/api/upload/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class File {

public uploadTags: UploadTags;

public alt: string;

constructor(private readonly _file: FileInstance, private readonly _sanitizeOptions?: SanitizeOptions) {
this._file.name = sanitizeName(this._file.name, this._sanitizeOptions);
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/api/upload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export interface UploadOptions {
* @memberof UploadOptions
*/
tags?: UploadTags;

altText?: string;
}

export type StoreUploadOptions = StoreBaseParams & {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/api/upload/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ export class Upload extends EventEmitter {
* Upload single file
*
* @param {(InputFile)} file
* @param {(string)} altText
* @returns {Promise<any>}
* @memberof Upload
*/
async upload(input: InputFile): Promise<any> {
async upload(input: InputFile, altText?: string): Promise<any> {

const f = await getFile(input, this.sanitizerOptions);
f.customName = this.overrideFileName;
if (altText) {
f.alt = altText;
}

this.uploader.addFile(f);

this.startProgressInterval();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/api/upload/uploaders/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export class S3Uploader extends UploaderAbstract {
location_url: payload.location_url,
upload_id: payload.upload_id,
region: payload.region,
alt: payload.file.alt,
};

if (this.uploadMode === UploadMode.INTELLIGENT || (this.uploadMode === UploadMode.FALLBACK && fiiFallback)) {
Expand Down Expand Up @@ -687,7 +688,7 @@ export class S3Uploader extends UploaderAbstract {
return FsRequest.post(
`${this.getUploadUrl(id)}/multipart/complete`,
{
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii'], true),
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii', 'alt'], true),
// method specific keys
filename: payload.file.name,
mimetype: payload.file.type,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export class Client extends EventEmitter {
this.emit('upload.error', e);
});

return upload.upload(file);
return upload.upload(file, options.altText);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/schema/upload.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ export const UploadParamsSchema = {
maxlength: 256,
},
},
altText: {
type: ['string', 'null'],
maxLength: 60,
},
},
};

0 comments on commit ef373ee

Please sign in to comment.