Merge branch 'metadata' into staging
This commit is contained in:
27
rpc.js
27
rpc.js
@@ -326,6 +326,24 @@ var getFileSize = function (Env, channel, cb) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getMetadata = function (Env, channel, cb) {
|
||||||
|
if (!isValidId(channel)) { return void cb('INVALID_CHAN'); }
|
||||||
|
|
||||||
|
if (channel.length === 32) {
|
||||||
|
if (typeof(Env.msgStore.getChannelMetadata) !== 'function') {
|
||||||
|
return cb('GET_CHANNEL_METADATA_UNSUPPORTED');
|
||||||
|
}
|
||||||
|
|
||||||
|
return void Env.msgStore.getChannelMetadata(channel, function (e, data /*:object*/) {
|
||||||
|
if (e) {
|
||||||
|
if (e.code === 'INVALID_METADATA') { return void cb(void 0, {}); }
|
||||||
|
return void cb(e.code);
|
||||||
|
}
|
||||||
|
cb(void 0, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var getMultipleFileSize = function (Env, channels, cb) {
|
var getMultipleFileSize = function (Env, channels, cb) {
|
||||||
if (!Array.isArray(channels)) { return cb('INVALID_PIN_LIST'); }
|
if (!Array.isArray(channels)) { return cb('INVALID_PIN_LIST'); }
|
||||||
if (typeof(Env.msgStore.getChannelSize) !== 'function') {
|
if (typeof(Env.msgStore.getChannelSize) !== 'function') {
|
||||||
@@ -1139,6 +1157,7 @@ var isNewChannel = function (Env, channel, cb) {
|
|||||||
var isUnauthenticatedCall = function (call) {
|
var isUnauthenticatedCall = function (call) {
|
||||||
return [
|
return [
|
||||||
'GET_FILE_SIZE',
|
'GET_FILE_SIZE',
|
||||||
|
'GET_METADATA',
|
||||||
'GET_MULTIPLE_FILE_SIZE',
|
'GET_MULTIPLE_FILE_SIZE',
|
||||||
'IS_CHANNEL_PINNED',
|
'IS_CHANNEL_PINNED',
|
||||||
'IS_NEW_CHANNEL',
|
'IS_NEW_CHANNEL',
|
||||||
@@ -1260,12 +1279,14 @@ RPC.create = function (
|
|||||||
}
|
}
|
||||||
case 'GET_FILE_SIZE':
|
case 'GET_FILE_SIZE':
|
||||||
return void getFileSize(Env, msg[1], function (e, size) {
|
return void getFileSize(Env, msg[1], function (e, size) {
|
||||||
if (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
WARN(e, msg[1]);
|
WARN(e, msg[1]);
|
||||||
respond(e, [null, size, null]);
|
respond(e, [null, size, null]);
|
||||||
});
|
});
|
||||||
|
case 'GET_METADATA':
|
||||||
|
return void getMetadata(Env, msg[1], function (e, data) {
|
||||||
|
WARN(e, msg[1]);
|
||||||
|
respond(e, [null, data, null]);
|
||||||
|
});
|
||||||
case 'GET_MULTIPLE_FILE_SIZE':
|
case 'GET_MULTIPLE_FILE_SIZE':
|
||||||
return void getMultipleFileSize(Env, msg[1], function (e, dict) {
|
return void getMultipleFileSize(Env, msg[1], function (e, dict) {
|
||||||
if (e) {
|
if (e) {
|
||||||
|
|||||||
@@ -429,12 +429,26 @@ define([
|
|||||||
toSign.drive = secret.channel;
|
toSign.drive = secret.channel;
|
||||||
toSign.edPublic = store.proxy.edPublic;
|
toSign.edPublic = store.proxy.edPublic;
|
||||||
var signKey = Crypto.Nacl.util.decodeBase64(secret.keys.signKey);
|
var signKey = Crypto.Nacl.util.decodeBase64(secret.keys.signKey);
|
||||||
console.log(Sortify(toSign));
|
Store.anonRpcMsg({
|
||||||
var proof = Crypto.Nacl.sign.detached(Crypto.Nacl.util.decodeUTF8(Sortify(toSign)), signKey);
|
msg: 'GET_METADATA',
|
||||||
var proofTxt = Crypto.Nacl.util.encodeBase64(proof);
|
data: secret.channel
|
||||||
cb({
|
}, function (data) {
|
||||||
proof: proofTxt,
|
console.log(data[0]);
|
||||||
toSign: JSON.parse(Sortify(toSign))
|
var metadata = data[0];
|
||||||
|
// Owned drive
|
||||||
|
if (metadata && metadata.owners && metadata.owners.length === 1 &&
|
||||||
|
metadata.owners.indexOf(edPublic) !== -1) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not owned drive
|
||||||
|
var proof = Crypto.Nacl.sign.detached(Crypto.Nacl.util.decodeUTF8(Sortify(toSign)), signKey);
|
||||||
|
var proofTxt = Crypto.Nacl.util.encodeBase64(proof);
|
||||||
|
cb({
|
||||||
|
proof: proofTxt,
|
||||||
|
toSign: JSON.parse(Sortify(toSign))
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user