Last active
December 10, 2015 20:18
-
-
Save raix/4486978 to your computer and use it in GitHub Desktop.
Debug file transport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timerTotal = self.startTimer(); | |
var timerMeteorCall = self.startTimer(); | |
Meteor.apply('saveChunck'+fileItem.collectionName, [ | |
fileId = fileId, | |
currentChunk = chunkNumber, | |
countChunks = fileItem.countChunks, | |
data = data | |
],[ | |
wait = true | |
], function(error, result) { | |
//Callback | |
self.setTimer('upload', 'meteorcallserver', result.time); | |
self.stopTimer('upload', 'meteorcall', timerMeteorCall); | |
if (result.chunkId) { | |
self.que[fileId].currentChunkServer = result.currentChunk; | |
//TODO: Really, should the next function rule? or the result.currentChunk? | |
//The result could be async? multiple users | |
//Use in >saveChunk< function: | |
// updating files $inc: { currentChunk: 0 } until == countChunks | |
// if not missing any chunks then complete else request client to upload by returning missing chunk number? | |
// | |
// var next = result.currentChunck; //Chunck to download.. if not the save func gotta test fs.chunks index | |
var next = self.nextChunk(result.fileId); //or let server decide | |
//!result.complete && | |
if (next ) { | |
self.getDataChunk(result.fileId, next); | |
} else { | |
} | |
} | |
self.stopTimer('upload', 'total', timerTotal); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
methodFunc['saveChunck'+self._name] = function(fileId, chunkNumber, countChunks, data) { | |
this.unblock(); | |
var complete = (chunkNumber == countChunks - 1); | |
var updateFiles = (chunkNumber == 0); //lower db overheat on files record. eg. chunkNumber % 100 == 0 | |
var cId = null; | |
if (Meteor.isServer && fileId) { | |
var startTime = Date.now(); | |
cId = self.chunks.insert({ | |
//"_id" : <unspecified>, // object id of the chunk in the _chunks collection | |
"files_id" : fileId, // _id of the corresponding files collection entry | |
"n" : chunkNumber, // chunks are numbered in order, starting with 0 | |
"data" : data, // the chunk's payload as a BSON binary type | |
}); | |
/* Improve chunk index integrity have a look at TODO in uploadChunk() */ | |
if (cId) { //If chunk added successful | |
if (complete || updateFiles) //update file status | |
self.files.update({ _id:fileId }, { | |
$set: { complete: complete, currentChunk: chunkNumber+1 } | |
}) | |
else | |
self.files.update({ _id:fileId }, { | |
$set: { currentChunk: chunkNumber+1 } | |
}); | |
//** Only update currentChunk if not complete? , complete: {$ne: true} | |
} //If cId | |
} //EO isServer | |
return { fileId: fileId, chunkId: cId, complete: complete, currentChunk: chunkNumber+1, time: (Date.now()-startTime)}; | |
}; //EO saveChunck+name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment