|
|
|
@ -112,6 +112,30 @@ var handleUnauthenticatedMessage = function (Env, msg, respond, Server) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AUTHENTICATED_USER_TARGETED = {
|
|
|
|
|
RESET: Pinning.resetUserPins,
|
|
|
|
|
PIN: Pinning.pinChannel,
|
|
|
|
|
UNPIN: Pinning.unpinChannel,
|
|
|
|
|
CLEAR_OWNED_CHANNEL: Channel.clearOwnedChannel,
|
|
|
|
|
REMOVE_OWNED_CHANNEL: Channel.removeOwnedChannel,
|
|
|
|
|
UPLOAD_STATUS: Upload.status,
|
|
|
|
|
UPLOAD: Upload.upload,
|
|
|
|
|
UPLOAD_COMPLETE: Upload.complete,
|
|
|
|
|
UPLOAD_CANCEL: Upload.cancel,
|
|
|
|
|
OWNED_UPLOAD_COMPLETE: Upload.complete_owned,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AUTHENTICATED_USER_SCOPED = {
|
|
|
|
|
GET_HASH: Pinning.getHash,
|
|
|
|
|
GET_TOTAL_SIZE: Pinning.getTotalSize,
|
|
|
|
|
UPDATE_LIMITS: Quota.updateLimits,
|
|
|
|
|
GET_LIMIT: Pinning.getLimit,
|
|
|
|
|
EXPIRE_SESSION: Core.expireSession,
|
|
|
|
|
REMOVE_PINS: Pinning.removePins,
|
|
|
|
|
TRIM_PINS: Pinning.trimPins,
|
|
|
|
|
SET_METADATA: Metadata.setMetadata,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var handleAuthenticatedMessage = function (Env, map) {
|
|
|
|
|
var msg = map.msg;
|
|
|
|
|
var safeKey = map.safeKey;
|
|
|
|
@ -119,118 +143,34 @@ var handleAuthenticatedMessage = function (Env, map) {
|
|
|
|
|
var Respond = map.Respond;
|
|
|
|
|
var Server = map.Server;
|
|
|
|
|
|
|
|
|
|
Env.Log.silly('LOG_RPC', msg[0]);
|
|
|
|
|
switch (msg[0]) {
|
|
|
|
|
case 'COOKIE': return void Respond(void 0);
|
|
|
|
|
case 'RESET':
|
|
|
|
|
return Pinning.resetUserPins(Env, safeKey, msg[1], function (e, hash) { // XXX USER_TARGETED
|
|
|
|
|
//WARN(e, hash);
|
|
|
|
|
return void Respond(e, hash);
|
|
|
|
|
});
|
|
|
|
|
case 'PIN':
|
|
|
|
|
return Pinning.pinChannel(Env, safeKey, msg[1], function (e, hash) { // XXX USER_TARGETED
|
|
|
|
|
Env.WARN(e, hash);
|
|
|
|
|
Respond(e, hash);
|
|
|
|
|
});
|
|
|
|
|
case 'UNPIN':
|
|
|
|
|
return Pinning.unpinChannel(Env, safeKey, msg[1], function (e, hash) { // XXX USER_TARGETED
|
|
|
|
|
Env.WARN(e, hash);
|
|
|
|
|
Respond(e, hash);
|
|
|
|
|
});
|
|
|
|
|
case 'GET_HASH':
|
|
|
|
|
return void Pinning.getHash(Env, safeKey, function (e, hash) { // XXX USER_SCOPED
|
|
|
|
|
Env.WARN(e, hash);
|
|
|
|
|
Respond(e, hash);
|
|
|
|
|
var TYPE = msg[0];
|
|
|
|
|
|
|
|
|
|
Env.Log.silly('LOG_RPC', TYPE);
|
|
|
|
|
|
|
|
|
|
if (typeof(AUTHENTICATED_USER_TARGETED[TYPE]) === 'function') {
|
|
|
|
|
return void AUTHENTICATED_USER_TARGETED[TYPE](Env, safeKey, msg[1], function (e, value) {
|
|
|
|
|
Env.WARN(e, value);
|
|
|
|
|
return void Respond(e, value);
|
|
|
|
|
});
|
|
|
|
|
case 'GET_TOTAL_SIZE': // TODO cache this, since it will get called quite a bit
|
|
|
|
|
return Pinning.getTotalSize(Env, safeKey, function (e, size) { // XXX USER_SCOPED
|
|
|
|
|
if (e) {
|
|
|
|
|
Env.WARN(e, safeKey);
|
|
|
|
|
return void Respond(e);
|
|
|
|
|
}
|
|
|
|
|
Respond(e, size);
|
|
|
|
|
});
|
|
|
|
|
case 'UPDATE_LIMITS':
|
|
|
|
|
return void Quota.updateLimits(Env, safeKey, function (e, limit) { // XXX USER_SCOPED
|
|
|
|
|
|
|
|
|
|
if (typeof(AUTHENTICATED_USER_SCOPED[TYPE]) === 'function') {
|
|
|
|
|
return void AUTHENTICATED_USER_SCOPED[TYPE](Env, safeKey, function (e, value) {
|
|
|
|
|
if (e) {
|
|
|
|
|
Env.WARN(e, limit);
|
|
|
|
|
Env.WARN(e, safeKey);
|
|
|
|
|
return void Respond(e);
|
|
|
|
|
}
|
|
|
|
|
Respond(void 0, limit);
|
|
|
|
|
Respond(e, value);
|
|
|
|
|
});
|
|
|
|
|
case 'GET_LIMIT':
|
|
|
|
|
return void Pinning.getLimit(Env, safeKey, function (e, limit) { // XXX USER_SCOPED
|
|
|
|
|
if (e) {
|
|
|
|
|
Env.WARN(e, limit);
|
|
|
|
|
return void Respond(e);
|
|
|
|
|
}
|
|
|
|
|
Respond(void 0, limit);
|
|
|
|
|
});
|
|
|
|
|
case 'EXPIRE_SESSION':
|
|
|
|
|
return void setTimeout(function () { // XXX USER_SCOPED
|
|
|
|
|
Core.expireSession(Env.Sessions, safeKey);
|
|
|
|
|
Respond(void 0, "OK");
|
|
|
|
|
});
|
|
|
|
|
case 'CLEAR_OWNED_CHANNEL':
|
|
|
|
|
return void Channel.clearOwnedChannel(Env, msg[1], publicKey, function (e, response) { // XXX USER_TARGETD_INVERSE
|
|
|
|
|
if (e) { return void Respond(e); }
|
|
|
|
|
Respond(void 0, response);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
case 'REMOVE_OWNED_CHANNEL':
|
|
|
|
|
return void Channel.removeOwnedChannel(Env, msg[1], publicKey, function (e) { // XXX USER_TARGETED_INVERSE
|
|
|
|
|
if (e) { return void Respond(e); }
|
|
|
|
|
Respond(void 0, "OK");
|
|
|
|
|
});
|
|
|
|
|
switch (msg[0]) {
|
|
|
|
|
case 'COOKIE': return void Respond(void 0);
|
|
|
|
|
case 'TRIM_OWNED_CHANNEL_HISTORY':
|
|
|
|
|
return void Channel.removeOwnedChannelHistory(Env, msg[1], publicKey, msg[2], function (e) { // XXX USER_TARGETED_DOUBLE
|
|
|
|
|
if (e) { return void Respond(e); }
|
|
|
|
|
Respond(void 0, 'OK');
|
|
|
|
|
});
|
|
|
|
|
case 'REMOVE_PINS':
|
|
|
|
|
return void Pinning.removePins(Env, safeKey, function (e) { // XXX USER_SCOPED
|
|
|
|
|
if (e) { return void Respond(e); }
|
|
|
|
|
Respond(void 0, "OK");
|
|
|
|
|
});
|
|
|
|
|
case 'TRIM_PINS':
|
|
|
|
|
return void Pinning.trimPins(Env, safeKey, function (e) { // XXX USER_SCOPED
|
|
|
|
|
if (e) { return void Respond(e); }
|
|
|
|
|
Respond(void 0, "OK");
|
|
|
|
|
});
|
|
|
|
|
case 'UPLOAD':
|
|
|
|
|
return void Env.blobStore.upload(safeKey, msg[1], function (e, len) { // XXX USER_SCOPED_SPECIAL
|
|
|
|
|
Env.WARN(e, len);
|
|
|
|
|
Respond(e, len);
|
|
|
|
|
});
|
|
|
|
|
case 'UPLOAD_STATUS':
|
|
|
|
|
var filesize = msg[1];
|
|
|
|
|
return void Upload.upload_status(Env, safeKey, filesize, function (e, yes) { // XXX USER_TARGETED
|
|
|
|
|
if (!e && !yes) {
|
|
|
|
|
// no pending uploads, set the new size
|
|
|
|
|
var user = Core.getSession(Env.Sessions, safeKey);
|
|
|
|
|
user.pendingUploadSize = filesize;
|
|
|
|
|
user.currentUploadSize = 0;
|
|
|
|
|
}
|
|
|
|
|
Respond(e, yes);
|
|
|
|
|
});
|
|
|
|
|
case 'UPLOAD_COMPLETE':
|
|
|
|
|
return void Env.blobStore.complete(safeKey, msg[1], function (e, hash) { // XXX USER_SCOPED_SPECIAL
|
|
|
|
|
Env.WARN(e, hash);
|
|
|
|
|
Respond(e, hash);
|
|
|
|
|
});
|
|
|
|
|
case 'OWNED_UPLOAD_COMPLETE':
|
|
|
|
|
return void Env.blobStore.completeOwned(safeKey, msg[1], function (e, blobId) { // XXX USER_SCOPED_SPECIAL
|
|
|
|
|
Env.WARN(e, blobId);
|
|
|
|
|
Respond(e, blobId);
|
|
|
|
|
});
|
|
|
|
|
case 'UPLOAD_CANCEL':
|
|
|
|
|
// msg[1] is fileSize
|
|
|
|
|
// if we pass it here, we can start an upload right away without calling
|
|
|
|
|
// UPLOAD_STATUS again
|
|
|
|
|
return void Env.blobStore.cancel(safeKey, msg[1], function (e) { // XXX USER_SCOPED_SPECIAL
|
|
|
|
|
Env.WARN(e, 'UPLOAD_CANCEL');
|
|
|
|
|
Respond(e);
|
|
|
|
|
});
|
|
|
|
|
case 'WRITE_LOGIN_BLOCK':
|
|
|
|
|
return void Block.writeLoginBlock(Env, msg[1], function (e) { // XXX SPECIAL
|
|
|
|
|
if (e) {
|
|
|
|
@ -255,15 +195,9 @@ var handleAuthenticatedMessage = function (Env, map) {
|
|
|
|
|
}
|
|
|
|
|
Respond(void 0, result);
|
|
|
|
|
});
|
|
|
|
|
case 'SET_METADATA':
|
|
|
|
|
return void Metadata.setMetadata(Env, msg[1], publicKey, function (e, data) { // XXX USER_TARGETED_INVERSE
|
|
|
|
|
if (e) {
|
|
|
|
|
Env.WARN(e, data);
|
|
|
|
|
return void Respond(e);
|
|
|
|
|
}
|
|
|
|
|
Respond(void 0, data);
|
|
|
|
|
});
|
|
|
|
|
default:
|
|
|
|
|
console.log(msg);
|
|
|
|
|
throw new Error("OOPS");
|
|
|
|
|
return void Respond('UNSUPPORTED_RPC_CALL', msg);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|