Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/upgrade to api v3 #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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 = {
darkmavis1980 marked this conversation as resolved.
Show resolved Hide resolved
access: 'PUBLIC_NOT_INDEXABLE',
overwrite: true,
...customParams,
darkmavis1980 marked this conversation as resolved.
Show resolved Hide resolved
}

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(),
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -24,7 +24,7 @@
},
"license": "MIT",
"dependencies": {
"axios": "^0.19.2",
"axios": "^0.21.1",
"form-data": "^3.0.0"
}
}