mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Fallback to owners proofs during migration
This commit is contained in:
parent
18e8f057cb
commit
5fbcd78ab3
@ -415,6 +415,7 @@ const BAD = [
|
|||||||
'limits',
|
'limits',
|
||||||
'customLimits',
|
'customLimits',
|
||||||
'scheduleDecree',
|
'scheduleDecree',
|
||||||
|
'plugins',
|
||||||
|
|
||||||
'httpServer',
|
'httpServer',
|
||||||
|
|
||||||
|
|||||||
@ -737,6 +737,11 @@ BlobStore.create = function (config, _cb) {
|
|||||||
upload_cancel(Env, safeKey, fileSize, cb);
|
upload_cancel(Env, safeKey, fileSize, cb);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isOwnedBy: function (safeKey, blobId, _cb) {
|
||||||
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
|
if (!isValidSafeKey(safeKey)) { return void cb('INVALID_SAFEKEY'); }
|
||||||
|
isOwnedBy(Env, safeKey, blobId, cb);
|
||||||
|
},
|
||||||
readMetadata: (blobId, handler, cb) => {
|
readMetadata: (blobId, handler, cb) => {
|
||||||
if (!isValidId(blobId)) { return void cb("INVALID_ID"); }
|
if (!isValidId(blobId)) { return void cb("INVALID_ID"); }
|
||||||
readBlobMetadata(Env, blobId, handler, cb);
|
readBlobMetadata(Env, blobId, handler, cb);
|
||||||
|
|||||||
@ -158,6 +158,12 @@ const isValidOffsetNumber = function (n) {
|
|||||||
return typeof(n) === 'number' && n >= 0;
|
return typeof(n) === 'number' && n >= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateEnv = data => {
|
||||||
|
const {value} = data;
|
||||||
|
let env = Util.tryParse(value) || {};
|
||||||
|
Env.proofsMigrated = env?.proofsMigrated;
|
||||||
|
};
|
||||||
|
|
||||||
const computeIndexFromOffset = function (channelName, offset, cb) {
|
const computeIndexFromOffset = function (channelName, offset, cb) {
|
||||||
let cpIndex = [];
|
let cpIndex = [];
|
||||||
let messageBuf = [];
|
let messageBuf = [];
|
||||||
@ -576,6 +582,16 @@ const removeOwnedBlob = function (data, cb) {
|
|||||||
return void cb("INSUFFICIENT_PERMISSIONS");
|
return void cb("INSUFFICIENT_PERMISSIONS");
|
||||||
}
|
}
|
||||||
let owners = meta.owners;
|
let owners = meta.owners;
|
||||||
|
if (!owners && !Env.proofsMigrated) {
|
||||||
|
// Check old proofs during migration
|
||||||
|
blobStore.isOwnedBy(safeKey, blobId, w((e, owned) => {
|
||||||
|
if (e || !owned) {
|
||||||
|
w.abort();
|
||||||
|
return void cb("INSUFFICIENT_PERMISSIONS");
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!owners || !owners.includes(unsafeKey)) {
|
if (!owners || !owners.includes(unsafeKey)) {
|
||||||
w.abort();
|
w.abort();
|
||||||
return void cb("INSUFFICIENT_PERMISSIONS");
|
return void cb("INSUFFICIENT_PERMISSIONS");
|
||||||
@ -693,6 +709,7 @@ const getLastChannelTime = function (data, cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const COMMANDS = {
|
const COMMANDS = {
|
||||||
|
ENV_UPDATE: updateEnv,
|
||||||
COMPUTE_INDEX: computeIndex,
|
COMPUTE_INDEX: computeIndex,
|
||||||
COMPUTE_METADATA: computeMetadata,
|
COMPUTE_METADATA: computeMetadata,
|
||||||
GET_OLDER_HISTORY: getOlderHistory,
|
GET_OLDER_HISTORY: getOlderHistory,
|
||||||
@ -848,6 +865,9 @@ process.on('message', function (data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
|
if (data.env) {
|
||||||
|
updateEnv({value:data.env});
|
||||||
|
}
|
||||||
return void init(data.config, function (err) {
|
return void init(data.config, function (err) {
|
||||||
if (err) { return void cb(Util.serializeError(err)); }
|
if (err) { return void cb(Util.serializeError(err)); }
|
||||||
ready = true;
|
ready = true;
|
||||||
|
|||||||
@ -9,6 +9,7 @@ const { fork } = require('child_process');
|
|||||||
const Workers = module.exports;
|
const Workers = module.exports;
|
||||||
const PID = process.pid;
|
const PID = process.pid;
|
||||||
const Block = require("../storage/block");
|
const Block = require("../storage/block");
|
||||||
|
const Environment = require('../env');
|
||||||
|
|
||||||
const DB_PATH = 'lib/workers/db-worker';
|
const DB_PATH = 'lib/workers/db-worker';
|
||||||
const MAX_JOBS = 16;
|
const MAX_JOBS = 16;
|
||||||
@ -256,6 +257,7 @@ Workers.initialize = function (Env, config, _cb) {
|
|||||||
pid: PID,
|
pid: PID,
|
||||||
txid: txid,
|
txid: txid,
|
||||||
config: config,
|
config: config,
|
||||||
|
env: Environment.serialize(Env)
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.on('message', function (res) {
|
worker.on('message', function (res) {
|
||||||
@ -342,7 +344,8 @@ Workers.initialize = function (Env, config, _cb) {
|
|||||||
type: 'broadcast',
|
type: 'broadcast',
|
||||||
pid: PID,
|
pid: PID,
|
||||||
command: data.command,
|
command: data.command,
|
||||||
txid: data.txid
|
txid: data.txid,
|
||||||
|
value: data.value
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return workers;
|
return workers;
|
||||||
|
|||||||
10
server.js
10
server.js
@ -190,7 +190,15 @@ nThen(function (w) {
|
|||||||
|
|
||||||
var throttledEnvChange = Util.throttle(function () {
|
var throttledEnvChange = Util.throttle(function () {
|
||||||
Env.Log.info('WORKER_ENV_UPDATE', 'Updating HTTP workers with latest state');
|
Env.Log.info('WORKER_ENV_UPDATE', 'Updating HTTP workers with latest state');
|
||||||
broadcast('ENV_UPDATE', Environment.serialize(Env));
|
let serialized = Environment.serialize(Env);
|
||||||
|
broadcast('ENV_UPDATE', serialized);
|
||||||
|
if (Env.broadcastWorkerCommand) {
|
||||||
|
Env.broadcastWorkerCommand({
|
||||||
|
command: 'ENV_UPDATE',
|
||||||
|
value: serialized,
|
||||||
|
txid: Util.uid()
|
||||||
|
});
|
||||||
|
}
|
||||||
}, 250); // NOTE: changing this value will impact lib/commands/admin-rpc.js#adminDecree callback
|
}, 250); // NOTE: changing this value will impact lib/commands/admin-rpc.js#adminDecree callback
|
||||||
|
|
||||||
var throttledCacheFlush = Util.throttle(function () {
|
var throttledCacheFlush = Util.throttle(function () {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user