mirror of https://github.com/xwiki-labs/cryptpad
give function a more sensible name
This commit is contained in:
parent
5114292b43
commit
3c1779a667
27
rpc.js
27
rpc.js
|
@ -95,8 +95,7 @@ var unescapeKeyCharacters = function (key) {
|
||||||
return key.replace(/\-/g, '/');
|
return key.replace(/\-/g, '/');
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO Rename to getSession ?
|
var getSession = function (Sessions, key) {
|
||||||
var beginSession = function (Sessions, key) {
|
|
||||||
var safeKey = escapeKeyCharacters(key);
|
var safeKey = escapeKeyCharacters(key);
|
||||||
if (Sessions[safeKey]) {
|
if (Sessions[safeKey]) {
|
||||||
Sessions[safeKey].atime = +new Date();
|
Sessions[safeKey].atime = +new Date();
|
||||||
|
@ -136,7 +135,7 @@ var expireSessions = function (Sessions) {
|
||||||
var addTokenForKey = function (Sessions, publicKey, token) {
|
var addTokenForKey = function (Sessions, publicKey, token) {
|
||||||
if (!Sessions[publicKey]) { throw new Error('undefined user'); }
|
if (!Sessions[publicKey]) { throw new Error('undefined user'); }
|
||||||
|
|
||||||
var user = beginSession(Sessions, publicKey);
|
var user = getSession(Sessions, publicKey);
|
||||||
user.tokens.push(token);
|
user.tokens.push(token);
|
||||||
user.atime = +new Date();
|
user.atime = +new Date();
|
||||||
if (user.tokens.length > 2) { user.tokens.shift(); }
|
if (user.tokens.length > 2) { user.tokens.shift(); }
|
||||||
|
@ -158,7 +157,7 @@ var isValidCookie = function (Sessions, publicKey, cookie) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = beginSession(Sessions, publicKey);
|
var user = getSession(Sessions, publicKey);
|
||||||
if (!user) { return false; }
|
if (!user) { return false; }
|
||||||
|
|
||||||
var idx = user.tokens.indexOf(parsed.seq);
|
var idx = user.tokens.indexOf(parsed.seq);
|
||||||
|
@ -213,7 +212,7 @@ var checkSignature = function (signedMsg, signature, publicKey) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var loadUserPins = function (Env, publicKey, cb) {
|
var loadUserPins = function (Env, publicKey, cb) {
|
||||||
var session = beginSession(Env.Sessions, publicKey);
|
var session = getSession(Env.Sessions, publicKey);
|
||||||
|
|
||||||
if (session.channels) {
|
if (session.channels) {
|
||||||
return cb(session.channels);
|
return cb(session.channels);
|
||||||
|
@ -579,7 +578,7 @@ var pinChannel = function (Env, publicKey, channels, cb) {
|
||||||
|
|
||||||
// get channel list ensures your session has a cached channel list
|
// get channel list ensures your session has a cached channel list
|
||||||
getChannelList(Env, publicKey, function (pinned) {
|
getChannelList(Env, publicKey, function (pinned) {
|
||||||
var session = beginSession(Env.Sessions, publicKey);
|
var session = getSession(Env.Sessions, publicKey);
|
||||||
|
|
||||||
// only pin channels which are not already pinned
|
// only pin channels which are not already pinned
|
||||||
var toStore = channels.filter(function (channel) {
|
var toStore = channels.filter(function (channel) {
|
||||||
|
@ -622,7 +621,7 @@ var unpinChannel = function (Env, publicKey, channels, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
getChannelList(Env, publicKey, function (pinned) {
|
getChannelList(Env, publicKey, function (pinned) {
|
||||||
var session = beginSession(Env.Sessions, publicKey);
|
var session = getSession(Env.Sessions, publicKey);
|
||||||
|
|
||||||
// only unpin channels which are pinned
|
// only unpin channels which are pinned
|
||||||
var toStore = channels.filter(function (channel) {
|
var toStore = channels.filter(function (channel) {
|
||||||
|
@ -647,7 +646,7 @@ var unpinChannel = function (Env, publicKey, channels, cb) {
|
||||||
|
|
||||||
var resetUserPins = function (Env, publicKey, channelList, cb) {
|
var resetUserPins = function (Env, publicKey, channelList, cb) {
|
||||||
if (!Array.isArray(channelList)) { return void cb('INVALID_PIN_LIST'); }
|
if (!Array.isArray(channelList)) { return void cb('INVALID_PIN_LIST'); }
|
||||||
var session = beginSession(Env.Sessions, publicKey);
|
var session = getSession(Env.Sessions, publicKey);
|
||||||
|
|
||||||
if (!channelList.length) {
|
if (!channelList.length) {
|
||||||
return void getHash(Env, publicKey, function (e, hash) {
|
return void getHash(Env, publicKey, function (e, hash) {
|
||||||
|
@ -812,7 +811,7 @@ var upload = function (Env, publicKey, content, cb) {
|
||||||
catch (e) { return void cb('DECODE_BUFFER'); }
|
catch (e) { return void cb('DECODE_BUFFER'); }
|
||||||
var len = dec.length;
|
var len = dec.length;
|
||||||
|
|
||||||
var session = beginSession(Env.Sessions, publicKey);
|
var session = getSession(Env.Sessions, publicKey);
|
||||||
|
|
||||||
if (typeof(session.currentUploadSize) !== 'number' ||
|
if (typeof(session.currentUploadSize) !== 'number' ||
|
||||||
typeof(session.currentUploadSize) !== 'number') {
|
typeof(session.currentUploadSize) !== 'number') {
|
||||||
|
@ -844,7 +843,7 @@ var upload = function (Env, publicKey, content, cb) {
|
||||||
var upload_cancel = function (Env, publicKey, cb) {
|
var upload_cancel = function (Env, publicKey, cb) {
|
||||||
var paths = Env.paths;
|
var paths = Env.paths;
|
||||||
|
|
||||||
var session = beginSession(Env.Sessions, publicKey);
|
var session = getSession(Env.Sessions, publicKey);
|
||||||
delete session.currentUploadSize;
|
delete session.currentUploadSize;
|
||||||
delete session.pendingUploadSize;
|
delete session.pendingUploadSize;
|
||||||
if (session.blobstage) { session.blobstage.close(); }
|
if (session.blobstage) { session.blobstage.close(); }
|
||||||
|
@ -874,7 +873,7 @@ var isFile = function (filePath, cb) {
|
||||||
|
|
||||||
var upload_complete = function (Env, publicKey, cb) {
|
var upload_complete = function (Env, publicKey, cb) {
|
||||||
var paths = Env.paths;
|
var paths = Env.paths;
|
||||||
var session = beginSession(Env.Sessions, publicKey);
|
var session = getSession(Env.Sessions, publicKey);
|
||||||
|
|
||||||
if (session.blobstage && session.blobstage.close) {
|
if (session.blobstage && session.blobstage.close) {
|
||||||
session.blobstage.close();
|
session.blobstage.close();
|
||||||
|
@ -1141,7 +1140,7 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
|
||||||
|
|
||||||
// make sure a user object is initialized in the cookie jar
|
// make sure a user object is initialized in the cookie jar
|
||||||
if (publicKey) {
|
if (publicKey) {
|
||||||
beginSession(Sessions, publicKey);
|
getSession(Sessions, publicKey);
|
||||||
} else {
|
} else {
|
||||||
console.log("No public key");
|
console.log("No public key");
|
||||||
}
|
}
|
||||||
|
@ -1287,7 +1286,7 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
|
||||||
return void upload_status(Env, safeKey, msg[1], function (e, yes) {
|
return void upload_status(Env, safeKey, msg[1], function (e, yes) {
|
||||||
if (!e && !yes) {
|
if (!e && !yes) {
|
||||||
// no pending uploads, set the new size
|
// no pending uploads, set the new size
|
||||||
var user = beginSession(Sessions, safeKey);
|
var user = getSession(Sessions, safeKey);
|
||||||
user.pendingUploadSize = filesize;
|
user.pendingUploadSize = filesize;
|
||||||
user.currentUploadSize = 0;
|
user.currentUploadSize = 0;
|
||||||
}
|
}
|
||||||
|
@ -1321,7 +1320,7 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if session has not been authenticated, do so
|
// if session has not been authenticated, do so
|
||||||
var session = beginSession(Sessions, safeKey);
|
var session = getSession(Sessions, safeKey);
|
||||||
if (typeof(session.privilege) !== 'boolean') {
|
if (typeof(session.privilege) !== 'boolean') {
|
||||||
return void isPrivilegedUser(publicKey, function (yes) {
|
return void isPrivilegedUser(publicKey, function (yes) {
|
||||||
session.privilege = yes;
|
session.privilege = yes;
|
||||||
|
|
Loading…
Reference in New Issue