1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-23 02:34:53 +00:00

AWS Plugin: Add s3-load and s3-rendertiddlers commands

With these commands we can do static rendering straight to an S3 bucket
This commit is contained in:
Jermolene
2017-08-15 15:48:12 +01:00
parent 1088b01f96
commit 509a474f4a
3 changed files with 147 additions and 8 deletions

View File

@@ -13,14 +13,44 @@ AWS utility functions
"use strict";
/*
Put a file to an S3 bucket
Get a file from an S3 bucket
region:
bucketName:
title:
callback: invoked with (err,{body:,type:}
*/
function putFile(region,bucketName,title,text,type,callback) {
console.log("Writing file",bucketName,title,type)
function getTextFile(region,bucketName,title,callback) {
console.log("Reading file from S3",bucketName,title)
var AWS = require("aws-sdk"),
s3bucket = new AWS.S3({
region: region
}),
region: region
}),
params = {
Bucket: bucketName,
Key: title
};
s3bucket.getObject(params,function(err,data) {
if(err) {
return callback(err);
}
callback(null,{
etag: data.ETag,
version: data.VersionId,
type: data.ContentType,
body: data.Body.toString()
});
});
}
/*
Put a file to an S3 bucket
*/
function putTextFile(region,bucketName,title,text,type,callback) {
console.log("Writing file to S3",bucketName,title,type)
var AWS = require("aws-sdk"),
s3bucket = new AWS.S3({
region: region
}),
encoding = ($tw.config.contentTypeInfo[type] || {encoding: "utf8"}).encoding,
params = {
Bucket: bucketName,
@@ -31,6 +61,7 @@ console.log("Writing file",bucketName,title,type)
s3bucket.upload(params,callback);
}
exports.putFile = putFile;
exports.putTextFile = putTextFile;
exports.getTextFile = getTextFile;
})();