mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Compute new metadata first and fallback to old system if needed
This commit is contained in:
parent
3863888fd3
commit
44aee13a56
@ -429,7 +429,27 @@ How to proceed
|
||||
|
||||
*/
|
||||
|
||||
let requiresChannel = true;
|
||||
let all = [];
|
||||
nThen(function (w) {
|
||||
let first = true;
|
||||
getDedicatedMetadata(env, channelId, (err, line) => {
|
||||
if (first && !err) {
|
||||
if (!Array.isArray(line)) {
|
||||
requiresChannel = false;
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
all.push({err, line});
|
||||
}, w(function (err) {
|
||||
if (err) {
|
||||
// stream errors?
|
||||
w.abort();
|
||||
return void cb(err);
|
||||
}
|
||||
}));
|
||||
}).nThen(function (w) {
|
||||
if (!requiresChannel) { return; }
|
||||
// returns the first line of a channel, parsed...
|
||||
getChannelMetadata(env, channelId, w(function (err, data) {
|
||||
if (err) {
|
||||
@ -445,13 +465,10 @@ How to proceed
|
||||
handler(null, data);
|
||||
}));
|
||||
}).nThen(function () {
|
||||
getDedicatedMetadata(env, channelId, handler, function (err) {
|
||||
if (err) {
|
||||
// stream errors?
|
||||
return void cb(err);
|
||||
}
|
||||
cb();
|
||||
all.forEach(({err, line}) => {
|
||||
handler(err, line);
|
||||
});
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
{"owners":["TestOwner"],"validateKey":"TestKey","channel":"0","created":1721035117462}
|
||||
[0,"test","MSG","test",1721035117969]
|
||||
[0,"test","MSG","test2",1721035117969]
|
||||
[0,"test","MSG","test3",1721035117969]
|
||||
[0,"test","MSG","test4",1721035117969]
|
||||
[0,"test","MSG","test5",1721035117969]
|
||||
[0,"test","MSG","test6",1721035117969]
|
||||
@ -0,0 +1,5 @@
|
||||
["RESTRICT_ACCESS",[true],1721035145090]
|
||||
["ADD_ALLOWED",["NewAllowedKeyNewAllowedKeyNewAllowedKeyNewAl"],1721035148115]
|
||||
["ADD_PENDING_OWNERS",["PendingOwner"],1721035151295]
|
||||
["RESTRICT_ACCESS",[false],1721035155836]
|
||||
["RESTRICT_ACCESS",[true],1721035156728]
|
||||
@ -0,0 +1,7 @@
|
||||
{"owners":["TestOwner"],"validateKey":"TestKey","channel":"0","created":1721035117462}
|
||||
[0,"test","MSG","test",1721035117969]
|
||||
[0,"test","MSG","test2",1721035117969]
|
||||
[0,"test","MSG","test3",1721035117969]
|
||||
[0,"test","MSG","test4",1721035117969]
|
||||
[0,"test","MSG","test5",1721035117969]
|
||||
[0,"test","MSG","test6",1721035117969]
|
||||
@ -0,0 +1 @@
|
||||
{"owners":["TestOwner"],"validateKey":"TestKey","channel":"0","created":1721035117462}
|
||||
@ -0,0 +1,6 @@
|
||||
[0,"test","MSG","test",1721035117969]
|
||||
[0,"test","MSG","test2",1721035117969]
|
||||
[0,"test","MSG","test3",1721035117969]
|
||||
[0,"test","MSG","test4",1721035117969]
|
||||
[0,"test","MSG","test5",1721035117969]
|
||||
[0,"test","MSG","test6",1721035117969]
|
||||
@ -0,0 +1,6 @@
|
||||
{"owners":["TestOwner"],"validateKey":"TestKey","channel":"0","created":1721035117462}
|
||||
["RESTRICT_ACCESS",[true],1721035145090]
|
||||
["ADD_ALLOWED",["NewAllowedKeyNewAllowedKeyNewAllowedKeyNewAl"],1721035148115]
|
||||
["ADD_PENDING_OWNERS",["PendingOwner"],1721035151295]
|
||||
["RESTRICT_ACCESS",[false],1721035155836]
|
||||
["RESTRICT_ACCESS",[true],1721035156728]
|
||||
@ -0,0 +1,6 @@
|
||||
[0,"test","MSG","test",1721035117969]
|
||||
[0,"test","MSG","test2",1721035117969]
|
||||
[0,"test","MSG","test3",1721035117969]
|
||||
[0,"test","MSG","test4",1721035117969]
|
||||
[0,"test","MSG","test5",1721035117969]
|
||||
[0,"test","MSG","test6",1721035117969]
|
||||
@ -0,0 +1,6 @@
|
||||
[0,"test","MSG","test",1721035117969]
|
||||
[0,"test","MSG","test2",1721035117969]
|
||||
[0,"test","MSG","test3",1721035117969]
|
||||
[0,"test","MSG","test4",1721035117969]
|
||||
[0,"test","MSG","test5",1721035117969]
|
||||
[0,"test","MSG","test6",1721035117969]
|
||||
60
scripts/tests/test-metadata.js
Normal file
60
scripts/tests/test-metadata.js
Normal file
@ -0,0 +1,60 @@
|
||||
const Store = require("../../lib/storage/file");
|
||||
const Meta = require("../../lib/metadata");
|
||||
const nThen = require('nthen');
|
||||
|
||||
let chanOld = '00000000000000000000000000000000';
|
||||
let chanOldUpdated = '00000000000000000000000000000001';
|
||||
let chanNew = '00000000000000000000000000000002';
|
||||
let chanNewUpdated = '00000000000000000000000000000003';
|
||||
let chanNoMeta = '00000000000000000000000000000004';
|
||||
|
||||
Store.create({
|
||||
filePath: './test-data/'
|
||||
}, (err, store) => {
|
||||
if (err) { return void console.error(err); }
|
||||
|
||||
const readMetadata = (channel, cb) => {
|
||||
const ref = {};
|
||||
const h = Meta.createLineHandler(ref, console.error);
|
||||
store.readChannelMetadata(channel, h, () => {
|
||||
cb(ref && ref.meta);
|
||||
});
|
||||
};
|
||||
|
||||
nThen(w => {
|
||||
readMetadata(chanOld, w(meta => {
|
||||
if (!meta || meta.validateKey !== "TestKey") {
|
||||
console.log('OldChanNoUpdate', meta);
|
||||
throw new Error("Error with old channel without metadata update");
|
||||
}
|
||||
}));
|
||||
readMetadata(chanOldUpdated, w(meta => {
|
||||
if (!meta || meta.validateKey !== "TestKey" || !meta.restricted || !meta.allowed.includes('NewAllowedKeyNewAllowedKeyNewAllowedKeyNewAl')) {
|
||||
console.log('OldChanUpdate', meta);
|
||||
throw new Error("Error with old channel with metadata updates");
|
||||
}
|
||||
}));
|
||||
readMetadata(chanNew, w(meta => {
|
||||
if (!meta || meta.validateKey !== "TestKey") {
|
||||
console.log('NewChanNoUpdate', meta);
|
||||
throw new Error("Error with new channel without metadata update");
|
||||
}
|
||||
}));
|
||||
readMetadata(chanNewUpdated, w(meta => {
|
||||
if (!meta || meta.validateKey !== "TestKey" || !meta.restricted || !meta.allowed.includes('NewAllowedKeyNewAllowedKeyNewAllowedKeyNewAl')) {
|
||||
console.log('NewChanUpdate', meta);
|
||||
throw new Error("Error with new channel with metadata updates");
|
||||
}
|
||||
}));
|
||||
readMetadata(chanNoMeta, w(meta => {
|
||||
if (meta && Object.keys(meta).length) {
|
||||
console.log('NoMetadataChan', meta);
|
||||
throw new Error("Error with channel without metadata");
|
||||
}
|
||||
}));
|
||||
}).nThen(() => {
|
||||
console.log('Success');
|
||||
process.exit(1);
|
||||
});
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user