@@ -7,7 +7,7 @@ const StorageBase = require('ghost-storage-base'),
77 path = require ( 'path' ) ,
88 got = require ( 'got' ) ,
99 plugin = require ( path . join ( __dirname , '/plugins' ) ) ,
10- debug = require ( '@tryghost/debug' ) ,
10+ debug = require ( '@tryghost/debug' ) ( 'adapter' ) ,
1111 common = ( ( ) => {
1212 // Tries to include GhostError helper
1313 try {
@@ -40,9 +40,9 @@ class CloudinaryAdapter extends StorageBase {
4040 fetch : fetchOptions
4141 } ;
4242
43- debug ( 'useDatedFolder:' , this . useDatedFolder ) ;
44- debug ( 'uploaderOptions:' , this . uploaderOptions ) ;
45- debug ( 'rjsOptions:' , this . rjsOptions ) ;
43+ debug ( 'constructor: useDatedFolder:' , this . useDatedFolder ) ;
44+ debug ( 'constructor: uploaderOptions:' , this . uploaderOptions ) ;
45+ debug ( 'constructor: rjsOptions:' , this . rjsOptions ) ;
4646
4747 cloudinary . config ( auth ) ;
4848 }
@@ -51,6 +51,8 @@ class CloudinaryAdapter extends StorageBase {
5151 * @override
5252 */
5353 exists ( filename ) {
54+ debug ( 'exists:filename' , filename ) ;
55+
5456 const pubId = this . toCloudinaryId ( filename ) ;
5557
5658 return new Promise ( ( resolve ) => cloudinary . uploader . explicit ( pubId , { type : 'upload' } , ( err ) => {
@@ -107,12 +109,16 @@ class CloudinaryAdapter extends StorageBase {
107109
108110 return new Promise ( ( resolve , reject ) => cloudinary . uploader . upload ( imagePath , options . upload , ( err , res ) => {
109111 if ( err ) {
112+ debug ( 'uploader:error' , err ) ;
113+
110114 return reject ( new common . errors . GhostError ( {
111115 err : err ,
112116 message : `Could not upload image ${ imagePath } `
113117 } ) ) ;
114118 }
115119 if ( url ) {
120+ debug ( 'uploader:url' , url ) ;
121+
116122 return resolve ( cloudinary . url ( res . public_id . concat ( '.' , res . format ) , options . fetch ) ) ;
117123 }
118124 return resolve ( ) ;
@@ -132,10 +138,14 @@ class CloudinaryAdapter extends StorageBase {
132138 * @override
133139 */
134140 delete ( filename ) {
141+ debug ( 'delete:filename' , filename ) ;
142+
135143 const pubId = this . toCloudinaryId ( filename ) ;
136144
137145 return new Promise ( ( resolve , reject ) => cloudinary . uploader . destroy ( pubId , ( err , res ) => {
138146 if ( err ) {
147+ debug ( 'delete:error' , err ) ;
148+
139149 return reject ( new common . errors . GhostError ( {
140150 err : err ,
141151 message : `Could not delete image ${ filename } `
@@ -150,13 +160,19 @@ class CloudinaryAdapter extends StorageBase {
150160 */
151161 read ( options ) {
152162 const opts = options || { } ;
163+
164+ debug ( 'read:opts' , opts ) ;
165+
153166 return new Promise ( async ( resolve , reject ) => {
154167 try {
155168 return resolve ( await got ( opts . path , {
156169 responseType : 'buffer' ,
157170 resolveBodyOnly : true
158171 } ) ) ;
159172 } catch ( err ) {
173+
174+ debug ( 'read:error' , err ) ;
175+
160176 return reject ( new common . errors . GhostError ( {
161177 err : err ,
162178 message : `Could not read image ${ opts . path } `
0 commit comments