Fix issues with temporary documents

This commit is contained in:
yflory 2024-11-07 16:23:07 +01:00
parent 4a88155581
commit 3de5784be7
3 changed files with 13 additions and 8 deletions

View File

@ -67,10 +67,7 @@ module.exports.create = function (Env, cb) {
}
if (metadata && metadata.selfdestruct && metadata.selfdestruct !== Env.id) {
if (Env.store) {
Env.store.archiveChannel(channelName, false,
() => {});
}
HK.removeChannel(Env, channelName);
return void cb('ESELFDESTRUCT');
}

View File

@ -134,6 +134,13 @@ const expireChannel = HK.expireChannel = function (Env, channel) {
});
};
const removeChannel = HK.removeChannel = function (Env, channel) {
if (!Env.store) { return; }
Env.store.archiveChannel(channel, void 0, () => {});
delete Env.metadata_cache[channel];
delete Env.channel_cache[channel];
};
/* dropChannel
* cleans up memory structures which are managed entirely by the historyKeeper
*/
@ -143,8 +150,7 @@ const dropChannel = HK.dropChannel = function (Env, chanName) {
delete Env.channel_cache[chanName];
if (meta && meta.selfdestruct && Env.selfDestructTo) {
Env.selfDestructTo[chanName] = setTimeout(function () {
if (!Env.store) { return; }
Env.store.archiveChannel(chanName, false, () => {});
removeChannel(Env, chanName);
}, TEMPORARY_CHANNEL_LIFETIME);
}
if (Env.store) { Env.store.closeChannel(chanName, function () {}); }
@ -693,6 +699,7 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) {
}, (err, reason) => {
// Any error but ENOENT: abort
// ENOENT is allowed in case we want to create a new pad
if (err && err.error) { err = err.error; }
if (err && err.code !== 'ENOENT') {
if (err.message === "EUNKNOWN") {
Log.error("HK_GET_HISTORY", {
@ -708,7 +715,7 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) {
stack: err && err.stack,
}); }
// FIXME err.message isn't useful for users
const parsedMsg = {error:err.message, channel: channelName, txid: txid};
const parsedMsg = {error:err.message || 'ERROR', channel: channelName, txid: txid};
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(parsedMsg)]);
return;
}

View File

@ -1843,7 +1843,7 @@ define([
Store.leavePad(null, data, function () {});
};
var conf = {
Cache: Cache, // ICE pad cache
Cache: store.neverCache ? undefined : Cache, // ICE pad cache
onCacheStart: function () {
postMessage(clientId, "PAD_CACHE");
},
@ -3271,6 +3271,7 @@ define([
// ==> don't create a drive
// Or "neverDrive" (integration into another platform?)
// ==> don't create a drive BUT create temp RPC (we may need to upload)
if (data.neverDrive) { store.neverCache = true; }
if (data.neverDrive || (data.noDrive && !data.userHash && !data.anonHash)) {
return void onNoDrive(clientId, function (obj) {
if (obj && obj.error) {