mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
pluginfw: Export .etherpad hooks (#4466)
* export support * proper prefix * just a basic example, needs working on still * docs * comments shouldnt be hard coded
This commit is contained in:
parent
d5c5ca224b
commit
3fa58efede
3 changed files with 42 additions and 0 deletions
|
@ -751,6 +751,21 @@ exports.exportHtmlAdditionalTagsWithData = function(hook, pad, cb){
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## exportEtherpadAdditionalContent
|
||||||
|
Called from src/node/utils/ExportEtherpad.js and src/node/utils/ImportEtherpad.js
|
||||||
|
|
||||||
|
Things in context:
|
||||||
|
|
||||||
|
Useful for exporting and importing non-pad centric data stored about a pad. For example in ep_comments_page the comments are stored as comments:padId:uniqueIdOfComment and as such when you export .etherpad this data is not included.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
// Add support for exporting comments metadata
|
||||||
|
exports.exportEtherpadAdditionalContent = function(hook_name, context, callback){
|
||||||
|
return callback(["comments"]);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
## userLeave
|
## userLeave
|
||||||
Called from src/node/handler/PadMessageHandler.js
|
Called from src/node/handler/PadMessageHandler.js
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
|
|
||||||
let db = require("../db/DB");
|
let db = require("../db/DB");
|
||||||
|
let hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
|
|
||||||
exports.getPadRaw = async function(padId) {
|
exports.getPadRaw = async function(padId) {
|
||||||
|
|
||||||
|
@ -58,5 +59,17 @@ exports.getPadRaw = async function(padId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
// get content that has a different prefix IE comments:padId:foo
|
||||||
|
// a plugin would return something likle ["comments", "cakes"]
|
||||||
|
hooks.aCallAll('exportEtherpadAdditionalContent').then((prefixes) => {
|
||||||
|
prefixes.forEach(async function(prefix) {
|
||||||
|
let pluginContent = await db.get(prefix + ":" + padId);
|
||||||
|
data[prefix + ":" + padId] = pluginContent;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
var log4js = require('log4js');
|
var log4js = require('log4js');
|
||||||
const db = require("../db/DB");
|
const db = require("../db/DB");
|
||||||
|
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||||
|
|
||||||
exports.setPadRaw = function(padId, records)
|
exports.setPadRaw = function(padId, records)
|
||||||
{
|
{
|
||||||
|
@ -62,6 +63,19 @@ exports.setPadRaw = function(padId, records)
|
||||||
// and create the value
|
// and create the value
|
||||||
newKey = oldPadId.join(":"); // create the new key
|
newKey = oldPadId.join(":"); // create the new key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is this a key that is supported through a plugin?
|
||||||
|
await Promise.all([
|
||||||
|
// get content that has a different prefix IE comments:padId:foo
|
||||||
|
// a plugin would return something likle ["comments", "cakes"]
|
||||||
|
hooks.aCallAll('exportEtherpadAdditionalContent').then((prefixes) => {
|
||||||
|
prefixes.forEach(async function(prefix) {
|
||||||
|
if(key.split(":")[0] === prefix){
|
||||||
|
newKey = prefix + ":" + padId;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the value to the server
|
// Write the value to the server
|
||||||
|
|
Loading…
Reference in a new issue