Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adonis-kraken

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis-kraken - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

2

package.json
{
"name": "adonis-kraken",
"version": "0.0.11",
"version": "0.0.12",
"description": "Simplifies working with Kraken.io (image optimisation service) through Adonis",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,5 +14,16 @@ 'use strict'

this.options = inputConfig.merge('kraken', Config.get('kraken'))
this.auth = {
api_key: this.options.api_key || '',
api_secret: this.options.api_secret || ''
}
/**
* Attaches authentication data to request body
*
* @param {Object} body
*/
_attachAuth (body = {}) {
body = {
auth: {
api_key: this.options.api_key || '',
api_secret: this.options.api_secret || ''
},
...body
}

@@ -22,2 +33,29 @@ }

/**
* Gets an streamable instance of a file
*
* @param {*} file
*/
_getStreamedFile (file) {
return (file && file instanceof stream.Stream) ? file : fs.createReadStream(file)
}
/**
* Gets the filename from a streamed file
*
* @param {Stream} file
*/
_getFileName (file) {
return file.filename || 'file'
}
/**
* Gets the auto-generated headers from a form
*
* @param {FormData} form
*/
_getFormHeaders (form) {
return { headers: form.getHeaders() }
}
/**
* Rounds bytes to nearest KB, MB, GB etc

@@ -44,5 +82,3 @@ *

try {
body.auth = this.auth
const { data } = await axios.post('https://api.kraken.io/v1/url', body)
return data
return axios.post('https://api.kraken.io/v1/url', this._attachAuth(body))
} catch (error) {

@@ -57,19 +93,15 @@ console.log(error)

*
* @param {Object} opts
* @param {Object} body
*/
async upload (opts = {}) {
opts.auth = this.auth
let form = new FormData()
form.append('file', (opts.file && opts.file instanceof stream.Stream)
? opts.file
: fs.createReadStream(opts.file)
)
delete opts.file
form.append('data', JSON.stringify(opts))
return axios.post('https://api.kraken.io/v1/upload', form, { headers: form.getHeaders() })
.then((response) => response)
.catch((error) => {
console.log(error)
return error
})
async upload (body = {}) {
try {
let form = new FormData()
form.append('file', this._getStreamedFile(body.file), this._getFileName(this._getStreamedFile(body.file)))
delete body.file
form.append('data', JSON.stringify(this._attachAuth(body)))
return axios.post('https://api.kraken.io/v1/upload', form, this._getFormHeaders(form))
} catch (error) {
console.log(error)
return error
}
}

@@ -76,0 +108,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc