2016-12-21 12:09:04 +00:00
|
|
|
/*\
|
2016-12-22 08:15:16 +00:00
|
|
|
title: $:/core/modules/savers/beaker.js
|
2016-12-21 12:09:04 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: saver
|
|
|
|
|
2016-12-22 08:15:16 +00:00
|
|
|
Saves files using the Beaker browser's (https://beakerbrowser.com) Dat protocol (https://datproject.org/)
|
2016-12-21 12:09:04 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
2016-12-22 08:15:16 +00:00
|
|
|
Set up the saver
|
2016-12-21 12:09:04 +00:00
|
|
|
*/
|
2016-12-22 08:15:16 +00:00
|
|
|
var BeakerSaver = function(wiki) {
|
2016-12-21 12:09:04 +00:00
|
|
|
this.wiki = wiki;
|
|
|
|
};
|
|
|
|
|
2016-12-22 08:15:16 +00:00
|
|
|
BeakerSaver.prototype.save = function(text,method,callback) {
|
2016-12-29 16:45:47 +00:00
|
|
|
var url = (location.toString()).split("#")[0];
|
|
|
|
dat.stat(url).then(function(value) {
|
|
|
|
if(value.type === "directory") {
|
|
|
|
url = url + "/index.html";
|
|
|
|
}
|
|
|
|
dat.writeFile(url,text,"utf8").then(function(value) {
|
|
|
|
callback(null);
|
|
|
|
},function(reason) {
|
|
|
|
callback("Beaker Saver Write Error: " + reason);
|
|
|
|
});
|
2016-12-21 12:09:04 +00:00
|
|
|
},function(reason) {
|
2016-12-29 16:45:47 +00:00
|
|
|
callback("Beaker Saver Stat Error: " + reason);
|
2016-12-21 12:09:04 +00:00
|
|
|
});
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Information about this saver
|
|
|
|
*/
|
2016-12-22 08:15:16 +00:00
|
|
|
BeakerSaver.prototype.info = {
|
|
|
|
name: "beaker",
|
2016-12-21 12:09:04 +00:00
|
|
|
priority: 3000,
|
|
|
|
capabilities: ["save", "autosave"]
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Static method that returns true if this saver is capable of working
|
|
|
|
*/
|
|
|
|
exports.canSave = function(wiki) {
|
|
|
|
return !!window.dat;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create an instance of this saver
|
|
|
|
*/
|
|
|
|
exports.create = function(wiki) {
|
2016-12-22 08:15:16 +00:00
|
|
|
return new BeakerSaver(wiki);
|
2016-12-21 12:09:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|