Skip to content

Commit d7e1489

Browse files
speedywizardStanislav Kolotinskiyhemanth-3gary-singh-filestack
authored andcommitted
FS-8673 Add alt text to images (#550)
* FS-8673 Add alt text to images * updated the branch name * Fix failing spec * Switch picker version to beta * update build branch * add log * update picker version * update version to beta * add log * add alt to response interface * cleanup and final commit * clean up * Add useNewTransformer * Update README.md --------- Co-authored-by: Stanislav Kolotinskiy <stanislav@assembla.com> Co-authored-by: hemanth-3 <98961835+hemanth-3@users.noreply.github.com> Co-authored-by: gary-singh-filestack <gary.singh@filestack.com>
1 parent d331452 commit d7e1489

File tree

11 files changed

+54
-7
lines changed

11 files changed

+54
-7
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ If you're using [Sentry](https://sentry.io/welcome/) to monitor your application
237237
## Versioning
238238

239239
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags](https://github.com/filestack/filestack-js/tags) on this repository.
240-
241240
## Contributing
242241

243242
We follow the [conventional commits](https://conventionalcommits.org/) specification to ensure consistent commit messages and changelog formatting.

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* @private
2020
*/
21-
const PICKER_VERSION = '1.27.3';
21+
const PICKER_VERSION = 'beta';
2222

2323
/**
2424
* @private

src/lib/api/upload/file.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ export class File {
7979

8080
public uploadTags: UploadTags;
8181

82+
public alt: string;
83+
8284
constructor(private readonly _file: FileInstance, private readonly _sanitizeOptions?: SanitizeOptions) {
8385
this._file.name = sanitizeName(this._file.name, this._sanitizeOptions);
8486
}

src/lib/api/upload/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export interface UploadOptions {
8181
* @memberof UploadOptions
8282
*/
8383
tags?: UploadTags;
84+
85+
altText?: string;
8486
}
8587

8688
export type StoreUploadOptions = StoreBaseParams & {

src/lib/api/upload/upload.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,18 @@ export class Upload extends EventEmitter {
199199
* Upload single file
200200
*
201201
* @param {(InputFile)} file
202+
* @param {(string)} altText
202203
* @returns {Promise<any>}
203204
* @memberof Upload
204205
*/
205-
async upload(input: InputFile): Promise<any> {
206+
async upload(input: InputFile, altText?: string): Promise<any> {
206207

207208
const f = await getFile(input, this.sanitizerOptions);
208209
f.customName = this.overrideFileName;
210+
if (altText) {
211+
f.alt = altText;
212+
}
213+
209214
this.uploader.addFile(f);
210215

211216
this.startProgressInterval();

src/lib/api/upload/uploaders/s3.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export class S3Uploader extends UploaderAbstract {
212212
location_url: payload.location_url,
213213
upload_id: payload.upload_id,
214214
region: payload.region,
215+
alt: payload.file.alt,
215216
};
216217

217218
if (this.uploadMode === UploadMode.INTELLIGENT || (this.uploadMode === UploadMode.FALLBACK && fiiFallback)) {
@@ -687,7 +688,7 @@ export class S3Uploader extends UploaderAbstract {
687688
return FsRequest.post(
688689
`${this.getUploadUrl(id)}/multipart/complete`,
689690
{
690-
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii'], true),
691+
...this.getDefaultFields(id, ['apikey', 'policy', 'signature', 'uri', 'region', 'upload_id', 'fii', 'alt'], true),
691692
// method specific keys
692693
filename: payload.file.name,
693694
mimetype: payload.file.type,

src/lib/client.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,30 @@ describe('client', () => {
210210

211211
expect(Upload.prototype.setToken).toHaveBeenCalledWith(token);
212212
expect(Upload.prototype.setSecurity).toHaveBeenCalledWith(defaultSecurity);
213-
expect(Upload.prototype.upload).toHaveBeenCalledWith(file);
213+
expect(Upload.prototype.upload).toHaveBeenCalledWith(file, undefined);
214+
});
215+
216+
it('should be able to upload file with alt text', async () => {
217+
const client = new Client(defaultApikey);
218+
const file = 'anyFile';
219+
const uploadOptions = {
220+
altText: 'alt',
221+
};
222+
const storeOptions = {};
223+
const token = {};
224+
225+
jest.spyOn(Upload.prototype, 'upload').mockImplementation(() => Promise.resolve());
226+
227+
await client.upload(file, uploadOptions, storeOptions, token, defaultSecurity);
228+
229+
expect(Upload.prototype.setSession).toHaveBeenCalledWith({
230+
apikey: defaultApikey,
231+
urls: sessionURls,
232+
});
233+
234+
expect(Upload.prototype.setToken).toHaveBeenCalledWith(token);
235+
expect(Upload.prototype.setSecurity).toHaveBeenCalledWith(defaultSecurity);
236+
expect(Upload.prototype.upload).toHaveBeenCalledWith(file, uploadOptions.altText);
214237
});
215238

216239
it('should be able to upload file without token and security', async () => {
@@ -228,7 +251,7 @@ describe('client', () => {
228251
urls: sessionURls,
229252
});
230253

231-
expect(Upload.prototype.upload).toHaveBeenCalledWith(file);
254+
expect(Upload.prototype.upload).toHaveBeenCalledWith(file, undefined);
232255
});
233256

234257
it('should emit error', async () => {

src/lib/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export class Client extends EventEmitter {
475475
this.emit('upload.error', e);
476476
});
477477

478-
return upload.upload(file);
478+
return upload.upload(file, options.altText);
479479
}
480480

481481
/**

src/lib/picker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export interface PickerFileMetadata {
155155
* The Filestack CDN URL for the uploaded file.
156156
*/
157157
url: string;
158+
/**
159+
* Alt text for images
160+
*/
161+
alt: string;
158162
}
159163

160164
export interface CustomAuthTextOptions {
@@ -683,6 +687,10 @@ export interface PickerOptions {
683687
* Specify options for images passed to the crop UI.
684688
*/
685689
transformations?: PickerTransformationOptions;
690+
/**
691+
* Whether to use the new transformations UI. Defaults to `false`.
692+
*/
693+
useNewTransformer?: boolean;
686694
/**
687695
* Options for local file uploads.
688696
*/

src/schema/picker.schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ export const PickerParamsSchema = {
439439
useSentryBreadcrumbs: {
440440
type: 'boolean',
441441
},
442+
useNewTransformer: {
443+
type: 'boolean',
444+
},
442445
pasteMode: {
443446
type: 'object',
444447
additionalProperties: false,

0 commit comments

Comments
 (0)