1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-14 12:48:05 +00:00
Files
TiddlyWiki5/plugins/tiddlywiki/aws/modules/utils.js
Mario Pietsch 8aa558eb2c Remove module function wrapper and add matching configurations for dprint and eslint (#7596)
* remove blks first try

* dprint.json seems to be OK, some forgotten functions

* add some more space-after-keyword settings

* server remove blks

* add **/files to dprint exclude

* dprint.js fixes a typo

* add boot.js and bootprefix.js to dprint exclude

* dprint change dprint.json

* add dprint fmt as script

* remove jslint comments

* fix whitespace

* fix whitespace

* remove function-wrapper from geospatial plugin

* fix whitespace

* add function wrapper to dyannotate-startup

* remove dpring.json
2025-03-21 17:22:57 +00:00

72 lines
1.5 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/aws/utils.js
type: application/javascript
module-type: library
AWS utility functions
\*/
"use strict";
/*
Get a file from an S3 bucket
region:
bucketName:
title:
callback: invoked with (err,{body:,type:}
*/
function getFile(region,bucketName,title,callback) {
// console.log("Reading file from S3",bucketName,title);
var AWS = require("aws-sdk"),
s3bucket = new AWS.S3({
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 putFile(region,bucketName,title,text,type,callback) {
// Log the write
if($tw["lambda-result"]) {
$tw["lambda-result"]["files-written"].push({bucket: bucketName,key: title});
}
// 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,
Key: title,
Body: new Buffer(text,encoding),
ContentType: type || "text/plain"
};
s3bucket.upload(params,function(err,data) {
if(err) {
return callback(err + " (writing " + title + " to " + bucketName + ", type " + type + ")");
}
callback(null,data);
});
}
exports.putFile = putFile;
exports.getFile = getFile;