Skip to content

Commit

Permalink
feat(transforms): Add animate transformation (#274)
Browse files Browse the repository at this point in the history
* feat(transforms): Add animate transformation

* fix(transforms): fix animate params
  • Loading branch information
pcholuj authored Aug 23, 2019
1 parent 32afd54 commit 3a82f02
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
17 changes: 16 additions & 1 deletion src/lib/filelink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Filelink, ShapeType, VideoAccessMode } from './filelink';
import { Filelink, ShapeType, VideoAccessMode, AnimationParams, FitOptions, Align } from './filelink';
import { TransformSchema } from './../schema/transforms.schema';
import * as validator from '../schema';

Expand Down Expand Up @@ -257,6 +257,21 @@ describe('filelink', () => {
expect(filelink.toString()).toBe('https://customDomain.com/DEFAULT_API_KEY/cache=expiry:666/5aYkEQJSQCmYShsoCnZN');
});

it('should be able add animation transform', () => {
const params: AnimationParams = {
loop: 1,
delay: 10,
width: 10,
height: 10,
fit: FitOptions.scale,
background: 'transparent',
align: [Align.top, Align.center],
};

filelink.animate(params);
expect(filelink.toString()).toBe('https://customDomain.com/DEFAULT_API_KEY/animate=loop:1,delay:10,width:10,height:10,fit:scale,background:transparent,align:[top,center]/5aYkEQJSQCmYShsoCnZN');
});

it('should be able to resize', () => {
const resizeParams = {
width: 200,
Expand Down
43 changes: 29 additions & 14 deletions src/lib/filelink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,21 @@ import { FilestackError, FilestackErrorType } from './../filestack_error';
import Debug from 'debug';

const debug = Debug('fs:filelink');
/**
* Align enum
*/
export enum AlignOptions {

export enum Align {
left = 'left',
right = 'right',
center = 'center',
bottom = 'bottom',
top = 'top',
faces = 'faces',
middle = 'middle',
}

/**
* Align enum with faces option
* Align
*/
export enum AlignFacesOptions {
left = 'left',
right = 'right',
center = 'center',
bottom = 'bottom',
top = 'top',
faces = 'faces',
}
export type AlignOptions = Align | [Align.top | Align.middle | Align.bottom, Align.left | Align.center | Align.right];

/**
* Fit enum
Expand Down Expand Up @@ -184,11 +177,21 @@ export type StoreParams = StoreBaseParams & {
base64decode?: boolean;
};

export interface AnimationParams {
delay?: number;
loop?: number;
width?: number;
height?: number;
fit?: FitOptions;
align?: AlignOptions;
background?: string;
}

export interface ResizeParams {
width?: number;
height?: number;
fit?: FitOptions;
align?: AlignFacesOptions;
align?: AlignOptions;
}

export interface CropParams {
Expand Down Expand Up @@ -824,6 +827,18 @@ export class Filelink {
return this.addTask('sfw', true);
}

/**
* Add animate transformation
*
* @see https://www.filestack.com/docs/api/processing/#animate-images-to-gif
* @param params
* @returns this
* @memberof Filelink
*/
animate(params: AnimationParams) {
return this.addTask('animate', params);
}

/**
* Adds store transformation
*
Expand Down
4 changes: 3 additions & 1 deletion src/schema/definitions.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const DefinitionsSchema = {
pattern: '^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$', // without # at the begining
}, {
type: 'string',
enum: ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fractal', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray0', 'gray1', 'gray2', 'gray3', 'gray4', 'gray5', 'gray6', 'gray7', 'gray8', 'gray9', 'gray10', 'gray11', 'gray12', 'gray13', 'gray14', 'gray15', 'gray16', 'gray17', 'gray18', 'gray19', 'gray20', 'gray21', 'gray22', 'gray23', 'gray24', 'gray25', 'gray26', 'gray27', 'gray28', 'gray29', 'gray30', 'gray31', 'gray32', 'gray33', 'gray34', 'gray35', 'gray36', 'gray37', 'gray38', 'gray39', 'gray40', 'gray41', 'gray42', 'gray43', 'gray44', 'gray45', 'gray46', 'gray47', 'gray48', 'gray49', 'gray50', 'gray51', 'gray52', 'gray53', 'gray54', 'gray55', 'gray56', 'gray57', 'gray58', 'gray59', 'gray60', 'gray61', 'gray62', 'gray63', 'gray64', 'gray65', 'gray66', 'gray67', 'gray68', 'gray69', 'gray70', 'gray71', 'gray72', 'gray73', 'gray74', 'gray75', 'gray76', 'gray77', 'gray78', 'gray79', 'gray80', 'gray81', 'gray82', 'gray83', 'gray84', 'gray85', 'gray86', 'gray87', 'gray88', 'gray89', 'gray90', 'gray91', 'gray92', 'gray93', 'gray94', 'gray95', 'gray96', 'gray97', 'gray98', 'gray99', 'gray100', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'none', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen',],
enum: ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fractal', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray0', 'gray1', 'gray2', 'gray3', 'gray4', 'gray5', 'gray6', 'gray7', 'gray8', 'gray9', 'gray10', 'gray11', 'gray12', 'gray13', 'gray14', 'gray15', 'gray16', 'gray17', 'gray18', 'gray19', 'gray20', 'gray21', 'gray22', 'gray23', 'gray24', 'gray25', 'gray26', 'gray27', 'gray28', 'gray29', 'gray30', 'gray31', 'gray32', 'gray33', 'gray34', 'gray35', 'gray36', 'gray37', 'gray38', 'gray39', 'gray40', 'gray41', 'gray42', 'gray43', 'gray44', 'gray45', 'gray46', 'gray47', 'gray48', 'gray49', 'gray50', 'gray51', 'gray52', 'gray53', 'gray54', 'gray55', 'gray56', 'gray57', 'gray58', 'gray59', 'gray60', 'gray61', 'gray62', 'gray63', 'gray64', 'gray65', 'gray66', 'gray67', 'gray68', 'gray69', 'gray70', 'gray71', 'gray72', 'gray73', 'gray74', 'gray75', 'gray76', 'gray77', 'gray78', 'gray79', 'gray80', 'gray81', 'gray82', 'gray83', 'gray84', 'gray85', 'gray86', 'gray87', 'gray88', 'gray89', 'gray90', 'gray91', 'gray92', 'gray93', 'gray94', 'gray95', 'gray96', 'gray97', 'gray98', 'gray99', 'gray100', 'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'none', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen', 'transparent'],
}],
},
pageFormatDef: {
Expand Down Expand Up @@ -159,13 +159,15 @@ export const DefinitionsSchema = {
'left',
'center',
'right',
'faces',
],
},
{
type: 'array',
uniqueItems: true,
additionalItems: false,
minItems: 2,
maxItems: 2,
default: ['middle', 'center'],
items: [
{
Expand Down
42 changes: 41 additions & 1 deletion src/schema/transforms.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,53 @@ export const TransformSchema = {
type: 'boolean',
additionalProperties: false,
},
animate: {
type: 'object',
properties: {
delay: {
type: 'integer',
minimum: 0,
maximum: 10000,
default: 100,
},
loop: {
type: 'integer',
minimum: 0,
maximum: 1000,
default: 0,
},
width: {
type: 'integer',
minimum: 1,
maximum: 1800,
},
height: {
type: 'integer',
minimum: 1,
maximum: 1800,
},
fit: {
type: 'string',
default: 'clip',
enum: ['clip', 'scale', 'crop'],
},
background: {
'$ref': 'colorDef',
default: 'transparent',
},
align: {
'$ref': 'positionDef',
default: 'center',
},
},
},
metadata: {
type: 'object',
params: {
type: 'array',
items: {
type: 'string',
'enum': [
enum: [
'filename',
'mimetype',
'size',
Expand Down

0 comments on commit 3a82f02

Please sign in to comment.