-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
George Kemp
committed
Jun 19, 2020
0 parents
commit cc743cc
Showing
7 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[{package.json,*.yml}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
############################ | ||
# OS X | ||
############################ | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
Icon | ||
.Spotlight-V100 | ||
.Trashes | ||
._* | ||
|
||
|
||
############################ | ||
# Linux | ||
############################ | ||
|
||
*~ | ||
|
||
|
||
############################ | ||
# Windows | ||
############################ | ||
|
||
Thumbs.db | ||
ehthumbs.db | ||
Desktop.ini | ||
$RECYCLE.BIN/ | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
|
||
############################ | ||
# Packages | ||
############################ | ||
|
||
*.7z | ||
*.csv | ||
*.dat | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.seed | ||
*.so | ||
*.swo | ||
*.swp | ||
*.swn | ||
*.swm | ||
*.out | ||
*.pid | ||
|
||
|
||
############################ | ||
# Logs and databases | ||
############################ | ||
|
||
.tmp | ||
*.log | ||
*.sql | ||
*.sqlite | ||
|
||
|
||
############################ | ||
# Misc. | ||
############################ | ||
|
||
*# | ||
.idea | ||
nbproject | ||
|
||
|
||
############################ | ||
# Node.js | ||
############################ | ||
|
||
lib-cov | ||
lcov.info | ||
pids | ||
logs | ||
results | ||
build | ||
node_modules | ||
.node_history | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
############################ | ||
# OS X | ||
############################ | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
Icon | ||
.Spotlight-V100 | ||
.Trashes | ||
._* | ||
|
||
|
||
############################ | ||
# Linux | ||
############################ | ||
|
||
*~ | ||
|
||
|
||
############################ | ||
# Windows | ||
############################ | ||
|
||
Thumbs.db | ||
ehthumbs.db | ||
Desktop.ini | ||
$RECYCLE.BIN/ | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
|
||
############################ | ||
# Packages | ||
############################ | ||
|
||
*.7z | ||
*.csv | ||
*.dat | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.seed | ||
*.so | ||
*.swo | ||
*.swp | ||
*.swn | ||
*.swm | ||
*.out | ||
*.pid | ||
|
||
|
||
############################ | ||
# Logs and databases | ||
############################ | ||
|
||
.tmp | ||
*.log | ||
*.sql | ||
*.sqlite | ||
|
||
|
||
############################ | ||
# Misc. | ||
############################ | ||
|
||
*# | ||
ssl | ||
.editorconfig | ||
.gitattributes | ||
.idea | ||
nbproject | ||
|
||
|
||
############################ | ||
# Node.js | ||
############################ | ||
|
||
lib-cov | ||
lcov.info | ||
pids | ||
logs | ||
results | ||
build | ||
node_modules | ||
.node_history | ||
|
||
|
||
############################ | ||
# Tests | ||
############################ | ||
|
||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 George Kemp | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# strapi-provider-upload-hubspot | ||
|
||
## Description | ||
This provider is used to upload files from Strapi into the HubSpot File Manager. It currently requires api key authentication. Visit the HubSpot [Developer Documentation](https://legacydocs.hubspot.com/docs/methods/auth/oauth-overview) for steps to obtain your api key for your portal. | ||
|
||
## Configurations | ||
|
||
Your configuration is used to determine what portal and location in the file manager your files are uploaded to. | ||
|
||
See the [using a provider](https://strapi.io/documentation/v3.x/plugins/upload.html#using-a-provider) documentation for information on installing and using a provider. And see the [environment variables](https://strapi.io/documentation/v3.x/concepts/configurations.html#environment-variables) for setting and using environment variables in your configs. | ||
|
||
**Example** | ||
|
||
`./config/plugins.js` | ||
|
||
```js | ||
module.exports = ({ env }) => ({ | ||
// ... | ||
upload: { | ||
provider: "hubspot", | ||
providerOptions: { | ||
hapikey: env('HAPI_KEY'), | ||
root: env('FILE_MANAGER_ROOT_PATH') | ||
} | ||
}, | ||
// ... | ||
}); | ||
``` | ||
|
||
## Resources | ||
|
||
- [MIT License](LICENSE.md) | ||
|
||
## Links | ||
|
||
- [HubSpot website](https://hubspot.com/) | ||
- [HubSpot File Manager API Docs](https://legacydocs.hubspot.com/docs/methods/files/post_files) | ||
|
||
## Roadmap | ||
- [ ] Provide the Ability to Use OAuth Authentication | ||
- [ ] Add Testing | ||
- [ ] Upgrade to file manager api v2 when released |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use strict"; | ||
|
||
const axios = require("axios"); | ||
const FormData = require("form-data"); | ||
|
||
module.exports = { | ||
init(providerOptions) { | ||
const { root = "strapi", hapikey } = providerOptions; | ||
|
||
const hs = axios.create({ | ||
baseURL: "https://api.hubapi.com/filemanager/api/v2/files", | ||
}); | ||
|
||
hs.interceptors.request.use((config) => { | ||
config.params = config.params || {}; | ||
config.params.hapikey = hapikey; | ||
return config; | ||
}); | ||
|
||
return { | ||
upload: async (file, customParams = {}) => { | ||
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 { data } = await hs({ | ||
method: "post", | ||
params: { | ||
overwrite: true, | ||
}, | ||
headers: formData.getHeaders(), | ||
data: formData.getBuffer(), | ||
}); | ||
|
||
const uploadedFile = data.objects[0]; | ||
file.url = uploadedFile.friendly_url; | ||
file.provider_metadata = { | ||
id: uploadedFile.id, | ||
}; | ||
return; | ||
}, | ||
delete: async (file) => { | ||
const fileId = file.provider_metadata.id; | ||
await hs.delete(`/${fileId}`); | ||
return; | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "strapi-provider-upload-hubspot", | ||
"version": "1.0.1", | ||
"description": "HubSpot provider for strapi upload", | ||
"main": "./lib", | ||
"keywords": [ | ||
"hubspot", | ||
"filemanager", | ||
"strapi", | ||
"upload" | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"strapi": { | ||
"isProvider": true | ||
}, | ||
"author": { | ||
"email": "gkemp@hubspot.com", | ||
"name": "George Kemp" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^0.19.2", | ||
"form-data": "^3.0.0" | ||
} | ||
} |