|
|
@ -139,6 +139,15 @@ var upload = function (Env, safeKey, content, cb) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var closeBlobstage = function (Env, safeKey) {
|
|
|
|
|
|
|
|
var session = Env.getSession(safeKey);
|
|
|
|
|
|
|
|
if (!(session && session.blobstage && typeof(session.blobstage.close) === 'function')) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
session.blobstage.close();
|
|
|
|
|
|
|
|
delete session.blobstage;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// upload_cancel
|
|
|
|
// upload_cancel
|
|
|
|
var upload_cancel = function (Env, safeKey, fileSize, cb) {
|
|
|
|
var upload_cancel = function (Env, safeKey, fileSize, cb) {
|
|
|
|
var session = Env.getSession(safeKey);
|
|
|
|
var session = Env.getSession(safeKey);
|
|
|
@ -159,27 +168,22 @@ var upload_cancel = function (Env, safeKey, fileSize, cb) {
|
|
|
|
|
|
|
|
|
|
|
|
// upload_complete
|
|
|
|
// upload_complete
|
|
|
|
var upload_complete = function (Env, safeKey, id, cb) {
|
|
|
|
var upload_complete = function (Env, safeKey, id, cb) {
|
|
|
|
var session = Env.getSession(safeKey);
|
|
|
|
closeBlobstage(Env, safeKey);
|
|
|
|
|
|
|
|
|
|
|
|
if (session.blobstage && session.blobstage.close) {
|
|
|
|
|
|
|
|
session.blobstage.close();
|
|
|
|
|
|
|
|
delete session.blobstage;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var oldPath = makeStagePath(Env, safeKey);
|
|
|
|
var oldPath = makeStagePath(Env, safeKey);
|
|
|
|
var newPath = makeBlobPath(Env, id);
|
|
|
|
var newPath = makeBlobPath(Env, id);
|
|
|
|
|
|
|
|
|
|
|
|
nThen(function (w) {
|
|
|
|
nThen(function (w) {
|
|
|
|
// make sure the path to your final location exists
|
|
|
|
// make sure the path to your final location exists
|
|
|
|
Fse.mkdirp(Path.dirname(newPath), function (e) {
|
|
|
|
Fse.mkdirp(Path.dirname(newPath), w(function (e) {
|
|
|
|
if (e) {
|
|
|
|
if (e) {
|
|
|
|
w.abort();
|
|
|
|
w.abort();
|
|
|
|
return void cb('RENAME_ERR');
|
|
|
|
return void cb('RENAME_ERR');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}).nThen(function (w) {
|
|
|
|
}).nThen(function (w) {
|
|
|
|
// make sure there's not already something in that exact location
|
|
|
|
// make sure there's not already something in that exact location
|
|
|
|
isFile(newPath, function (e, yes) {
|
|
|
|
isFile(newPath, w(function (e, yes) {
|
|
|
|
if (e) {
|
|
|
|
if (e) {
|
|
|
|
w.abort();
|
|
|
|
w.abort();
|
|
|
|
return void cb(e);
|
|
|
|
return void cb(e);
|
|
|
@ -188,8 +192,8 @@ var upload_complete = function (Env, safeKey, id, cb) {
|
|
|
|
w.abort();
|
|
|
|
w.abort();
|
|
|
|
return void cb('RENAME_ERR');
|
|
|
|
return void cb('RENAME_ERR');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cb(void 0, newPath, id);
|
|
|
|
cb(void 0, id);
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function () {
|
|
|
|
// finally, move the old file to the new path
|
|
|
|
// finally, move the old file to the new path
|
|
|
|
// FIXME we could just move and handle the EEXISTS instead of the above block
|
|
|
|
// FIXME we could just move and handle the EEXISTS instead of the above block
|
|
|
@ -217,15 +221,7 @@ var tryId = function (path, cb) {
|
|
|
|
|
|
|
|
|
|
|
|
// owned_upload_complete
|
|
|
|
// owned_upload_complete
|
|
|
|
var owned_upload_complete = function (Env, safeKey, id, cb) {
|
|
|
|
var owned_upload_complete = function (Env, safeKey, id, cb) {
|
|
|
|
var session = Env.getSession(safeKey);
|
|
|
|
closeBlobstage(Env, safeKey);
|
|
|
|
|
|
|
|
|
|
|
|
// the file has already been uploaded to the staging area
|
|
|
|
|
|
|
|
// close the pending writestream
|
|
|
|
|
|
|
|
if (session.blobstage && session.blobstage.close) {
|
|
|
|
|
|
|
|
session.blobstage.close();
|
|
|
|
|
|
|
|
delete session.blobstage;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isValidId(id)) {
|
|
|
|
if (!isValidId(id)) {
|
|
|
|
return void cb('EINVAL_ID');
|
|
|
|
return void cb('EINVAL_ID');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -582,6 +578,9 @@ BlobStore.create = function (config, _cb) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closeBlobstage: function (safeKey) {
|
|
|
|
|
|
|
|
closeBlobstage(Env, safeKey);
|
|
|
|
|
|
|
|
},
|
|
|
|
complete: function (safeKey, id, _cb) {
|
|
|
|
complete: function (safeKey, id, _cb) {
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
if (!isValidSafeKey(safeKey)) { return void cb('INVALID_SAFEKEY'); }
|
|
|
|
if (!isValidSafeKey(safeKey)) { return void cb('INVALID_SAFEKEY'); }
|
|
|
|