diff --git a/packages/strapi-upload-cloudinary/.editorconfig b/packages/strapi-upload-cloudinary/.editorconfig new file mode 100755 index 0000000000..d4eed8406b --- /dev/null +++ b/packages/strapi-upload-cloudinary/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = false +indent_style = space +indent_size = 2 diff --git a/packages/strapi-upload-cloudinary/.gitattributes b/packages/strapi-upload-cloudinary/.gitattributes new file mode 100755 index 0000000000..065a11c71d --- /dev/null +++ b/packages/strapi-upload-cloudinary/.gitattributes @@ -0,0 +1,103 @@ +# From https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes + +# Handle line endings automatically for files detected as text +# and leave all files detected as binary untouched. +* text=auto + +# +# The above will handle all files NOT found below +# + +# +## These files are text and should be normalized (Convert crlf => lf) +# + +# source code +*.php text +*.css text +*.sass text +*.scss text +*.less text +*.styl text +*.js text eol=lf +*.coffee text +*.json text +*.htm text +*.html text +*.xml text +*.svg text +*.txt text +*.ini text +*.inc text +*.pl text +*.rb text +*.py text +*.scm text +*.sql text +*.sh text +*.bat text + +# templates +*.ejs text +*.hbt text +*.jade text +*.haml text +*.hbs text +*.dot text +*.tmpl text +*.phtml text + +# git config +.gitattributes text +.gitignore text +.gitconfig text + +# code analysis config +.jshintrc text +.jscsrc text +.jshintignore text +.csslintrc text + +# misc config +*.yaml text +*.yml text +.editorconfig text + +# build config +*.npmignore text +*.bowerrc text + +# Heroku +Procfile text +.slugignore text + +# Documentation +*.md text +LICENSE text +AUTHORS text + + +# +## These files are binary and should be left untouched +# + +# (binary is a macro for -text -diff) +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.ico binary +*.mov binary +*.mp4 binary +*.mp3 binary +*.flv binary +*.fla binary +*.swf binary +*.gz binary +*.zip binary +*.7z binary +*.ttf binary +*.eot binary +*.woff binary +*.pyc binary +*.pdf binary diff --git a/packages/strapi-upload-cloudinary/.gitignore b/packages/strapi-upload-cloudinary/.gitignore new file mode 100644 index 0000000000..784dbb5950 --- /dev/null +++ b/packages/strapi-upload-cloudinary/.gitignore @@ -0,0 +1,8 @@ +# Don't check auto-generated stuff into git +node_modules +package-lock.json + +# Cruft +.DS_Store +npm-debug.log +.idea diff --git a/packages/strapi-upload-cloudinary/README.md b/packages/strapi-upload-cloudinary/README.md new file mode 100755 index 0000000000..1cd02a8d2e --- /dev/null +++ b/packages/strapi-upload-cloudinary/README.md @@ -0,0 +1,11 @@ +# strapi-upload-cloudinary + +## Resources + +- [MIT License](LICENSE.md) + +## Links + +- [Strapi website](http://strapi.io/) +- [Strapi community on Slack](http://slack.strapi.io) +- [Strapi news on Twitter](https://twitter.com/strapijs) diff --git a/packages/strapi-upload-cloudinary/lib/index.js b/packages/strapi-upload-cloudinary/lib/index.js new file mode 100644 index 0000000000..00c8fc05d3 --- /dev/null +++ b/packages/strapi-upload-cloudinary/lib/index.js @@ -0,0 +1,66 @@ +'use strict'; + +/** + * Module dependencies + */ + +// Public node modules. +const _ = require('lodash'); +const cloudinary = require('cloudinary').v2; +const intoStream = require('into-stream'); + +module.exports = { + provider: 'cloudinary', + name: 'Cloudinary', + auth: { + cloud_name: { + label: 'Cloud name', + type: 'text' + }, + api_key: { + label: 'API Key', + type: 'text' + }, + api_secret: { + label: 'API Secret', + type: 'text' + } + }, + init: (config) => { + cloudinary.config({ + cloud_name: config.cloud_name, + api_key: config.api_key, + api_secret: config.api_secret + }); + + return { + upload (file) { + return new Promise((resolve, reject) => { + const upload_stream = cloudinary.uploader.upload_stream({}, (err, image) => { + if (err) { + return reject(err); + } + file.public_id = image.public_id; + file.url = image.secure_url; + resolve(); + }); + intoStream(file.buffer).pipe(upload_stream); + }) + }, + async delete (file) { + try { + const response = await cloudinary.uploader.destroy(file.public_id + '3', { + invalidate: true + }); + if (response.result !== 'ok') { + throw { + error: new Error(response.result) + } + } + } catch (error) { + throw error.error; + } + } + }; + } +}; diff --git a/packages/strapi-upload-cloudinary/package.json b/packages/strapi-upload-cloudinary/package.json new file mode 100644 index 0000000000..7004f8de95 --- /dev/null +++ b/packages/strapi-upload-cloudinary/package.json @@ -0,0 +1,46 @@ +{ + "name": "strapi-upload-cloudinary", + "version": "3.0.0-alpha.11.1", + "description": "Cloudinary provider for strapi upload", + "homepage": "http://strapi.io", + "keywords": [ + "upload", + "cloudinary", + "strapi" + ], + "directories": { + "lib": "./lib" + }, + "main": "./lib", + "dependencies": { + "cloudinary": "^1.11.0", + "into-stream": "^3.1.0" + }, + "strapi": { + "isProvider": true + }, + "author": { + "email": "perret.luca@gmail.com", + "name": "Luca Perret", + "url": "https://github.com/lucaperret" + }, + "maintainers": [ + { + "name": "Strapi team", + "email": "hi@strapi.io", + "url": "http://strapi.io" + } + ], + "repository": { + "type": "git", + "url": "git://github.com/strapi/strapi.git" + }, + "bugs": { + "url": "https://github.com/strapi/strapi/issues" + }, + "engines": { + "node": ">= 9.0.0", + "npm": ">= 5.3.0" + }, + "license": "MIT" +}