add possibility to set expiry of a room
This commit is contained in:
parent
3f15ba7703
commit
b899e2efa4
4 changed files with 108 additions and 49 deletions
|
@ -11,8 +11,13 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="create-room">
|
||||
<input type="button" value="Create Room">
|
||||
<div id="welcome-message"></div>
|
||||
<input type="button" value="Create Room">
|
||||
<br>
|
||||
<div id="toggle-advanced">
|
||||
<span>Advanced</span>
|
||||
</div>
|
||||
<div id="advanced" class="home-element"></div>
|
||||
<div id="welcome-message" class="home-element"></div>
|
||||
</div>
|
||||
<div id="room">
|
||||
<div id="link">
|
||||
|
|
105
client/main.js
105
client/main.js
|
@ -2,11 +2,11 @@ var Uploader = {
|
|||
|
||||
roomId: null,
|
||||
|
||||
createRoom: function(callback) {
|
||||
var self = this;
|
||||
$.post('/room', {}, function(response) {
|
||||
callback($.parseJSON(response).id);
|
||||
})
|
||||
createRoom: function(callback, options) {
|
||||
var self = this;
|
||||
$.post('/room', options, function(response) {
|
||||
callback($.parseJSON(response).id);
|
||||
})
|
||||
},
|
||||
|
||||
getRoom: function(path,callback) {
|
||||
|
@ -14,67 +14,67 @@ var Uploader = {
|
|||
},
|
||||
|
||||
getFile: function(fileName, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/files/'+this.roomId+'/'+fileName, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onload = callback;
|
||||
xhr.send();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/files/'+this.roomId+'/'+fileName, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onload = callback;
|
||||
xhr.send();
|
||||
},
|
||||
|
||||
deleteRoom: function() {
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
url: '/room/'+this.roomId
|
||||
})
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
url: '/room/'+this.roomId
|
||||
})
|
||||
},
|
||||
|
||||
uploadFile: function(path, name, data, progress, success){
|
||||
var formData = new FormData();
|
||||
formData.append("path", path);
|
||||
formData.append("file", data, name);
|
||||
$.ajax({
|
||||
url: '/room/'+this.roomId,
|
||||
data: formData,
|
||||
success: success,
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
xhr: function () {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.upload.addEventListener('progress', progress, false)
|
||||
return xhr
|
||||
},
|
||||
type: 'POST'
|
||||
});
|
||||
var formData = new FormData();
|
||||
formData.append("path", path);
|
||||
formData.append("file", data, name);
|
||||
$.ajax({
|
||||
url: '/room/'+this.roomId,
|
||||
data: formData,
|
||||
success: success,
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
xhr: function () {
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.upload.addEventListener('pro Advanced gress', progress, false)
|
||||
return xhr
|
||||
},
|
||||
type: 'POST'
|
||||
});
|
||||
},
|
||||
|
||||
createDirectory: function(path, success) {
|
||||
$.ajax({
|
||||
url: '/room/mkdir/'+this.roomId,
|
||||
type: 'POST',
|
||||
data: {path: path},
|
||||
success: success
|
||||
});
|
||||
$.ajax({
|
||||
url: '/room/mkdir/'+this.roomId,
|
||||
type: 'POST',
|
||||
data: {path: path},
|
||||
success: success
|
||||
});
|
||||
},
|
||||
|
||||
deleteFile: function(id) {
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
url: '/room/'+this.roomId+'/'+id
|
||||
})
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
url: '/room/'+this.roomId+'/'+id
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
var CryptoUploader = {
|
||||
|
||||
createRoom: function() {
|
||||
createRoom: function(options) {
|
||||
Uploader.createRoom(function(roomId){
|
||||
CryptoUtils.initialize()
|
||||
.then(function(){
|
||||
window.location = window.location.href+"#"+roomId+","+CryptoUtils.urlSafeKey;
|
||||
window.location.reload();
|
||||
})
|
||||
});
|
||||
}, options);
|
||||
},
|
||||
|
||||
uploadFile: function() {
|
||||
|
@ -246,17 +246,30 @@ $(function(){
|
|||
}
|
||||
else {
|
||||
$("#welcome-message").hide()
|
||||
$("#advanced").hide();
|
||||
$("#room").hide();
|
||||
$("#toggle-advanced > span").on('click', function(e) {
|
||||
$("#advanced").toggle()
|
||||
});
|
||||
$("#create-room > input").show().on('click', function(e){
|
||||
CryptoUploader.createRoom();
|
||||
const expire_inactivity = $('#expire_inactivity').val();
|
||||
let options = {};
|
||||
if(expire_inactivity) { options.expire_inactivity = expire_inactivity}
|
||||
CryptoUploader.createRoom(options);
|
||||
});
|
||||
$.getJSON('/config', function(result) {
|
||||
if(result.home && result.home.welcome_message) {
|
||||
console.log('ciao')
|
||||
console.log(result)
|
||||
$("#welcome-message").html(result.home.welcome_message);
|
||||
$("#welcome-message").show()
|
||||
}
|
||||
if(result.config && result.config.expire_inactivity) {
|
||||
const el = $("<select id='expire_inactivity'><select>");
|
||||
for(const expiry of result.config.expire_inactivity) {
|
||||
$(`<option value=${expiry.id}>${expiry.label}</option>`).appendTo(el);
|
||||
}
|
||||
$("#advanced").append("Expire after inactivity");
|
||||
$("#advanced").append(el);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -57,6 +57,11 @@ body {
|
|||
padding: 0;
|
||||
}
|
||||
|
||||
#file-list > ul > li > a, .delete-button{
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
#file-list > ul > li {
|
||||
position: relative;
|
||||
display: block;
|
||||
|
@ -141,6 +146,28 @@ label, input {
|
|||
}
|
||||
|
||||
#welcome-message {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
#toggle-advanced {
|
||||
max-width: 20%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
text-align: right;
|
||||
text-decoration: underline;
|
||||
color: #ccc;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#advanced > select {
|
||||
background-color: #232323;
|
||||
color: #ccc;
|
||||
border: solid 1px #ccc;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
|
||||
.home-element {
|
||||
background-color: #363636;
|
||||
border: 2px dashed #ccc;
|
||||
border-radius: 10px;
|
||||
|
@ -152,4 +179,9 @@ label, input {
|
|||
max-width: 20%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
#advanced {
|
||||
display: grid;
|
||||
grid-template-columns: auto auto;
|
||||
}
|
|
@ -43,7 +43,16 @@ end
|
|||
# create a room
|
||||
|
||||
post '/room' do
|
||||
id = SecureRandom.hex(6)
|
||||
expire_suffix = ''
|
||||
if params[:expire_inactivity]
|
||||
puts(params)
|
||||
expire_inactivity_option_id = params[:expire_inactivity].to_i
|
||||
expire_inactivity_option = settings.silent_drive_config.fetch('config', {}).fetch('expire_inactivity', []).detect { |e| e['id'].to_i == expire_inactivity_option_id }
|
||||
if expire_inactivity_option
|
||||
expire_suffix = expire_inactivity_option['suffix']
|
||||
end
|
||||
end
|
||||
id = SecureRandom.hex(6)+expire_suffix
|
||||
Dir.mkdir(settings.storage_directory+id)
|
||||
content_type 'text/json'
|
||||
{id: id}.to_json
|
||||
|
|
Loading…
Add table
Reference in a new issue