diff --git a/lib/index.js b/lib/index.js index 8c41c79..a99f405 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,14 +1,14 @@ -"use strict"; +'use strict'; -const axios = require("axios"); -const FormData = require("form-data"); +const axios = require('axios'); +const FormData = require('form-data'); module.exports = { init(providerOptions) { - const { root = "strapi", hapikey } = providerOptions; + const { root = 'strapi', hapikey } = providerOptions; const hs = axios.create({ - baseURL: "https://api.hubapi.com/filemanager/api/v2/files", + baseURL: 'https://api.hubapi.com/filemanager/api/v3/files/upload', }); hs.interceptors.request.use((config) => { @@ -19,21 +19,27 @@ module.exports = { return { upload: async (file, customParams = {}) => { - const path = file.path ? `${file.path}/` : ""; + const path = file.path ? `${file.path}/` : ''; const formData = new FormData(); - - formData.append("files", file.buffer, { - filename: file.hash, - contentType: file.mime, - }); - formData.append("files_names", file.hash); - formData.append("folder_paths", `${root}/${path}`); + const { + buffer, + hash, + mime, + } = file; + + const options = { + access: 'PUBLIC_NOT_INDEXABLE', + overwrite: true, + ...customParams, + } + + formData.append('options', JSON.stringify(options)); + formData.append('file', buffer, { filename: hash, contentType: mime }); + formData.append('fileName', hash); + formData.append('folderPath', `${root}/${path}`); const { data } = await hs({ - method: "post", - params: { - overwrite: true, - }, + method: 'post', headers: formData.getHeaders(), data: formData.getBuffer(), }); diff --git a/package.json b/package.json index 590c834..a958f5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "strapi-provider-upload-hubspot", - "version": "1.0.1", + "version": "2.0.0", "description": "HubSpot provider for strapi upload", "main": "./lib", "keywords": [ @@ -24,7 +24,7 @@ }, "license": "MIT", "dependencies": { - "axios": "^0.19.2", + "axios": "^0.21.1", "form-data": "^3.0.0" } }