Zips or unzips a page and its attachments
Get parameters
- action = "zip" or "unzip"
- pageName = Page name to zip/unzip
- fileName = File name to unzip (required for "unzip" action)
Get examples:
// Simple URL - zip a page
/OpenForum/Actions/Zip?action=zip&pageName=/MyPage
// Using JSON.get - unzip a file
JSON.get('/OpenForum/Actions/Zip', 'unzip', 'pageName=/MyPage&fileName=backup.zip')
.onSuccess(function(result) {
console.log('Unzipped:', result);
}).go();
Get Action
Server Side Javascript for GET method
//OpenForum/Actions/Zip/get.sjs
var action = transaction.getParameter("action");
if(action===null) {
transaction.setResult(transaction.SHOW_PAGE);
return;
}
try{
action = ""+action;
var pageName = ""+transaction.getParameter("pageName");
result = {result: "error", message: "Action "+action+" not recognised."};
if(action === "zip") {
file.zipPage( pageName );
wiki.buildPage( pageName );
var fileName = pageName.substring(pageName.lastIndexOf("/"))+".wiki.zip";
transaction.goToPage( pageName+"/"+fileName );
return;
} else if(action === "unzip") {
var fileName = transaction.getParameter("fileName");
file.unZipAttachment(pageName,fileName);
result = JSON.stringify({result: "ok"});
}
} catch(e) {
transaction.sendJSON( JSON.stringify({result: "error",message: "Error:"+e}));
return;
}
transaction.sendJSON( JSON.stringify(result) );