diff --git a/src/UI/UIDesktop.js b/src/UI/UIDesktop.js index cab94d9d..c2db78d7 100644 --- a/src/UI/UIDesktop.js +++ b/src/UI/UIDesktop.js @@ -817,7 +817,6 @@ async function UIDesktop(options){ //------------------------------------------- if(!is_embedded && !window.is_fullpage_mode){ refresh_item_container(el_desktop, {fadeInItems: true}) - window.launch_download_from_url(); } // ------------------------------------------- diff --git a/src/UI/UIWindowConfirmDownload.js b/src/UI/UIWindowConfirmDownload.js deleted file mode 100644 index b9605ad2..00000000 --- a/src/UI/UIWindowConfirmDownload.js +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright (C) 2024 Puter Technologies Inc. - * - * This file is part of Puter. - * - * Puter is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import UIWindow from './UIWindow.js' - -// todo do this using uid rather than item_path, since item_path is way mroe expensive on the DB -async function UIWindowConfirmDownload(options){ - return new Promise(async (resolve) => { - let h = ''; - h += `
`; - // Confirm download - h +=`
`; - // Message - h += `

Do you want to download this file?

`; - h += `
`; - h += ``; - h += `
`; - // Item information - h += `
`; - // Name - h += `

${i18n('name')}: ${options.name ?? options.url}

`; - // Type - h += `

${i18n('type')}: ${options.is_dir === '1' || options.is_dir === 'true' ? 'Folder' : options.type ?? 'Unknown File Type'}

`; - // Source - h += `

${i18n('from')}: ${options.source}

`; - h += `
`; - h += `
`; - // Download - h += ``; - // Cancel - h += ``; - h +=`
`; - - const el_window = await UIWindow({ - title: `Upload`, - icon: window.icons[`app-icon-uploader.svg`], - uid: null, - is_dir: false, - body_content: h, - has_head: false, - selectable_body: false, - draggable_body: true, - allow_context_menu: false, - is_resizable: false, - is_droppable: false, - init_center: true, - allow_native_ctxmenu: false, - allow_user_select: false, - window_class: 'window-upload-progress', - width: 450, - dominant: true, - window_css:{ - height: 'initial', - }, - body_css: { - padding: '22px', - width: 'initial', - 'background-color': 'rgba(231, 238, 245, .95)', - 'backdrop-filter': 'blur(3px)', - } - }); - - $(el_window).find('.btn-download-confirm').on('click submit', function(e){ - $(el_window).close(); - resolve(true); - }) - - $(el_window).find('.btn-download-cancel').on('click submit', function(e){ - $(el_window).close(); - resolve(false); - }) - }) -} - -export default UIWindowConfirmDownload \ No newline at end of file diff --git a/src/helpers.js b/src/helpers.js index 9465db44..5158fc0c 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -24,7 +24,6 @@ import UIItem from './UI/UIItem.js' import UIWindow from './UI/UIWindow.js' import UIWindowLogin from './UI/UIWindowLogin.js'; import UIWindowSaveAccount from './UI/UIWindowSaveAccount.js'; -import UIWindowConfirmDownload from './UI/UIWindowConfirmDownload.js'; import UIWindowCopyProgress from './UI/UIWindowCopyProgress.js'; import UIWindowMoveProgress from './UI/UIWindowMoveProgress.js'; import UIWindowNewFolderProgress from './UI/UIWindowNewFolderProgress.js'; @@ -1097,80 +1096,6 @@ window.show_save_account_notice_if_needed = function(message){ }) } -window.launch_download_from_url = async function(){ - // get url query params - const url_query_params = new URLSearchParams(window.location.search); - - // is this download? - if(url_query_params.has('download')){ - let url = url_query_params.get('download'); - let name = url_query_params.get('name'); - let is_dir = url_query_params.get('is_dir'); - let url_obj; - - // if url doesn't have a protocol, add http:// - if(!url.startsWith('http://') && !url.startsWith('https://')){ - url = 'http://' + url; - } - - // parse url - try{ - url_obj = new URL(url); - }catch(e){ - UIAlert("Invalid download URL."); - return; - } - - // get hostname from url - let hostname = url_obj.hostname; - - // name - if(!name) - name = url.split('/').pop().split('#')[0].split('?')[0]; - - // determine file type from url - let file_type = mime.getType(name); - - // confirm download - if(await UIWindowConfirmDownload({url: url, name: name, source: hostname, type: file_type, is_dir: is_dir})){ - // download progress tracker - let dl_op_id = operation_id++; - - // upload progress tracker defaults - window.progress_tracker[dl_op_id] = []; - window.progress_tracker[dl_op_id][0] = {}; - window.progress_tracker[dl_op_id][0].total = 0; - window.progress_tracker[dl_op_id][0].ajax_uploaded = 0; - window.progress_tracker[dl_op_id][0].cloud_uploaded = 0; - - const progress_window = await UIWindowDownloadProgress({operation_id: dl_op_id, item_name: name}); - - const res = await download({ - url: url, - name: name, - dest_path: desktop_path, - auth_token: auth_token, - api_origin: api_origin, - dedupe_name: true, - overwrite: false, - operation_id: dl_op_id, - item_upload_id: 0, - success: function(res){ - $(progress_window).close(); - }, - error: function(err){ - UIAlert(err && err.message ? err.message : "Download failed."); - $(progress_window).close(); - } - }); - - // clear window URL - window.history.pushState(null, document.title, '/'); - } - - } -} - window.onpopstate = (event) => { if(event.state !== null && event.state.window_id !== null){ $(`.window[data-id="${event.state.window_id}"]`).focusWindow();