mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-11-29 16:50:13 +01:00
2020-10-16 Fred Gleason <fredg@paravelsystems.com>
* Modified the 'WebGet' service to supply a sane default filename for downloaded content. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
104
web/webget/webget.js
Normal file
104
web/webget/webget.js
Normal file
@@ -0,0 +1,104 @@
|
||||
// webget.js
|
||||
//
|
||||
// (C) Copyright 2020 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
function Id(id)
|
||||
{
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
|
||||
function MakePost()
|
||||
{
|
||||
var sep=MakeMimeSeparator();
|
||||
form=sep+"\r\n";
|
||||
|
||||
form+=AddMimePart('title',Id('title').value,sep,false);
|
||||
form+=AddMimePart('preset',Id('preset').value,sep,false);
|
||||
form+=AddMimePart('LOGIN_NAME',Id('LOGIN_NAME').value,sep,false);
|
||||
form+=AddMimePart('PASSWORD',Id('PASSWORD').value,sep,true);
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
|
||||
function ProcessOkButton()
|
||||
{
|
||||
SendForm(MakePost(),"webget.cgi");
|
||||
}
|
||||
|
||||
|
||||
function SendForm(form,url)
|
||||
{
|
||||
var http=GetXMLHttpRequest();
|
||||
if(http==null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send the form
|
||||
//
|
||||
http.open("POST",url,true);
|
||||
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
|
||||
http.responseType='blob';
|
||||
http.send(form);
|
||||
|
||||
//
|
||||
// Process the response
|
||||
//
|
||||
http.onload=function(e) {
|
||||
if(this.status==200) {
|
||||
var blob=new Blob([this.response],
|
||||
{type: http.getResponseHeader('content-type')});
|
||||
let a=document.createElement('a');
|
||||
a.style='display: none';
|
||||
document.body.appendChild(a);
|
||||
let url=window.URL.createObjectURL(blob);
|
||||
a.href=url;
|
||||
a.download=Id('title').value+'.'+FileExtension(Id('preset').value);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
else {
|
||||
if(this.status==401) {
|
||||
alert('Invalid User Name or Password!');
|
||||
}
|
||||
else {
|
||||
if(this.status=404) {
|
||||
alert('No cart with that name found!');
|
||||
}
|
||||
else {
|
||||
alert('Unable to access WebGet [response code: '+
|
||||
http.status+']!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function FileExtension(prof_id)
|
||||
{
|
||||
for(id in preset_ids) {
|
||||
if(preset_ids[id]==prof_id) {
|
||||
return preset_exts[id];
|
||||
}
|
||||
}
|
||||
|
||||
return 'dat';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user