/**
* @module flitter-upload/store/Store
*/
const { Injectable } = require('flitter-di')
const ImplementationError = require('libflitter/errors/ImplementationError')
/**
* Abstract class representing a backend for storing and
* retrieving uploaded files.
* @abstract
* @extends module:flitter-di/src/Injectable~Injectable
*/
class Store extends Injectable {
/**
* The configuration for this store.
* @type {object}
*/
config = {}
/**
* Instantiate the store.
* @param {object} config - the store's configuration
*/
constructor(config) {
super()
this.config = config
}
/**
* Initializes the store. Called once when the application is started.
* This is where any logic required to connect to, prepare, or guarantee
* the store is ready to use should occur.
* @returns {Promise<void>}
*/
async init() { }
/**
* Permanently store a temporarily uploaded file in this store.
* @param {object} params
* @param {string} params.temp_path - absolute path to the temporarily uploaded file
* @param {string} params.original_name - the original upload name of the file
* @param {string} params.mime_type - the MIME type of the file.
* @abstract
* @returns {Promise<module:flitter-upload/model/File~File>}
*/
async store({ temp_path, original_name, mime_type }) {
throw new ImplementationError()
}
/**
* Send the specified file as the data for the response.
* This should set the appropriate Content-Type and Content-Disposition headers.
* @param {module:flitter-upload/model/File~File} file - the file to send
* @param {express/response} response - the response
* @abstract
* @returns {Promise<void>}
*/
async send_file(file, response) {
throw new ImplementationError()
}
}
module.exports = exports = Store