node-red-contrib-aws-s3
Version:
A Node-RED node to watch, save and retreive files from an Amazon S3 bucket
361 lines (358 loc) • 17.8 kB
HTML
<script type="text/x-red" data-template-name="aws-s3-in">
<div class="form-row">
<label for="node-input-aws"><i class="fa fa-user"></i> <span data-i18n="aws.label.aws"></span></label>
<input type="text" id="node-input-aws">
</div>
<div class="form-row">
<label for="node-input-bucket"><i class="fa fa-folder"></i> <span data-i18n="aws.label.bucket"></span></label>
<input type="text" id="node-input-bucket" style="width: 70%;">
<input type="hidden" id="node-input-bucketType">
</div>
<div class="form-row node-input-filepattern">
<label for="node-input-filepattern"><i class="fa fa-file"></i> <span data-i18n="aws.label.pattern"></span></label>
<input type="text" id="node-input-filepattern" data-i18n="[placeholder]aws.placeholder.pattern">
</div>
<div class="form-row">
<label for="node-input-pollingInterval"><i class="fa fa-clock-o"></i> Polling Interval (seconds)</label>
<input type="number" id="node-input-pollingInterval" placeholder="900" min="30" step="1">
</div>
<div class="form-row">
<span style="color: #888; font-size: 0.90em;">Minimum 30 seconds. Default is 900 seconds (15 minutes).</span>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="aws.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]aws.placeholder.name">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws-s3-in',{
category: 'storage-input',
color:"#ff7919",
defaults: {
aws: {type:"aws-s3-config",required:true},
bucket: {value:""},
bucketType: {value:"str"},
filepattern: {value:""},
name: {value:""},
pollingInterval: {value:900}
},
inputs:0,
outputs:1,
icon: "amazon.png",
label: function() {
return this.name ? this.name : "s3 " + this.bucket;
},
oneditprepare: function() {
$("#node-input-bucket").typedInput({
default: 'str',
types: ['str', 'msg', 'flow', 'global', 'env'],
typeField: "#node-input-bucketType"
});
$("#node-input-bucket").typedInput('type', this.bucketType || 'str');
$("#node-input-bucket").typedInput('value', this.bucket || '');
// Устанавливаем значение pollingInterval
$("#node-input-pollingInterval").val(this.pollingInterval || 900);
},
oneditsave: function() {
this.bucketType = $("#node-input-bucketType").val();
this.bucket = $("#node-input-bucket").typedInput('value');
// Сохраняем pollingInterval с валидацией
var interval = parseInt($("#node-input-pollingInterval").val()) || 900;
if (interval < 30) interval = 30; // Минимум 30 секунд
this.pollingInterval = interval;
}
});
</script>
<script type="text/x-red" data-template-name="aws-s3-handle">
<div class="form-row">
<label for="node-input-aws"><i class="fa fa-user"></i> <span data-i18n="aws.label.aws"></span></label>
<input type="text" id="node-input-aws">
</div>
<div class="form-row">
<label for="node-input-bucket"><i class="fa fa-folder"></i> <span data-i18n="aws.label.bucket"></span></label>
<input type="text" id="node-input-bucket" style="width: 70%;">
<input type="hidden" id="node-input-bucketType">
</div>
<div class="form-row node-input-filename">
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="aws.label.filename"></span></label>
<input type="text" id="node-input-filename" data-i18n="[placeholder]aws.placeholder.filename">
</div>
<div class="form-row">
<label for="node-input-createSignedUrl"><i class="fa fa-link"></i>
<span data-i18n="aws.label.createSignedUrl"></span>
</label>
<select type="text" id="node-input-createSignedUrl" style="width:70%;">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</div>
<div class="form-row">
<label for="node-input-urlExpiration"><i class="fa fa-clock-o"></i> <span data-i18n="aws.label.urlExpiration"></span></label>
<input type="number" id="node-input-urlExpiration" placeholder="URL Expiration (seconds)">
</div>
<div class="form-row">
<label for="node-input-returnBuffer"><i class="fa fa-file"></i>
<span data-i18n="aws.label.returnBuffer"></span>
</label>
<select type="text" id="node-input-returnBuffer" style="width:70%;">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="aws.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]aws.placeholder.name">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws-s3-handle',{
category: 'storage-output',
color:"#ff7919",
defaults: {
aws: {type:"aws-s3-config",required:true},
bucket: {value:""},
bucketType: {value:"str"},
filename: {value:""},
name: {value:""},
createSignedUrl: {value:"no"},
returnBuffer: {value:"yes"},
},
inputs:1,
outputs:1,
icon: "amazon.png",
align: "right",
label: function() {
return this.name ? this.name : "s3 "+this.bucket;
},
oneditprepare: function() {
$("#node-input-bucket").typedInput({
default: 'str',
types: ['str', 'msg', 'flow', 'global', 'env'],
typeField: "#node-input-bucketType"
});
$("#node-input-bucket").typedInput('type', this.bucketType || 'str');
$("#node-input-bucket").typedInput('value', this.bucket || '');
if (this.urlExpiration !== undefined) {
$("#node-input-urlExpiration").val(this.urlExpiration);
}
},
oneditsave: function() {
this.bucketType = $("#node-input-bucketType").val();
this.bucket = $("#node-input-bucket").typedInput('value');
this.urlExpiration = $("#node-input-urlExpiration").val();
}
});
</script>
<script type="text/x-red" data-template-name="aws-s3-out">
<div class="form-row">
<label for="node-input-aws"><i class="fa fa-user"></i> <span data-i18n="aws.label.aws"></span></label>
<input type="text" id="node-input-aws">
</div>
<div class="form-row">
<label for="node-input-bucket"><i class="fa fa-folder"></i> <span data-i18n="aws.label.bucket"></span></label>
<input type="text" id="node-input-bucket" style="width: 70%;">
<input type="hidden" id="node-input-bucketType">
</div>
<div class="form-row node-input-filename">
<label for="node-input-filename"><i class="fa fa-file"></i> <span data-i18n="aws.label.filename"></span></label>
<input type="text" id="node-input-filename" data-i18n="[placeholder]aws.placeholder.filename">
</div>
<div class="form-row node-input-localFilename">
<label for="node-input-localFilename"><i class="fa fa-file"></i> <span data-i18n="aws.label.local"></span></label>
<input type="text" id="node-input-localFilename" data-i18n="[placeholder]aws.placeholder.local">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="aws.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]aws.placeholder.name">
</div>
<div class="form-row">
<input type="checkbox" id="node-input-sendOutput" style="width: auto; margin-right: 8px;">
<label for="node-input-sendOutput" style="display: inline; font-weight: 500;">Send output</label>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws-s3-out',{
category: 'storage-output',
color:"#ff7919",
defaults: {
aws: {type:"aws-s3-config",required:true},
bucket: {value:""},
bucketType: {value:"str"},
filename: {value:""},
localFilename: {value:""},
name: {value:""},
sendOutput: {value:false},
outputs: {value:0}
},
inputs:1,
outputs:0,
icon: "amazon.png",
align: "right",
label: function() {
return this.name ? this.name : "s3 " + this.bucket;
},
oneditprepare: function() {
$("#node-input-bucket").typedInput({
default: 'str',
types: ['str', 'msg', 'flow', 'global', 'env'],
typeField: "#node-input-bucketType"
});
$("#node-input-bucket").typedInput('type', this.bucketType || 'str');
$("#node-input-bucket").typedInput('value', this.bucket || '');
// Устанавливаем состояние чекбокса
$("#node-input-sendOutput").prop("checked", this.sendOutput === true || this.sendOutput === "true");
},
oneditsave: function() {
this.bucketType = $("#node-input-bucketType").val();
this.bucket = $("#node-input-bucket").typedInput('value');
var hasOutput = $("#node-input-sendOutput").is(":checked");
this.sendOutput = hasOutput;
this.outputs = hasOutput ? 1 : 0;
}
});
</script>
<script type="text/x-red" data-template-name="aws-s3-config">
<div class="form-row">
<label for="node-config-input-configname"><i class="fa fa-bookmark"></i> <span data-i18n="aws.label.configname"></span></label>
<input class="input-append-left" type="text" id="node-config-input-configname" style="width: 40%;" >
</div>
<div class="form-row">
<input type="checkbox" id="node-config-input-useIamRole" style="width: auto; margin-right: 8px;">
<label for="node-config-input-useIamRole" style="display: inline; font-weight: 500;">
Use IAM Role for authentication
</label>
</div>
<div class="form-row">
<span style="color: #888; font-size: 0.90em;">Recommended for EC2/ECS/Lambda.</span><br/>
<span style="color: #888; font-size: 0.90em;">When enabled, credentials fields are ignored and AWS SDK will use the instance IAM role.</span>
</div>
<div class="credentials-fields">
<div class="form-row">
<label for="node-config-input-accessKeyId-typed"><i class="fa fa-bookmark"></i> <span data-i18n="aws.label.keyid"></span></label>
<input type="text" id="node-config-input-accessKeyId-typed" style="width: 70%;">
<input type="hidden" id="node-config-input-accessKeyIdType">
</div>
<div class="form-row">
<label for="node-config-input-secretAccessKey-typed"><i class="fa fa-bookmark"></i> <span data-i18n="aws.label.secret"></span></label>
<input type="password" id="node-config-input-secretAccessKey-typed" style="width: 70%;">
<input type="hidden" id="node-config-input-secretAccessKeyType">
</div>
</div>
<div class="form-row">
<label for="node-config-input-region-typed"><i class="fa fa-tag"></i> <span data-i18n="aws.label.region"></span></label>
<input type="text" id="node-config-input-region-typed" style="width: 70%;">
<input type="hidden" id="node-config-input-regionType">
</div>
<div class="form-row">
<label for="node-config-input-endpoint-typed"><i class="fa fa-tag"></i> <span data-i18n="aws.label.endpoint"></span></label>
<input type="text" id="node-config-input-endpoint-typed" style="width: 70%;">
<input type="hidden" id="node-config-input-endpointType">
</div>
<div class="form-tips">
<span data-i18n="[html]aws.tip.config1"></span>
<span data-i18n="[html]aws.tip.config2"></span>
</div>
<div class="form-row">
<label for="node-config-input-forcepathstyle"><i class="fa fa-tag"></i> <span data-i18n="aws.label.forcepathstyle"></span></label>
<input class="input-append-left" type="checkbox" id="node-config-input-forcepathstyle">
</div>
<div class="form-row">
<label for="node-config-input-skiptlsverify"><i class="fa fa-tag"></i> <span data-i18n="aws.label.skiptlsverify"></span></label>
<input class="input-append-left" type="checkbox" id="node-config-input-skiptlsverify">
</div>
<div class="form-tips">
<span data-i18n="[html]aws.tip.config3"></span>
<span data-i18n="[html]aws.tip.config4"></span>
</div>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('aws-s3-config',{
category: 'config',
defaults: {
configname: {value:"", required:true},
endpoint: {value:""},
endpointType: {value:"str"},
forcepathstyle: {value:false},
skiptlsverify: {value:false},
useIamRole: {value:false},
accessKeyId: {value:""},
accessKeyIdType: {value:"str"},
secretAccessKey: {value:""},
secretAccessKeyType: {value:"str"},
region: {value:"eu-west-1"},
regionType: {value:"str"}
},
credentials: {
accesskeyid: {type:"text"},
secretaccesskey: {type:"password"}
},
label: function() {
return this.configname;
},
oneditprepare: function() {
var stdTypes = ['str', 'flow', 'global', 'env', 'msg'];
$("#node-config-input-accessKeyId-typed").typedInput({
default: 'str',
types: stdTypes,
typeField: "#node-config-input-accessKeyIdType"
});
$("#node-config-input-accessKeyId-typed").typedInput('type', this.accessKeyIdType || 'str');
$("#node-config-input-accessKeyId-typed").typedInput('value', this.accessKeyId || '');
$("#node-config-input-secretAccessKey-typed").typedInput({
default: 'str',
types: stdTypes,
typeField: "#node-config-input-secretAccessKeyType"
});
$("#node-config-input-secretAccessKey-typed").typedInput('type', this.secretAccessKeyType || 'str');
$("#node-config-input-secretAccessKey-typed").typedInput('value', this.secretAccessKey || '');
$("#node-config-input-region-typed").typedInput({
default: 'str',
types: stdTypes,
typeField: "#node-config-input-regionType"
});
$("#node-config-input-region-typed").typedInput('type', this.regionType || 'str');
$("#node-config-input-region-typed").typedInput('value', this.region || '');
$("#node-config-input-endpoint-typed").typedInput({
default: 'str',
types: stdTypes,
typeField: "#node-config-input-endpointType"
});
$("#node-config-input-endpoint-typed").typedInput('type', this.endpointType || 'str');
$("#node-config-input-endpoint-typed").typedInput('value', this.endpoint || '');
$("#node-config-input-useIamRole").on("change", function() {
if ($(this).is(":checked")) {
$(".credentials-fields").hide();
} else {
$(".credentials-fields").show();
}
});
if ($("#node-config-input-useIamRole").is(":checked")) {
$(".credentials-fields").hide();
}
},
oneditsave: function() {
this.accessKeyId = $("#node-config-input-accessKeyId-typed").typedInput('value');
this.accessKeyIdType = $("#node-config-input-accessKeyId-typed").typedInput('type');
this.secretAccessKey = $("#node-config-input-secretAccessKey-typed").typedInput('value');
this.secretAccessKeyType = $("#node-config-input-secretAccessKey-typed").typedInput('type');
this.region = $("#node-config-input-region-typed").typedInput('value');
this.regionType = $("#node-config-input-region-typed").typedInput('type');
this.endpoint = $("#node-config-input-endpoint-typed").typedInput('value');
this.endpointType = $("#node-config-input-endpoint-typed").typedInput('type');
}
});
})();
</script>
<script type="text/javascript">
var stdTypes = ['str', 'flow', 'global', 'env', 'msg'];
function prepareTypedInput(selector, typeSelector, value, type) {
$(selector).typedInput({
default: 'str',
types: stdTypes,
typeField: typeSelector
});
$(selector).typedInput('type', type || 'str');
$(selector).typedInput('value', value || '');
}
</script>