Pin images included in the spreadsheets

pull/1/head
yflory 5 years ago
parent 7f4dbd3245
commit dbb726e4ce

@ -1260,6 +1260,23 @@ define([
return stringify(obj);
};
var pinImages = function () {
if (content.mediasSources) {
var toPin = Object.keys(content.mediasSources || {}).map(function (id) {
var data = content.mediasSources[id] || {};
var src = data.src;
if (!src) { return; }
// Remove trailing slash
if (src.slice(-1) === '/') {
src = src.slice(0, -1);
}
// Extract the channel id from the source href
return src.slice(src.lastIndexOf('/') + 1);
}).filter(Boolean);
sframeChan.query('EV_OO_PIN_IMAGES', toPin);
}
};
APP.getContent = function () { return content; };
APP.onLocal = config.onLocal = function () {
@ -1269,6 +1286,7 @@ define([
// Update metadata
var content = stringifyInner();
APP.realtime.contentUpdate(content);
pinImages();
};
config.onInit = function (info) {
@ -1422,6 +1440,7 @@ define([
handleNewLocks(oldLocks, content.locks);
oldLocks = JSON.parse(JSON.stringify(content.locks));
}
pinImages();
};
config.onAbort = function () {

@ -88,6 +88,32 @@ define([
}, cb);
});
});
sframeChan.on('EV_OO_PIN_IMAGES', function (list) {
Cryptpad.getPadAttribute('ooImages', function (err, res) {
if (err) { return; }
if (!res || !Array.isArray(res)) { res = []; }
var toPin = [];
var toUnpin = [];
res.forEach(function (id) {
if (list.indexOf(id) === -1) {
toUnpin.push(id);
}
});
list.forEach(function (id) {
if (res.indexOf(id) === -1) {
toPin.push(id);
}
});
toPin = Utils.Util.deduplicateString(toPin);
toUnpin = Utils.Util.deduplicateString(toUnpin);
Cryptpad.pinPads(toPin, function () {});
Cryptpad.unpinPads(toUnpin, function () {});
if (!toPin.length && !toUnpin.length) { return; }
Cryptpad.setPadAttribute('ooImages', list, function (err) {
if (err) { console.error(err); }
});
});
});
sframeChan.on('Q_OO_COMMAND', function (obj, cb) {
if (obj.cmd === 'SEND_MESSAGE') {
obj.data.msg = Utils.crypto.encrypt(JSON.stringify(obj.data.msg));

@ -972,16 +972,22 @@ define([
if (!data) { return; }
// Don't pin pads owned by someone else
if (_ownedByOther(Env, data.owners)) { return; }
// Don't push duplicates
// Pin onlyoffice checkpoints
if (data.lastVersion) {
var otherChan = Hash.hrefToHexChannelId(data.lastVersion);
if (result.indexOf(otherChan) === -1) {
result.push(otherChan);
}
}
// Pin onlyoffice realtime patches
if (data.rtChannel && result.indexOf(data.rtChannel) === -1) {
result.push(data.rtChannel);
}
// Pin onlyoffice images
if (data.ooImages && Array.isArray(data.ooImages)) {
Array.prototype.push.apply(result, data.ooImages);
}
// Pin the pad
if (result.indexOf(data.channel) === -1) {
result.push(data.channel);
}

Loading…
Cancel
Save