updated for creating post from node
This commit is contained in:
		
							parent
							
								
									bae751916c
								
							
						
					
					
						commit
						1b7f41ae7a
					
				| @ -242,6 +242,14 @@ | |||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   // read config and such
 |   // read config and such
 | ||||||
|  |   Desi._initFileAdapter = function (env) { | ||||||
|  |     if (!exports.window) { | ||||||
|  |       // TODO pull state out of this later
 | ||||||
|  |       Desi.realFsapi.create(Desi, env); | ||||||
|  |     } | ||||||
|  |     return PromiseA.resolve(); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|   Desi.init = function (desi, env) { |   Desi.init = function (desi, env) { | ||||||
|     console.log(''); |     console.log(''); | ||||||
|     console.log(''); |     console.log(''); | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ function create(Desi, options) { | |||||||
|   var fsapi = Desi.fsapi |   var fsapi = Desi.fsapi | ||||||
|     ; |     ; | ||||||
| 
 | 
 | ||||||
|   options.blogdir = options.working_path; |   options.blogdir = options.blogdir || options.working_path; | ||||||
| 
 | 
 | ||||||
|   fsapi.getMeta = function (dirnames, opts) { |   fsapi.getMeta = function (dirnames, opts) { | ||||||
|     opts = opts || {}; |     opts = opts || {}; | ||||||
| @ -53,7 +53,7 @@ function create(Desi, options) { | |||||||
|     return fsapi.copyfs(options.blogdir, files); |     return fsapi.copyfs(options.blogdir, files); | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   fsapi.putFiles = function (files) { |   fsapi.putFiles = function (files, opts) { | ||||||
|     files.forEach(function (file) { |     files.forEach(function (file) { | ||||||
|       if (!file.contents || 'string' === typeof file.contents) { |       if (!file.contents || 'string' === typeof file.contents) { | ||||||
|         return; |         return; | ||||||
| @ -62,12 +62,12 @@ function create(Desi, options) { | |||||||
|         file.contents = JSON.stringify(file.contents); |         file.contents = JSON.stringify(file.contents); | ||||||
|       } |       } | ||||||
|       else if (/\.ya?ml$/i.test(file.path)) { |       else if (/\.ya?ml$/i.test(file.path)) { | ||||||
|         file.contents = exports.jsyaml.dump(file.contents);  |         file.contents = Desi.YAML.stringify(file.contents);  | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     // TODO size
 |     // TODO size
 | ||||||
|     return fsapi.putfs(options.blogdir, files); |     return fsapi.putfs(options.blogdir, files, opts); | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -270,8 +270,10 @@ function copyfs(blogdir, files) { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function putfs(blogdir, files) { | function putfs(blogdir, files, options) { | ||||||
|   var results = { errors: [] } |   options = options || {}; | ||||||
|  | 
 | ||||||
|  |   var putfsResults = { errors: [] } | ||||||
|     , dirpaths = {} |     , dirpaths = {} | ||||||
|     ; |     ; | ||||||
| 
 | 
 | ||||||
| @ -294,7 +296,7 @@ function putfs(blogdir, files) { | |||||||
|     return forEachAsync(Object.keys(dirpaths), function (pathname) { |     return forEachAsync(Object.keys(dirpaths), function (pathname) { | ||||||
|       return mkdirp(pathname).catch(function (e) { |       return mkdirp(pathname).catch(function (e) { | ||||||
|         // TODO exclude attempting to write files to this dir?
 |         // TODO exclude attempting to write files to this dir?
 | ||||||
|         results.errors.push({ |         putfsResults.errors.push({ | ||||||
|           type: 'directory' |           type: 'directory' | ||||||
| 
 | 
 | ||||||
|         , directory: pathname |         , directory: pathname | ||||||
| @ -311,19 +313,23 @@ function putfs(blogdir, files) { | |||||||
|   }).then(function () { |   }).then(function () { | ||||||
|     // TODO sort deletes last
 |     // TODO sort deletes last
 | ||||||
|     return forEachAsync(files, function (file) { |     return forEachAsync(files, function (file) { | ||||||
|       var p |  | ||||||
|         ; |  | ||||||
| 
 |  | ||||||
|       // TODO use lastModifiedDate as per client request?
 |       // TODO use lastModifiedDate as per client request?
 | ||||||
|       // TODO compare sha1 sums for integrity
 |       // TODO compare sha1 sums for integrity
 | ||||||
|       if (file.delete || !file.contents) { |       // NOTE existsAsync is backwards
 | ||||||
|         p = fs.unlinkAsync(file.realPath); |       return fs.existsAsync(file.realPath).then(function () { | ||||||
|       } else { |         return fs.writeFileAsync(file.realPath, file.contents, 'utf8'); | ||||||
|         p = fs.writeFileAsync(file.realPath, file.contents, 'utf8'); |       }).catch(function (/*exists*/) { | ||||||
|       } |         if (file.delete || !file.contents) { | ||||||
|  |           return fs.unlinkAsync(file.realPath); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|       return p.catch(function (e) { |         if (false === options.replace || false === options.overwrite) { | ||||||
|         results.errors.push({ |           throw new Error('EEXIST: the file already exists'); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return fs.writeFileAsync(file.realPath, file.contents, 'utf8'); | ||||||
|  |       }).catch(function (e) { | ||||||
|  |         putfsResults.errors.push({ | ||||||
|           type: 'file' |           type: 'file' | ||||||
| 
 | 
 | ||||||
|         , file: file.realPath |         , file: file.realPath | ||||||
| @ -341,7 +347,7 @@ function putfs(blogdir, files) { | |||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
|   }).catch(function (e) { |   }).catch(function (e) { | ||||||
|     results.error = { |     putfsResults.error = { | ||||||
|       message: e.message |       message: e.message | ||||||
|     , code: e.code |     , code: e.code | ||||||
|     , errno: e.errno |     , errno: e.errno | ||||||
| @ -349,7 +355,7 @@ function putfs(blogdir, files) { | |||||||
|     , syscall: e.syscall |     , syscall: e.syscall | ||||||
|     }; |     }; | ||||||
|   }).then(function () { |   }).then(function () { | ||||||
|     return results; |     return putfsResults; | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
| /* | /* | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user