Merge pull request #3196 from strapi/cloudinary-password

Cloudinary provider plugin secret field now password type
This commit is contained in:
Jim LAURIE 2019-05-14 12:01:28 +02:00 committed by GitHub
commit 1d172fa4ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,52 +16,55 @@ module.exports = {
auth: {
cloud_name: {
label: 'Cloud name',
type: 'text'
type: 'text',
},
api_key: {
label: 'API Key',
type: 'text'
type: 'text',
},
api_secret: {
label: 'API Secret',
type: 'text'
}
type: 'password',
},
},
init: (config) => {
init: config => {
cloudinary.config({
cloud_name: config.cloud_name,
api_key: config.api_key,
api_secret: config.api_secret
api_secret: config.api_secret,
});
return {
upload (file) {
upload(file) {
return new Promise((resolve, reject) => {
const upload_stream = cloudinary.uploader.upload_stream({ resource_type: "auto" }, (err, image) => {
if (err) {
return reject(err);
}
file.public_id = image.public_id;
file.url = image.secure_url;
resolve();
});
const upload_stream = cloudinary.uploader.upload_stream(
{ resource_type: 'auto' },
(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) {
async delete(file) {
try {
const response = await cloudinary.uploader.destroy(file.public_id, {
invalidate: true
invalidate: true,
});
if (response.result !== 'ok') {
throw {
error: new Error(response.result)
error: new Error(response.result),
};
}
} catch (error) {
throw error.error;
}
}
},
};
}
},
};