Skip to content

Commit

Permalink
Fixed some more unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
supernomad committed Jun 21, 2015
1 parent 13dfb37 commit c0a75d7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
68 changes: 35 additions & 33 deletions routes/chunked-upload-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,45 @@ var routes = {
}

dataCache.restore(req.params.uploadId, function(error, keyVal) {
errorHelper.genericErrorHandler(error, debug);
var file = {};
var upload = keyVal.value;
for (var key in req.files) {
if (req.files.hasOwnProperty(key)) {
file = req.files[key];
break;
}
}

function readCallback(error, data) {
errorHelper.genericErrorHandler(error, debug);
io.WriteFileChunk(upload.TempPath, data, 0, data.length, index * upload.ChunkSize, writeChunkCallback);
}

function writeChunkCallback(error) {
if(typeHelper.doesExist(keyVal.value)) {
console.log(keyVal);
errorHelper.genericErrorHandler(error, debug);
if (upload.chunks.every(function(val){
return val === true;
}))
{
io.RenameFile(upload.TempPath, upload.FinalPath, renameCallback);
} else {
res.json(new apiModels.ApiResponse(routePrefix, {}, "Chunk Recieved"));
var file = {};
var upload = keyVal.value;
for (var key in req.files) {
if (req.files.hasOwnProperty(key)) {
file = req.files[key];
break;
}
}
}

function renameCallback(error) {
errorHelper.genericErrorHandler(error, debug);
dataCache.delete(upload.id, function(error, count) {

function readCallback(error, data) {
errorHelper.genericErrorHandler(error, debug);
});

res.json(new apiModels.ApiResponse(routePrefix, {}, "Upload Complete"));
};
io.WriteFileChunk(upload.TempPath, data, 0, data.length, index * upload.ChunkSize, writeChunkCallback);
}

function writeChunkCallback(error) {
errorHelper.genericErrorHandler(error, debug);
if (upload.chunks.every(function(val){
return val === true;
}))
{
io.RenameFile(upload.TempPath, upload.FinalPath, renameCallback);
} else {
res.json(new apiModels.ApiResponse(routePrefix, {}, "Chunk Recieved"));
}
}

function renameCallback(error) {
errorHelper.genericErrorHandler(error, debug);
dataCache.delete(upload.id, function(error, count) {
errorHelper.genericErrorHandler(error, debug);
});

res.json(new apiModels.ApiResponse(routePrefix, {}, "Upload Complete"));
};


if(upload) {
upload.chunks[index] = true;
dataCache.update(upload.Id, upload, defaultTtl, function(error, success) {
errorHelper.genericErrorHandler(error, debug);
Expand Down
2 changes: 1 addition & 1 deletion test/routes/chunked-upload-routes-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe("chunked-upload-routes.js", function() {
routes.put.handler({
params: {
uploadId: guidHelper.newGuid(),
index: "woot"
index: 0
},
files: {
testFile: {
Expand Down

0 comments on commit c0a75d7

Please sign in to comment.