|
|
@ -15,9 +15,13 @@ var commands = {};
|
|
|
|
|
|
|
|
|
|
|
|
// ["ADD_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623438989]
|
|
|
|
// ["ADD_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623438989]
|
|
|
|
commands.ADD_OWNERS = function (meta, args) {
|
|
|
|
commands.ADD_OWNERS = function (meta, args) {
|
|
|
|
|
|
|
|
// bail out if args isn't an array
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
throw new Error('METADATA_INVALID_OWNERS');
|
|
|
|
throw new Error('METADATA_INVALID_OWNERS');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// you shouldn't be able to get here if there are no owners
|
|
|
|
|
|
|
|
// because only an owner should be able to change the owners
|
|
|
|
if (!Array.isArray(meta.owners)) {
|
|
|
|
if (!Array.isArray(meta.owners)) {
|
|
|
|
throw new Error("METADATA_NONSENSE_OWNERS");
|
|
|
|
throw new Error("METADATA_NONSENSE_OWNERS");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -30,19 +34,39 @@ commands.ADD_OWNERS = function (meta, args) {
|
|
|
|
|
|
|
|
|
|
|
|
// ["RM_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
|
|
|
|
// ["RM_OWNERS", ["CrufexqXcY-z+eKJlEbNELVy5Sb7E-EAAEFI8GnEtZ0="], 1561623439989]
|
|
|
|
commands.RM_OWNERS = function (meta, args) {
|
|
|
|
commands.RM_OWNERS = function (meta, args) {
|
|
|
|
|
|
|
|
// what are you doing if you don't have owners to remove?
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
throw new Error('METADATA_INVALID_OWNERS');
|
|
|
|
throw new Error('METADATA_INVALID_OWNERS');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there aren't any owners to start, this is also pointless
|
|
|
|
if (!Array.isArray(meta.owners)) {
|
|
|
|
if (!Array.isArray(meta.owners)) {
|
|
|
|
throw new Error("METADATA_NONSENSE_OWNERS");
|
|
|
|
throw new Error("METADATA_NONSENSE_OWNERS");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove owners one by one
|
|
|
|
|
|
|
|
// we assume there are no duplicates
|
|
|
|
args.forEach(function (owner) {
|
|
|
|
args.forEach(function (owner) {
|
|
|
|
var index = meta.owners.indexOf(owner);
|
|
|
|
var index = meta.owners.indexOf(owner);
|
|
|
|
|
|
|
|
if (index < 0) { return; }
|
|
|
|
meta.owners.splice(index, 1);
|
|
|
|
meta.owners.splice(index, 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ["RESET_OWNERS", ["7eEqelGso3EBr5jHlei6av4r9w2B9XZiGGwA1EgZ-5I="], 1561623439989]
|
|
|
|
|
|
|
|
commands.RESET_OWNERS = function (meta, args) {
|
|
|
|
|
|
|
|
// expect a new array, even if it's empty
|
|
|
|
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
|
|
|
|
throw new Error('METADATA_INVALID_OWNERS');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// assume there are owners to start
|
|
|
|
|
|
|
|
if (!Array.isArray(meta.owners)) {
|
|
|
|
|
|
|
|
throw new Error("METADATA_NONSENSE_OWNERS");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// overwrite the existing owners with the new one
|
|
|
|
|
|
|
|
meta.owners = args;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
commands.UPDATE_EXPIRATION = function () {
|
|
|
|
commands.UPDATE_EXPIRATION = function () {
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|