Skip to content

Commit

Permalink
Properly provide a default File model and handle asynchronous file up…
Browse files Browse the repository at this point in the history
…load
  • Loading branch information
kriszyp committed Jul 30, 2010
1 parent c9680e8 commit 7090bd7
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/media.js
Expand Up @@ -101,15 +101,23 @@ exports.forEachableToString = function(input){
return strings.join("");
});
};

exports.onFile = function(file){
var FileModel;
try{
FileModel = model.openObjectStore("File");
}catch(e){
model.classModel.put({id:"File"}, {store: 'require("pintura/store/binary-files").BinaryFiles("data/files")'})
FileModel = model.openObjectStore("File");
var fileModel;
exports.getFileModel = function(){
if(!fileModel){
var Model = require("perstore/model").Model;
fileModel = Model(require("perstore/store/filesystem").FileSystem({dataFolder:"files"}), exports.fileSchema);
}
return fileModel;
};
exports.setFileModel = function(value){
fileModel = value;
};
exports.fileSchema = {};

exports.onFile = function(file, directives){
file.isFile = true;
return {$ref:FileModel.put(file)};
return when(exports.getFileModel().put(file, directives), function(file){
file = file.id || file;
return {$ref:file};
});
};

0 comments on commit 7090bd7

Please sign in to comment.