First import

This commit is contained in:
Luc Didry 2015-03-02 23:44:24 +01:00
commit 0c969d386f
6 changed files with 167 additions and 0 deletions

1
.ep_initialized Normal file
View file

@ -0,0 +1 @@
done

32
README.md Normal file
View file

@ -0,0 +1,32 @@
# Ep_delete_after_delay
Etherpad-Lite plugin that deletes your pads after a configured delay.
## Configuration
Install the plugin and put this in your `settings.json`:
"ep_delete_after_delay": {
"delay": 86400, // one day, in seconds
"text": "The content of this pad has been deleted since it was older than the configured delay."
},
`delay` (mandatory) is in seconds. You can't put `7*86400` for a week, you have to put `604800`.
`text` is the text that will replace the deleted pad's content. Default is what is in the example above.
## License
Copyright 2015 Luc Didry
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

92
delete.js Normal file
View file

@ -0,0 +1,92 @@
var eejs = require('ep_etherpad-lite/node/eejs/'),
padManager = require('ep_etherpad-lite/node/db/PadManager'),
padMessageHandler = require("../../src/node/handler/PadMessageHandler"),
settings = require('../../src/node/utils/Settings');
// Add client code
exports.eejsBlock_scripts = function (hook_name, args, cb) {
args.content = '<script src="../static/plugins/ep_delete_after_delay/static/js/reconnect.js"></script>' + args.content;
}
// Get settings
var areParamsOk = (settings.ep_delete_after_delay) ? true : false,
delay, replaceText;
if (areParamsOk) {
delay = settings.ep_delete_after_delay.delay;
replaceText = settings.ep_delete_after_delay.text || "The content of this pad has been deleted since it was older than the configured delay.";
areParamsOk = (typeof delay === 'number' && delay > 0) ? true : false;
if (areParamsOk === false) {
console.error('ep_delete_after_delay.delay must be a number an not negative! Check you settings.json.');
}
} else {
console.error('You need to configure ep_delete_after_delay in your settings.json!');
}
exports.handleMessage = function(hook_name, context, cb) {
if (areParamsOk === false) return false;
var message = context.message,
type = message.type;
if (type === 'CLIENT_READY' || type === 'COLLABROOM') {
var padId = (type === 'CLIENT_READY') ? message.padId : context.client.rooms[1];
padManager.getPad(padId, function(callback, pad) {
//
// If this is a new pad, there's nothing to do
if (pad.getHeadRevisionNumber() !== 0) {
pad.getLastEdit(function(callback, timestamp) {
var currentTime = (new Date).getTime();
// Are we over delay?
if ((currentTime - timestamp) > (delay * 1000)) {
// Remove pad
padManager.removePad(padId);
console.info('Pad '+padId+' deleted since expired (delay: '+delay+' seconds).');
// Create new pad with an explanation
padManager.getPad(padId, replaceText, function() {
if (type === 'COLLABROOM') {
// Create disconnect message
var msg = {
type: "COLLABROOM",
data: {
type: "CUSTOM",
payload: {
authorId: message.authorId,
action: "requestRECONNECT",
padId: padId
}
}
};
// Send disconnect message to all clients
var sessions = padMessageHandler.sessioninfos;
Object.keys(sessions).forEach(function(key){
var session = sessions[key];
padMessageHandler.handleCustomObjectMessage(msg, false, function(){
// TODO: Error handling
}); // Send a message to this session
});
cb(null);
} else {
cb();
}
});
} else {
console.info('Nothing to do with '+padId+' (not expired)');
cb();
}
});
} else {
console.info('New or empty pad '+padId);
cb()
}
});
} else {
cb();
}
};
// Send
function sendToTarget(message, msg){
}

14
ep.json Normal file
View file

@ -0,0 +1,14 @@
{
"parts": [
{
"name": "ep_delete_after_delay",
"hooks": {
"handleMessage" : "ep_delete_after_delay/delete",
"eejsBlock_scripts": "ep_delete_after_delay/delete"
},
"client_hooks": {
"handleClientMessage_CUSTOM":"ep_delete_after_delay/static/js/reconnect"
}
}
]
}

20
package.json Normal file
View file

@ -0,0 +1,20 @@
{
"name": "ep_delete_after_delay",
"version": "0.0.1",
"description": "Automatically deletes pads after a configured delay",
"author": {
"name": "Luc Didry",
"email": "luc@didry.org",
"url": "https://fiat-tux.fr"
},
"dependencies": {
},
"peerDependencies":{
},
"repository" : {
"type" : "git",
"url" : "https://git.framasoft.org/luc/ep_delete_after_delay.git"
}
}

8
static/js/reconnect.js Normal file
View file

@ -0,0 +1,8 @@
if(typeof exports == 'undefined'){
var exports = this['mymodule'] = {};
}
exports.handleClientMessage_CUSTOM = function(hook, context, wut){
if(context.payload.action === 'requestRECONNECT'){
window.location.reload();
}
}