Files

142 lines
7.2 KiB
HTML

<script type="text/javascript">
RED.nodes.registerType('file-operations', {
category: 'nextcloud',
color: '#FF9900',
defaults: {
name: { value: "" },
nextcloud: { type: "nextcloud-config", required: true },
operation: { value: "list" },
ncUser: { value: "" },
ncPath: { value: "" },
ncFolder: { value: "" },
destination: { value: "" },
bodySharePath: { value: "" },
bodyShareType: { value: "" },
bodyPermissions: { value: "" },
bodyShareWith: { value: "" }
},
inputs: 1,
outputs: 1,
icon: "file.svg",
label: function() { return this.name || "File Operations"; },
oneditprepare: function() {
var opMeta = {
'list': { method: 'PROPFIND', user: true, folder: true, path: false, dest: false, share: false },
'get': { method: 'GET', user: true, folder: false, path: true, dest: false, share: false },
'upload': { method: 'PUT', user: true, folder: false, path: true, dest: false, share: false },
'mkdir': { method: 'MKCOL', user: true, folder: true, path: false, dest: false, share: false },
'move': { method: 'MOVE', user: true, folder: false, path: true, dest: true, share: false },
'copy': { method: 'COPY', user: true, folder: false, path: true, dest: true, share: false },
'delete': { method: 'DELETE', user: true, folder: false, path: true, dest: false, share: false },
'listShares': { method: 'GET', user: false, folder: false, path: false, dest: false, share: false },
'createShare': { method: 'POST', user: false, folder: false, path: false, dest: false, share: true },
'deleteShare': { method: 'DELETE', user: false, folder: false, path: false, dest: false, share: false },
'fileInfo': { method: 'GET', user: false, folder: false, path: false, dest: false, share: false },
'favorites': { method: 'GET', user: false, folder: false, path: false, dest: false, share: false }
};
function updateFields() {
var op = $('#node-input-operation').val();
var m = opMeta[op] || {};
$('#user-row').toggle(m.user);
$('#folder-row').toggle(m.folder);
$('#path-row').toggle(m.path);
$('#dest-row').toggle(m.dest);
$('#share-fields').toggle(m.share);
$('#op-method-file').text(m.method || 'GET');
}
$('#node-input-operation').change(updateFields);
setTimeout(updateFields, 100);
}
});
</script>
<script type="text/html" data-template-name="file-operations">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="File Operations">
</div>
<div class="form-row">
<label for="node-input-nextcloud"><i class="fa fa-cloud"></i> Nextcloud Config</label>
<input type="text" id="node-input-nextcloud" placeholder="Select config node">
</div>
<div class="form-row">
<label for="node-input-operation"><i class="fa fa-cog"></i> Operation</label>
<select id="node-input-operation" style="width:100%;">
<optgroup label="Read/List">
<option value="list">List Directory</option>
<option value="get">Download File</option>
<option value="fileInfo">Storage Stats</option>
<option value="favorites">List Favorites</option>
</optgroup>
<optgroup label="Write">
<option value="upload">Upload File</option>
<option value="mkdir">Create Directory</option>
</optgroup>
<optgroup label="Modify">
<option value="move">Move/Rename</option>
<option value="copy">Copy</option>
</optgroup>
<optgroup label="Delete">
<option value="delete">Delete File/Folder</option>
</optgroup>
<optgroup label="Sharing (OCS)">
<option value="listShares">List Shares</option>
<option value="createShare">Create Share</option>
<option value="deleteShare">Delete Share</option>
</optgroup>
</select>
<span id="op-method-file" style="margin-left:8px; color:#888; font-size:0.85em;">PROPFIND</span>
</div>
<hr style="margin:10px 0; border:none; border-top:1px solid #ccc;">
<div class="form-row" id="user-row">
<label for="node-input-ncUser"><i class="fa fa-user"></i> User</label>
<input type="text" id="node-input-ncUser" placeholder="Defaults to config username. msg.ncUser override.">
</div>
<div class="form-row" id="folder-row">
<label for="node-input-ncFolder"><i class="fa fa-folder"></i> Folder Path</label>
<input type="text" id="node-input-ncFolder" placeholder="e.g. Documents/Project. msg.ncFolder override.">
</div>
<div class="form-row" id="path-row">
<label for="node-input-ncPath"><i class="fa fa-file"></i> File Path</label>
<input type="text" id="node-input-ncPath" placeholder="e.g. Documents/report.txt. msg.ncPath override.">
</div>
<div class="form-row" id="dest-row">
<label for="node-input-destination"><i class="fa fa-arrow-right"></i> Destination</label>
<input type="text" id="node-input-destination" placeholder="e.g. Archive/old.txt. msg.destination override.">
</div>
<div id="share-fields" style="display:none;">
<hr style="margin:10px 0; border:none; border-top:1px solid #ccc;">
<div style="font-weight:bold; margin-bottom:6px;">Share Options</div>
<div class="form-row">
<label for="node-input-bodySharePath">File Path to Share</label>
<input type="text" id="node-input-bodySharePath" placeholder="e.g. /Documents/file.txt. msg.path override.">
</div>
<div class="form-row">
<label for="node-input-bodyShareType">Share Type</label>
<select id="node-input-bodyShareType">
<option value="">Default (msg.shareType)</option>
<option value="0">User</option>
<option value="1">Group</option>
<option value="3">Public Link</option>
<option value="4">Email</option>
</select>
</div>
<div class="form-row">
<label for="node-input-bodyPermissions">Permissions</label>
<input type="text" id="node-input-bodyPermissions" placeholder="e.g. 31 = all. msg.permissions override.">
</div>
<div class="form-row">
<label for="node-input-bodyShareWith">Share With</label>
<input type="text" id="node-input-bodyShareWith" placeholder="Username/group. msg.shareWith override.">
</div>
</div>
<div class="form-tips">
<p>All fields overridable via <code>msg.*</code>. Upload: pass file content in <code>msg.payload</code>.</p>
</div>
</script>