Upload and install addon from file

This commit is contained in:
Jan Schneider 2018-01-29 00:04:12 +01:00
parent d3b87c5dfc
commit 6fa4ba262e
3 changed files with 119 additions and 44 deletions

View File

@ -971,13 +971,18 @@ proc ::rmupdate::install_addon {{addon_id ""} {download_url ""}} {
set_running_installation "Addon ${addon_id}" set_running_installation "Addon ${addon_id}"
set archive_file ""
regexp {^file://(.*)$} $download_url match archive_file
if { [info exists archive_file] && $archive_file != "" } {
write_log 3 "Installing addon from local file ${archive_file}."
} else {
write_log 3 "Downloading addon from ${download_url}." write_log 3 "Downloading addon from ${download_url}."
set archive_file "/tmp/${addon_id}.tar.gz" set archive_file "/tmp/${addon_id}.tar.gz"
if {[file exists $archive_file]} { if {[file exists $archive_file]} {
file delete $archive_file file delete $archive_file
} }
exec /usr/bin/wget "${download_url}" --no-check-certificate --quiet --output-document=$archive_file exec /usr/bin/wget "${download_url}" --no-check-certificate --quiet --output-document=$archive_file
}
write_log 3 "Extracting archive ${archive_file}." write_log 3 "Extracting archive ${archive_file}."
set tmp_dir "/tmp/rmupdate_addon_install_${addon_id}" set tmp_dir "/tmp/rmupdate_addon_install_${addon_id}"

View File

@ -257,20 +257,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}); });
} }
function install_addon(addon_id, download_url) { function upload_and_install_addon() {
}
function install_addon(addon_id, download_url, file_input) {
if (!running_installation) { if (!running_installation) {
display_message('info', i18next.t('installing_addon', {'addon_id': addon_id}), 6000000); display_message('info', i18next.t('installing_addon', {'addon_id': addon_id}), 6000000);
if (addon_id) {
$('[data-update-addon-id="' + addon_id + '"]').addClass('loading'); $('[data-update-addon-id="' + addon_id + '"]').addClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').addClass('disabled'); $('[data-update-addon-id="' + addon_id + '"]').addClass('disabled');
$('[data-uninstall-addon-id="' + addon_id + '"]').addClass('disabled'); $('[data-uninstall-addon-id="' + addon_id + '"]').addClass('disabled');
}
if (download_url) {
$('#install-addon-url-button').addClass('loading');
}
if (file_input) {
$('#install-addon-file-button').addClass('loading');
}
$('#install-addon-url-button').addClass('disabled'); $('#install-addon-url-button').addClass('disabled');
rest("POST", "/install_addon", JSON.stringify({"addon_id":addon_id, "download_url":download_url}), $('#install-addon-file-button').addClass('disabled');
function(data) { var success_callback = function(data) {
//console.info(data); //console.info(data);
$('[data-update-addon-id="' + addon_id + '"]').removeClass('loading'); $('[data-update-addon-id="' + addon_id + '"]').removeClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled'); $('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled');
$('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('disabled'); $('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('disabled');
$('#install-addon-url-button').removeClass('disabled'); $('#install-addon-url-button').removeClass('disabled');
$('#install-addon-url-button').removeClass('loading');
$('#install-addon-file-button').removeClass('disabled');
$('#install-addon-file-button').removeClass('loading');
display_message('success', data, 6000000); display_message('success', data, 6000000);
if (addon_id) { if (addon_id) {
$('#tr-' + addon_id).removeClass('warning'); $('#tr-' + addon_id).removeClass('warning');
@ -282,21 +297,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} }
else { else {
$('#install-addon-url-input').val(''); $('#install-addon-url-input').val('');
$('#install-addon-file-input').val('');
get_addon_info(); get_addon_info();
} }
}, }
function(xhr, ajaxOptions, thrownError) { var error_callback = function(xhr, ajaxOptions, thrownError) {
console.error("Addon installation error: " + thrownError + ": " + xhr.responseText); console.error("Addon installation error: " + thrownError + ": " + xhr.responseText);
$('[data-update-addon-id="' + addon_id + '"]').removeClass('loading'); $('[data-update-addon-id="' + addon_id + '"]').removeClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled'); $('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled');
$('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('disabled'); $('[data-uninstall-addon-id="' + addon_id + '"]').removeClass('disabled');
$('#install-addon-url-input').val(''); $('#install-addon-url-input').val('');
$('#install-addon-file-input').val('');
$('#install-addon-url-button').removeClass('disabled'); $('#install-addon-url-button').removeClass('disabled');
$('#install-addon-url-button').removeClass('loading');
$('#install-addon-file-button').removeClass('disabled');
$('#install-addon-file-button').removeClass('loading');
default_error_callback(xhr, ajaxOptions, thrownError); default_error_callback(xhr, ajaxOptions, thrownError);
} }
if (file_input) {
$.ajax({
url: 'rest.cgi?/install_addon_archive',
data: file_input.files[0],
type: 'POST',
processData: false,
contentType: 'application/octet-stream',
success: success_callback,
error: error_callback
});
}
else {
rest("POST", "/install_addon", JSON.stringify({"addon_id":addon_id, "download_url":download_url}),
success_callback, error_callback
); );
} }
} }
}
function uninstall_addon(addon_id) { function uninstall_addon(addon_id) {
if (!running_installation) { if (!running_installation) {
@ -423,6 +459,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
installing_addon: 'Installing addon {{addon_id}}.', installing_addon: 'Installing addon {{addon_id}}.',
uninstalling_addon: 'Uninstalling addon {{addon_id}}.', uninstalling_addon: 'Uninstalling addon {{addon_id}}.',
install_addon_from_url: 'Install addon from url', install_addon_from_url: 'Install addon from url',
install_addon_from_file: 'Install addon from file',
choose_addon_file: 'Choose and install addon-file',
} }
}, },
de: { de: {
@ -466,6 +504,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
installing_addon: 'Installiere Addon {{addon_id}}.', installing_addon: 'Installiere Addon {{addon_id}}.',
uninstalling_addon: 'Deinstalliere Addon {{addon_id}}.', uninstalling_addon: 'Deinstalliere Addon {{addon_id}}.',
install_addon_from_url: 'Addon von URL installieren', install_addon_from_url: 'Addon von URL installieren',
install_addon_from_file: 'Addon aus Datei installieren',
choose_addon_file: 'Addon-Datei auswählen und installieren',
} }
} }
} }
@ -477,6 +517,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
$('div').localize(); $('div').localize();
$('th').localize(); $('th').localize();
$('label').localize(); $('label').localize();
$('#install-addon-url-button').contents().last()[0].textContent = i18next.t('install');
$('#install-addon-file-button').contents().last()[0].textContent = i18next.t('choose_addon_file');
}); });
rest("GET", "/version", null, function(version) { rest("GET", "/version", null, function(version) {
@ -565,6 +607,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</tbody> </tbody>
</table> </table>
</div> </div>
<h2 class="ui header"> <h2 class="ui header">
<i class="cloud download icon"></i> <i class="cloud download icon"></i>
<div data-i18n="install_addon_from_url" class="content"> <div data-i18n="install_addon_from_url" class="content">
@ -574,9 +617,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<input id="install-addon-url-input" type="text" placeholder="http://.../addon.tar.gz"/> <input id="install-addon-url-input" type="text" placeholder="http://.../addon.tar.gz"/>
<button id="install-addon-url-button" class="ui green right labeled icon button" onclick="install_addon(null, $('#install-addon-url-input').val());"> <button id="install-addon-url-button" class="ui green right labeled icon button" onclick="install_addon(null, $('#install-addon-url-input').val());">
<i class="sign in icon"></i> <i class="sign in icon"></i>
Install install
</button> </button>
</div> </div>
<h2 class="ui header">
<i class="upload icon"></i>
<div data-i18n="install_addon_from_file" class="content">
</div>
</h2>
<div style="width: 100%" class="ui action input">
<input class="inputfile" id="install-addon-file-input" type="file" onchange="install_addon(null, null, this);" style="display: none;"/>
<label id="install-addon-file-button" for="install-addon-file-input" class="ui green button">
<i class="ui file archive outline icon"></i>
choose_addon_file
</label>
</div>
</div> </div>
<div style="height:60vh;" id="modal-log" class="ui modal"> <div style="height:60vh;" id="modal-log" class="ui modal">

View File

@ -23,12 +23,26 @@ proc process {} {
global env global env
if { [info exists env(QUERY_STRING)] } { if { [info exists env(QUERY_STRING)] } {
set query $env(QUERY_STRING) set query $env(QUERY_STRING)
set path [split $query {/}]
set plen [expr [llength $path] - 1]
if {[lindex $path 1] == "install_addon_archive"} {
set archive_file "/tmp/uploaded_addon.tar.gz"
catch {fconfigure stdin -translation binary}
catch {fconfigure stdin -encoding binary}
set out [open $archive_file w]
catch {fconfigure $out -translation binary}
catch {fconfigure $out -encoding binary}
puts -nonewline $out [read stdin]
close $out
set res [rmupdate::install_addon "" "file://${archive_file}"]
return "\"${res}\""
}
set data "" set data ""
if { [info exists env(CONTENT_LENGTH)] } { if { [info exists env(CONTENT_LENGTH)] } {
set data [read stdin $env(CONTENT_LENGTH)] set data [read stdin $env(CONTENT_LENGTH)]
} }
set path [split $query {/}]
set plen [expr [llength $path] - 1]
if {[lindex $path 1] == "version"} { if {[lindex $path 1] == "version"} {
return "\"[rmupdate::version]\"" return "\"[rmupdate::version]\""