2016-11-24 15:47:41 -05:00
|
|
|
/*eslint no-unused-vars: "off"*/
|
2016-01-28 10:58:12 -08:00
|
|
|
// Files Adapter
|
|
|
|
|
//
|
|
|
|
|
// Allows you to change the file storage mechanism.
|
|
|
|
|
//
|
|
|
|
|
// Adapter classes must implement the following functions:
|
2017-09-09 13:11:16 -04:00
|
|
|
// * createFile(filename, data, contentType)
|
|
|
|
|
// * deleteFile(filename)
|
|
|
|
|
// * getFileData(filename)
|
|
|
|
|
// * getFileLocation(config, filename)
|
2016-01-28 10:58:12 -08:00
|
|
|
//
|
|
|
|
|
// Default is GridStoreAdapter, which requires mongo
|
2016-02-27 02:02:33 -08:00
|
|
|
// and for the API server to be using the DatabaseController with Mongo
|
2016-01-28 10:58:12 -08:00
|
|
|
// database adapter.
|
|
|
|
|
|
2017-09-09 13:11:16 -04:00
|
|
|
import type { Config } from '../../Config'
|
2018-08-10 15:51:31 -04:00
|
|
|
/**
|
|
|
|
|
* @module Adapters
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* @interface FilesAdapter
|
|
|
|
|
*/
|
2016-02-08 22:51:58 -08:00
|
|
|
export class FilesAdapter {
|
2017-09-09 13:11:16 -04:00
|
|
|
|
2018-08-10 15:51:31 -04:00
|
|
|
/** Responsible for storing the file in order to be retrieved later by its filename
|
2016-03-23 23:29:16 -04:00
|
|
|
*
|
2017-09-09 13:11:16 -04:00
|
|
|
* @param {string} filename - the filename to save
|
|
|
|
|
* @param {*} data - the buffer of data from the file
|
|
|
|
|
* @param {string} contentType - the supposed contentType
|
2016-03-23 23:29:16 -04:00
|
|
|
* @discussion the contentType can be undefined if the controller was not able to determine it
|
|
|
|
|
*
|
2017-09-09 13:11:16 -04:00
|
|
|
* @return {Promise} a promise that should fail if the storage didn't succeed
|
2016-03-01 15:45:11 -05:00
|
|
|
*/
|
2017-09-09 13:11:16 -04:00
|
|
|
createFile(filename: string, data, contentType: string): Promise { }
|
2016-02-08 22:51:58 -08:00
|
|
|
|
2018-08-10 15:51:31 -04:00
|
|
|
/** Responsible for deleting the specified file
|
2017-09-09 13:11:16 -04:00
|
|
|
*
|
|
|
|
|
* @param {string} filename - the filename to delete
|
|
|
|
|
*
|
|
|
|
|
* @return {Promise} a promise that should fail if the deletion didn't succeed
|
|
|
|
|
*/
|
|
|
|
|
deleteFile(filename: string): Promise { }
|
2016-02-10 18:42:21 -05:00
|
|
|
|
2018-08-10 15:51:31 -04:00
|
|
|
/** Responsible for retrieving the data of the specified file
|
2017-09-09 13:11:16 -04:00
|
|
|
*
|
|
|
|
|
* @param {string} filename - the name of file to retrieve
|
|
|
|
|
*
|
|
|
|
|
* @return {Promise} a promise that should pass with the file data or fail on error
|
|
|
|
|
*/
|
|
|
|
|
getFileData(filename: string): Promise<any> { }
|
2016-02-08 22:51:58 -08:00
|
|
|
|
2018-08-10 15:51:31 -04:00
|
|
|
/** Returns an absolute URL where the file can be accessed
|
2017-09-09 13:11:16 -04:00
|
|
|
*
|
|
|
|
|
* @param {Config} config - server configuration
|
|
|
|
|
* @param {string} filename
|
|
|
|
|
*
|
|
|
|
|
* @return {string} Absolute URL
|
|
|
|
|
*/
|
|
|
|
|
getFileLocation(config: Config, filename: string): string { }
|
2016-02-08 22:51:58 -08:00
|
|
|
}
|
2016-02-09 12:53:02 -08:00
|
|
|
|
|
|
|
|
export default FilesAdapter;
|