make explicit file size RPCs unauthenticated
This commit is contained in:
64
rpc.js
64
rpc.js
@@ -281,7 +281,7 @@ var getUploadSize = function (Env, channel, cb) {
|
||||
var paths = Env.paths;
|
||||
var path = makeFilePath(paths.blob, channel);
|
||||
if (!path) {
|
||||
return cb('INVALID_UPLOAD_ID');
|
||||
return cb('INVALID_UPLOAD_ID', path);
|
||||
}
|
||||
|
||||
Fs.stat(path, function (err, stats) {
|
||||
@@ -826,6 +826,13 @@ var upload_status = function (Env, publicKey, filesize, cb) {
|
||||
});
|
||||
};
|
||||
|
||||
var isUnauthenticatedCall = function (call) {
|
||||
return [
|
||||
'GET_FILE_SIZE',
|
||||
'GET_MULTIPLE_FILE_SIZE',
|
||||
].indexOf(call) !== -1;
|
||||
};
|
||||
|
||||
var isAuthenticatedCall = function (call) {
|
||||
return [
|
||||
'COOKIE',
|
||||
@@ -834,11 +841,8 @@ var isAuthenticatedCall = function (call) {
|
||||
'UNPIN',
|
||||
'GET_HASH',
|
||||
'GET_TOTAL_SIZE',
|
||||
'GET_FILE_SIZE',
|
||||
'UPDATE_LIMITS',
|
||||
'GET_LIMIT',
|
||||
'GET_MULTIPLE_FILE_SIZE',
|
||||
//'UPLOAD',
|
||||
'UPLOAD_COMPLETE',
|
||||
'UPLOAD_CANCEL',
|
||||
].indexOf(call) !== -1;
|
||||
@@ -867,6 +871,45 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
|
||||
var blobPath = paths.blob = keyOrDefaultString('blobPath', './blob');
|
||||
var blobStagingPath = paths.staging = keyOrDefaultString('blobStagingPath', './blobstage');
|
||||
|
||||
var isUnauthenticateMessage = function (msg) {
|
||||
var unAuthed = msg && msg.length === 2 && isUnauthenticatedCall(msg[0]);
|
||||
|
||||
if (unAuthed) {
|
||||
console.log(msg);
|
||||
console.log('is unauthenticated call!');
|
||||
return unAuthed;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var handleUnauthenticatedMessage = function (msg, respond) {
|
||||
console.log(msg);
|
||||
switch (msg[0]) {
|
||||
case 'GET_FILE_SIZE':
|
||||
console.log("Get file size");
|
||||
return void getFileSize(Env, msg[1], function (e, size) {
|
||||
if (e) {
|
||||
console.error(e);
|
||||
}
|
||||
WARN(e, msg[1]);
|
||||
console.log(size);
|
||||
respond(e, [null, size, null]);
|
||||
});
|
||||
case 'GET_MULTIPLE_FILE_SIZE':
|
||||
return void getMultipleFileSize(Env, msg[1], function (e, dict) {
|
||||
if (e) {
|
||||
WARN(e, dict);
|
||||
return respond(e);
|
||||
}
|
||||
respond(e, [null, dict, null]);
|
||||
});
|
||||
default:
|
||||
console.error("unsupported!");
|
||||
return respond('UNSUPPORTED_RPC_CALL', msg);
|
||||
}
|
||||
};
|
||||
|
||||
var rpc = function (
|
||||
ctx /*:{ store: Object }*/,
|
||||
data /*:Array<Array<any>>*/,
|
||||
@@ -888,11 +931,19 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
|
||||
return void respond('INVALID_ARG_FORMAT');
|
||||
}
|
||||
|
||||
if (isUnauthenticateMessage(msg)) {
|
||||
return handleUnauthenticatedMessage(msg, respond);
|
||||
}
|
||||
|
||||
var signature = msg.shift();
|
||||
var publicKey = msg.shift();
|
||||
|
||||
// make sure a user object is initialized in the cookie jar
|
||||
beginSession(Sessions, publicKey);
|
||||
if (publicKey) {
|
||||
beginSession(Sessions, publicKey);
|
||||
} else {
|
||||
console.log("No public key");
|
||||
}
|
||||
|
||||
var cookie = msg[0];
|
||||
if (!isValidCookie(Sessions, publicKey, cookie)) {
|
||||
@@ -928,7 +979,8 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
|
||||
msg.shift();
|
||||
|
||||
var Respond = function (e, msg) {
|
||||
var token = Sessions[safeKey].tokens.slice(-1)[0];
|
||||
var session = Sessions[safeKey];
|
||||
var token = session? session.tokens.slice(-1)[0]: '';
|
||||
var cookie = makeCookie(token).join('|');
|
||||
respond(e, [cookie].concat(typeof(msg) !== 'undefined' ?msg: []));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user