Unified metadata
This commit is contained in:
parent
60bea6b33b
commit
5be37f2e45
@ -396,32 +396,35 @@ module.exports.create = function (cfg) {
|
|||||||
// parsed[3] is the last known hash (optionnal)
|
// parsed[3] is the last known hash (optionnal)
|
||||||
sendMsg(ctx, user, [seq, 'ACK']);
|
sendMsg(ctx, user, [seq, 'ACK']);
|
||||||
channelName = parsed[1];
|
channelName = parsed[1];
|
||||||
var validateKey = parsed[2];
|
var config = parsed[2];
|
||||||
var lastKnownHash = parsed[3];
|
var metadata = {};
|
||||||
var owners;
|
var lastKnownHash;
|
||||||
var expire;
|
if (config && typeof config === "object") {
|
||||||
if (parsed[2] && typeof parsed[2] === "object") {
|
lastKnownHash = config.lastKnownHash;
|
||||||
validateKey = parsed[2].validateKey;
|
metadata = config.metadata || {};
|
||||||
lastKnownHash = parsed[2].lastKnownHash;
|
if (metadata.expire) {
|
||||||
owners = parsed[2].owners;
|
metadata.expire = +metadata.expire * 1000 + (+new Date());
|
||||||
if (parsed[2].expire) {
|
|
||||||
expire = +parsed[2].expire * 1000 + (+new Date());
|
|
||||||
}
|
}
|
||||||
|
} else if (config) {
|
||||||
|
// This is the old way: parsed[2] is the validateKey and parsed[3] is the last known hash
|
||||||
|
lastKnownHash = parsed[3];
|
||||||
|
metadata.validateKey = parsed[2];
|
||||||
}
|
}
|
||||||
|
metadata.channel = channelName;
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
if (!tasks) { return; } // tasks are not supported
|
if (!tasks) { return; } // tasks are not supported
|
||||||
if (typeof(expire) !== 'number' || !expire) { return; }
|
if (typeof(metadata.expire) !== 'number' || !metadata.expire) { return; }
|
||||||
|
|
||||||
// the fun part...
|
// the fun part...
|
||||||
// the user has said they want this pad to expire at some point
|
// the user has said they want this pad to expire at some point
|
||||||
tasks.write(expire, "EXPIRE", [ channelName ], waitFor(function (err) {
|
tasks.write(metadata.expire, "EXPIRE", [ channelName ], waitFor(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
// if there is an error, we don't want to crash the whole server...
|
// if there is an error, we don't want to crash the whole server...
|
||||||
// just log it, and if there's a problem you'll be able to fix it
|
// just log it, and if there's a problem you'll be able to fix it
|
||||||
// at a later date with the provided information
|
// at a later date with the provided information
|
||||||
Log.error('HK_CREATE_EXPIRE_TASK', err);
|
Log.error('HK_CREATE_EXPIRE_TASK', err);
|
||||||
Log.info('HK_INVALID_EXPIRE_TASK', JSON.stringify([expire, 'EXPIRE', channelName]));
|
Log.info('HK_INVALID_EXPIRE_TASK', JSON.stringify([metadata.expire, 'EXPIRE', channelName]));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
@ -482,20 +485,9 @@ module.exports.create = function (cfg) {
|
|||||||
// the first message in the file
|
// the first message in the file
|
||||||
const chan = ctx.channels[channelName];
|
const chan = ctx.channels[channelName];
|
||||||
if (msgCount === 0 && !historyKeeperKeys[channelName] && chan && chan.indexOf(user) > -1) {
|
if (msgCount === 0 && !historyKeeperKeys[channelName] && chan && chan.indexOf(user) > -1) {
|
||||||
var key = {};
|
historyKeeperKeys[channelName] = metadata;
|
||||||
key.channel = channelName;
|
storeMessage(ctx, chan, JSON.stringify(metadata), false, undefined);
|
||||||
if (validateKey) {
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(metadata)]);
|
||||||
key.validateKey = validateKey;
|
|
||||||
}
|
|
||||||
if (owners) {
|
|
||||||
key.owners = owners;
|
|
||||||
}
|
|
||||||
if (expire) {
|
|
||||||
key.expire = expire;
|
|
||||||
}
|
|
||||||
historyKeeperKeys[channelName] = key;
|
|
||||||
storeMessage(ctx, chan, JSON.stringify(key), false, undefined);
|
|
||||||
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(key)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of history message:
|
// End of history message:
|
||||||
|
|||||||
@ -422,8 +422,10 @@ define([
|
|||||||
|
|
||||||
var friend = getFriendFromChannel(chan.id) || {};
|
var friend = getFriendFromChannel(chan.id) || {};
|
||||||
var cfg = {
|
var cfg = {
|
||||||
validateKey: keys ? keys.validateKey : undefined,
|
metadata: {
|
||||||
owners: [proxy.edPublic, friend.edPublic],
|
validateKey: keys ? keys.validateKey : undefined,
|
||||||
|
owners: [proxy.edPublic, friend.edPublic],
|
||||||
|
},
|
||||||
lastKnownHash: data.lastKnownHash
|
lastKnownHash: data.lastKnownHash
|
||||||
};
|
};
|
||||||
var msg = ['GET_HISTORY', chan.id, cfg];
|
var msg = ['GET_HISTORY', chan.id, cfg];
|
||||||
|
|||||||
@ -1191,10 +1191,7 @@ define([
|
|||||||
},
|
},
|
||||||
noChainPad: true,
|
noChainPad: true,
|
||||||
channel: data.channel,
|
channel: data.channel,
|
||||||
validateKey: data.validateKey,
|
metadata: data.metadata,
|
||||||
owners: data.owners,
|
|
||||||
password: data.password,
|
|
||||||
expire: data.expire,
|
|
||||||
network: store.network,
|
network: store.network,
|
||||||
//readOnly: data.readOnly,
|
//readOnly: data.readOnly,
|
||||||
onConnect: function (wc, sendMessage) {
|
onConnect: function (wc, sendMessage) {
|
||||||
@ -1441,14 +1438,16 @@ define([
|
|||||||
websocketURL: NetConfig.getWebsocketURL(),
|
websocketURL: NetConfig.getWebsocketURL(),
|
||||||
channel: secret.channel,
|
channel: secret.channel,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
validateKey: secret.keys.validateKey || undefined,
|
|
||||||
crypto: Crypto.createEncryptor(secret.keys),
|
crypto: Crypto.createEncryptor(secret.keys),
|
||||||
userName: 'sharedFolder',
|
userName: 'sharedFolder',
|
||||||
logLevel: 1,
|
logLevel: 1,
|
||||||
ChainPad: ChainPad,
|
ChainPad: ChainPad,
|
||||||
classic: true,
|
classic: true,
|
||||||
network: store.network,
|
network: store.network,
|
||||||
owners: owners
|
metadata: {
|
||||||
|
validateKey: secret.keys.validateKey || undefined,
|
||||||
|
owners: owners
|
||||||
|
}
|
||||||
};
|
};
|
||||||
var rt = Listmap.create(listmapConfig);
|
var rt = Listmap.create(listmapConfig);
|
||||||
store.sharedFolders[id] = rt;
|
store.sharedFolders[id] = rt;
|
||||||
|
|||||||
@ -92,9 +92,11 @@ define([
|
|||||||
var hk = network.historyKeeper;
|
var hk = network.historyKeeper;
|
||||||
var cfg = {
|
var cfg = {
|
||||||
validateKey: obj.validateKey,
|
validateKey: obj.validateKey,
|
||||||
lastKnownHash: chan.lastKnownHash || chan.lastCpHash,
|
metadata: {
|
||||||
owners: obj.owners,
|
lastKnownHash: chan.lastKnownHash || chan.lastCpHash,
|
||||||
expire: obj.expire
|
owners: obj.owners,
|
||||||
|
expire: obj.expire
|
||||||
|
}
|
||||||
};
|
};
|
||||||
var msg = ['GET_HISTORY', wc.id, cfg];
|
var msg = ['GET_HISTORY', wc.id, cfg];
|
||||||
// Add the validateKey if we are the channel creator and we have a validateKey
|
// Add the validateKey if we are the channel creator and we have a validateKey
|
||||||
|
|||||||
@ -23,14 +23,12 @@ define([], function () {
|
|||||||
var start = function (conf) {
|
var start = function (conf) {
|
||||||
var channel = conf.channel;
|
var channel = conf.channel;
|
||||||
var Crypto = conf.crypto;
|
var Crypto = conf.crypto;
|
||||||
var validateKey = conf.validateKey;
|
|
||||||
var isNewHash = conf.isNewHash;
|
var isNewHash = conf.isNewHash;
|
||||||
var readOnly = conf.readOnly || false;
|
var readOnly = conf.readOnly || false;
|
||||||
var padRpc = conf.padRpc;
|
var padRpc = conf.padRpc;
|
||||||
var sframeChan = conf.sframeChan;
|
var sframeChan = conf.sframeChan;
|
||||||
var password = conf.password;
|
var metadata= conf.metadata || {};
|
||||||
var owners = conf.owners;
|
var validateKey = metadata.validateKey;
|
||||||
var expire = conf.expire;
|
|
||||||
var onConnect = conf.onConnect || function () { };
|
var onConnect = conf.onConnect || function () { };
|
||||||
conf = undefined;
|
conf = undefined;
|
||||||
|
|
||||||
@ -127,11 +125,8 @@ define([], function () {
|
|||||||
// join the netflux network, promise to handle opening of the channel
|
// join the netflux network, promise to handle opening of the channel
|
||||||
padRpc.joinPad({
|
padRpc.joinPad({
|
||||||
channel: channel || null,
|
channel: channel || null,
|
||||||
validateKey: validateKey,
|
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
owners: owners,
|
metadata: metadata
|
||||||
password: password,
|
|
||||||
expire: expire
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1074,13 +1074,17 @@ define([
|
|||||||
readOnly = false;
|
readOnly = false;
|
||||||
updateMeta();
|
updateMeta();
|
||||||
|
|
||||||
var rtConfig = {};
|
var rtConfig = {
|
||||||
|
metadata: {}
|
||||||
|
};
|
||||||
if (data.owned) {
|
if (data.owned) {
|
||||||
rtConfig.owners = [edPublic];
|
rtConfig.metadata.owners = [edPublic];
|
||||||
}
|
}
|
||||||
if (data.expire) {
|
if (data.expire) {
|
||||||
rtConfig.expire = data.expire;
|
rtConfig.metadata.expire = data.expire;
|
||||||
}
|
}
|
||||||
|
rtConfig.metadata.validateKey = (secret.keys && secret.keys.validateKey) || undefined;
|
||||||
|
|
||||||
Utils.rtConfig = rtConfig;
|
Utils.rtConfig = rtConfig;
|
||||||
nThen(function(waitFor) {
|
nThen(function(waitFor) {
|
||||||
if (data.templateId) {
|
if (data.templateId) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user