- Source:
Methods
buildOperation(request, reply) → {Promise.<FlamingoOperation>}
Function that builds an operation for a given request.
Note: don't overwrite the buildOperation, if you don't know what you're doing.
It's the core convert method that calls other convert methods, used in other mixins.
Parameters:
Name | Type | Description |
---|---|---|
request |
ClientRequest | incoming http request |
reply |
function | hapi reply function |
- Source:
Returns:
Promise that resolves the build operation
- Type
- Promise.<FlamingoOperation>
extractInput(operation) → {Promise.<undefined>}
Function that resolves a url pointing to the input that should be converted
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
- Type
- Promise.<undefined>
extractProcess(operation) → {Promise.<{process: Array, response: {}}>}
Extract a processing instruction from a given operation.
The processing instruction can also expose data useful for the response writer.
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
- Type
- Promise.<{process: Array, response: {}}>
extractReader(input) → {Promise.<function()>}
Function that resolves a reader for the given input.
Rejects with InvalidInputError if no compatible reader is found.
Parameters:
Name | Type | Description |
---|---|---|
input |
Url |
- Source:
Returns:
reader
- Type
- Promise.<function()>
Example
(input) =>
Promise.resolve((operation) => ({stream: fs.createReadStream('path/to/image.png'), type: 'file'}))
handle(operation) → {Promise}
Overwrites the Routes handle function to start the conversation process
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
- See:
-
- flamingo/src/model/Route
Returns:
promise that contains the whole convert process
- Type
- Promise
preprocess(operation) → {function}
Function that preprocesses the reader result.
Can be used i.e. to transform a non image input to an image stream.
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
function that returns a promise which resolves an image stream
- Type
- function
Example
preprocess(operation) {
return (readerResult) => markdown2Image(operation.request.path.md);
}
process(operation) → {function}
Builds a function that takes a stream and transforms it.
This is the point where the incoming image stream is transformed.
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
- Type
- function
read(operation) → {function}
Builds a read function that reads a given operation.
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
- Type
- function
validOperation(operation) → {Promise.<FlamingoOperation>}
Resolves if the given operation is valid.
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
- Type
- Promise.<FlamingoOperation>
Example
validOperation(operation) => operation.input.protocol ?
Promise.resolve(operation) :
Promise.reject(new InvalidInputError('target has no protocol'))
validStream(operation) → {function}
Builds a validation function that resolves if the given stream is valid
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
- Type
- function
write(operation) → {function}
Builds a function that takes a stream and writes it somewhere.
Parameters:
Name | Type | Description |
---|---|---|
operation |
FlamingoOperation |
- Source:
Returns:
- Type
- function