Global

Methods

(static) module:grunt/copyTask(grunt) → {function}

Defines a grunt task to copy a file or a directory.

Parameters:
Name Type Description
grunt Object

Grunt instance

Source:
Returns:

Task function

Type
function
Example
// Register task
var openVeoApi = require('@openveo/api');
grunt.registerMultiTask('copy', openVeoApi.grunt.copyTask(grunt));

// Configure task
grunt.initConfig({
  copy: {
    copyDirectory: {
      src: 'directoryToCopy',
      dest: 'some/directory/'
    },
    copyFile: {
      src: 'fileToCopy.txt',
      dest: 'some/directory/'
    }
  }
});

(static) module:grunt/ngDpTask(grunt) → {function}

Defines a grunt task to build the list of sources (css and js) of an AngularJS application.

Parameters:
Name Type Description
grunt Object

Grunt instance

Source:
Returns:

Task function

Type
function
Example
// Register task
var openVeoApi = require('@openveo/api');
grunt.registerMultiTask('ngDp', openVeoApi.grunt.ngDpTask(grunt));

// Configure task
grunt.initConfig({
  'ngDp': {
    options: {
      basePath: '/path/to/the/',
      cssPrefix: '../../other/css/path/',
      jsPrefix: '../../other/js/path/'
    },
    app1: {
      src: '/path/to/the/app1/**\/*.*',
      dest: '/path/to/the/app1/topology.json'
    },
    app2: {
      src: '/path/to/the/app2**\/*.*',
      dest: '/path/to/the/app2/topology.json'
    }
  }
});

// Ouput example (/path/to/the/app1/topology.json)
{
  js: ['../..other/js/path/app1/file1.js', '../..other/js/path/app1/file2.js', [...]],
  css: ['../..other/css/path/app1/file1.css', '../..other/css/path/app1/file2.css', [...]]
}

AngularJS applications, which respect components architecture, need to be loaded in the right order as some
components may depend on other components. This task helps build an array of JavaScript files and css / scss files
in the right order.

For this to work, each module must be declared in a separated file and a single file should not define AngularJS
elements belonging to several different modules.

Available options are:
  - basePath: The base path which will be replaced by the cssPrefix or jsPrefix
  - cssPrefix: For CSS / SCSS files, replace the basePath by this prefix
  - jsPrefix: For JS files, replace the basePath by this prefix

(static) module:grunt/removeTask(grunt) → {function}

Defines a grunt task to remove a file or a directory.

Parameters:
Name Type Description
grunt Object

Grunt instance

Source:
Returns:

Task function

Type
function
Example
// Register task
var openVeoApi = require('@openveo/api');
grunt.registerMultiTask('remove', openVeoApi.grunt.removeTask(grunt));

// Configure task
grunt.initConfig({
  removeTask: {
    removeDirectory: {
      src: 'directoryToRemove'
    },
    removeFile: {
      src: 'fileToRemove.txt'
    }
  }
});

(static) module:grunt/renameTask(grunt) → {function}

Defines a grunt task to rename a file or a directory.

Parameters:
Name Type Description
grunt Object

Grunt instance

Source:
Returns:

Task function

Type
function
Example
// Register task
var openVeoApi = require('@openveo/api');
grunt.registerMultiTask('rename', openVeoApi.grunt.renameTask(grunt));

// Configure task
grunt.initConfig({
  rename: {
    renameDirectory: {
      src: 'directoryToRename',
      dest: 'some/sub/directories/directoryRenamed'
    },
    renameFile: {
      src: 'fileToRename.txt',
      dest: 'some/sub/directories/fileRenamed.txt'
    }
  }
});

(static) module:middlewares/disableCacheMiddleware(request, response, next)

Defines an express middleware to deactivate user agent cache of requests.

  • Cache-Control : no-cache to force caches to request the original server
  • Cache-Control : no-store to force caches not to keep any copy of the response
  • Cache-Control : must-revalidate to force caches to ask original server validation of a stale response
  • Pragma : no-cache to be backward compatible with HTTP/1.0 caches
  • Expires : 0 to mark all responses as staled
Parameters:
Name Type Description
request Object

The Express.JS Request object

response Object

The Express.JS Response object

next Object

The Express.JS next function

Source:
Example
var openVeoApi = require('@openveo/api');
expressApp.use(openVeoApi.middlewares.disableCacheMiddleware);

(static) module:middlewares/imageProcessorMiddleware(imagesDirectory, cacheDirectory, styles, headers) → {function}

Defines an expressJS middleware to process images.

If path corresponds to an image with a parameter "style", the style is applied to the image before returning it to the client. Actually only one type of manipulation can be applied to an image: generate a thumbnail. If path does not correspond to an image the processor is skipped.

Parameters:
Name Type Description
imagesDirectory String

The path of the directory containing the images to process

cacheDirectory String

The path of the directory containing already processed images (for cache purpose)

styles Array

The list of available styles to process images with for each style:

Properties
Name Type Description
id String

Id of the style to apply when requesting an image processing

width String

Expected width of the image (in px) (default to 10)

quality String

Expected quality from 0 to 100 (default to 90 with 100 the best)

headers Object

The name / value list of headers to send with the image when responding to the client

Source:
Throws:

If imagesdirectory or styles is empty

Type
TypeError
Returns:

The ExpressJS middleware

Type
function
Example
var openVeoApi = require('@openveo/api');
expressApp.use('/mount-path', openVeoApi.middlewares.imageProcessorMiddleware(
  '/path/to/the/folder/containing/images'
  '/path/to/the/folder/containing/processed/images/cache'
  [
    {
      id: 'my-thumb', // Id of the style to apply when requesting an image processing
      width: 200, // Expected width (in px) of the image
      quality: 50 // Expected quality from 0 to 100 (default to 90 with 100 the best)
    }
  ]
));

// Then it's possible to apply style "my-thumb" to the image /mount-path/my-image.jpg using
// parameter "style": /mount-path/my-image.jpg?style=my-thumb

(static) module:middlewares/logRequestMiddleware(request, response, next)

Defines an expressJS middleware to log request's information (header, method, path).

Parameters:
Name Type Description
request Object

The Express.JS Request object

response Object

The Express.JS Response object

next Object

The Express.JS next function

Source:
Example
var openVeoApi = require('@openveo/api');
expressApp.use(openVeoApi.middlewares.logRequestMiddleware);

Type Definitions

callback(error)

Parameters:
Name Type Description
error Error | undefined

The error if an error occurred

Source: