diff --git a/src/helpers.js b/src/helpers.js index 53ad2bb97..9f8a704c6 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -31,6 +31,7 @@ import truncate_filename from './helpers/truncate_filename.js'; import UIWindowProgress from './UI/UIWindowProgress.js'; import launch_app from "./helpers/launch_app.js"; import globToRegExp from "./helpers/globToRegExp.js"; +import get_html_element_from_options from "./helpers/get_html_element_from_options.js"; window.is_auth = ()=>{ if(localStorage.getItem("auth_token") === null || window.auth_token === null) @@ -2138,7 +2139,6 @@ window.upload_items = async function(items, dest_path){ }, // abort abort: async function(operation_id){ - // console.log('upload aborted'); // remove from active_uploads delete window.active_uploads[opid]; } @@ -2456,7 +2456,6 @@ window.unzipItem = async function(itemPath) { zip.loadAsync(file).then(async function (zip) { const rootdir = await puter.fs.mkdir(path.dirname(filPath) + '/' + path.basename(filPath, '.zip'), {dedupeName: true}); Object.keys(zip.files).forEach(async function (filename) { - console.log(filename); if(filename.endsWith('/')) await puter.fs.mkdir(rootdir.path +'/' + filename, {createMissingParents: true}); zip.files[filename].async('blob').then(async function (fileData) { @@ -2652,146 +2651,19 @@ window.undo_copy = async(files)=>{ window.undo_move = async(items)=>{ for (const item of items) { - const el = await window.get_html_element_from_options(item.options); - console.log(item.original_path) + const el = await get_html_element_from_options(item.options); window.move_items([el], path.dirname(item.original_path), true); } } window.undo_delete = async(items)=>{ for (const item of items) { - const el = await window.get_html_element_from_options(item.options); + const el = await get_html_element_from_options(item.options); let metadata = $(el).attr('data-metadata') === '' ? {} : JSON.parse($(el).attr('data-metadata')) window.move_items([el], path.dirname(metadata.original_path), true); } } - -window.get_html_element_from_options = async function(options){ - const item_id = window.global_element_id++; - - options.disabled = options.disabled ?? false; - options.visible = options.visible ?? 'visible'; // one of 'visible', 'revealed', 'hidden' - options.is_dir = options.is_dir ?? false; - options.is_selected = options.is_selected ?? false; - options.is_shared = options.is_shared ?? false; - options.is_shortcut = options.is_shortcut ?? 0; - options.is_trash = options.is_trash ?? false; - options.metadata = options.metadata ?? ''; - options.multiselectable = (!options.multiselectable || options.multiselectable === true) ? true : false; - options.shortcut_to = options.shortcut_to ?? ''; - options.shortcut_to_path = options.shortcut_to_path ?? ''; - options.immutable = (options.immutable === false || options.immutable === 0 || options.immutable === undefined ? 0 : 1); - options.sort_container_after_append = (options.sort_container_after_append !== undefined ? options.sort_container_after_append : false); - const is_shared_with_me = (options.path !== '/'+window.user.username && !options.path.startsWith('/'+window.user.username+'/')); - - let website_url = window.determine_website_url(options.path); - - // do a quick check to see if the target parent has any file type restrictions - const appendto_allowed_file_types = $(options.appendTo).attr('data-allowed_file_types') - if(!window.check_fsentry_against_allowed_file_types_string({is_dir: options.is_dir, name:options.name, type:options.type}, appendto_allowed_file_types)) - options.disabled = true; - - // -------------------------------------------------------- - // HTML for Item - // -------------------------------------------------------- - let h = ''; - h += `
`; - - // spinner - h += `
`; - h += `
`; - // modified - h += `
`; - h += `${options.modified === 0 ? '-' : timeago.format(options.modified*1000)}`; - h += `
`; - // size - h += `
`; - h += `${options.size ? window.byte_format(options.size) : '-'}`; - h += `
`; - // type - h += `
`; - if(options.is_dir) - h += `Folder`; - else - h += `${options.type ? html_encode(options.type) : '-'}`; - h += `
`; - - - // icon - h += `
`; - h += ``; - h += `
`; - // badges - h += `
`; - // website badge - h += ``; - // link badge - h += ``; - - // shared badge - h += ``; - // owner-shared badge - h += ``; - // shortcut badge - h += ``; - - h += `
`; - - // name - h += `${html_encode(truncate_filename(options.name)).replaceAll(' ', ' ')}` - // name editor - h += `` - h += `
`; - - return h; -} - window.store_auto_arrange_preference = (preference)=>{ puter.kv.set('user_preferences.auto_arrange_desktop', preference); localStorage.setItem('auto_arrange', preference); diff --git a/src/helpers/get_html_element_from_options.js b/src/helpers/get_html_element_from_options.js new file mode 100644 index 000000000..ee464d5f2 --- /dev/null +++ b/src/helpers/get_html_element_from_options.js @@ -0,0 +1,147 @@ +/** + * 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 truncate_filename from './truncate_filename.js'; + +const get_html_element_from_options = async function(options){ + const item_id = window.global_element_id++; + + options.disabled = options.disabled ?? false; + options.visible = options.visible ?? 'visible'; // one of 'visible', 'revealed', 'hidden' + options.is_dir = options.is_dir ?? false; + options.is_selected = options.is_selected ?? false; + options.is_shared = options.is_shared ?? false; + options.is_shortcut = options.is_shortcut ?? 0; + options.is_trash = options.is_trash ?? false; + options.metadata = options.metadata ?? ''; + options.multiselectable = (!options.multiselectable || options.multiselectable === true) ? true : false; + options.shortcut_to = options.shortcut_to ?? ''; + options.shortcut_to_path = options.shortcut_to_path ?? ''; + options.immutable = (options.immutable === false || options.immutable === 0 || options.immutable === undefined ? 0 : 1); + options.sort_container_after_append = (options.sort_container_after_append !== undefined ? options.sort_container_after_append : false); + const is_shared_with_me = (options.path !== '/'+window.user.username && !options.path.startsWith('/'+window.user.username+'/')); + + let website_url = window.determine_website_url(options.path); + + // do a quick check to see if the target parent has any file type restrictions + const appendto_allowed_file_types = $(options.appendTo).attr('data-allowed_file_types') + if(!window.check_fsentry_against_allowed_file_types_string({is_dir: options.is_dir, name:options.name, type:options.type}, appendto_allowed_file_types)) + options.disabled = true; + + // -------------------------------------------------------- + // HTML for Item + // -------------------------------------------------------- + let h = ''; + h += `
`; + + // spinner + h += `
`; + h += `
`; + // modified + h += `
`; + h += `${options.modified === 0 ? '-' : timeago.format(options.modified*1000)}`; + h += `
`; + // size + h += `
`; + h += `${options.size ? window.byte_format(options.size) : '-'}`; + h += `
`; + // type + h += `
`; + if(options.is_dir) + h += `Folder`; + else + h += `${options.type ? html_encode(options.type) : '-'}`; + h += `
`; + + + // icon + h += `
`; + h += ``; + h += `
`; + // badges + h += `
`; + // website badge + h += ``; + // link badge + h += ``; + + // shared badge + h += ``; + // owner-shared badge + h += ``; + // shortcut badge + h += ``; + + h += `
`; + + // name + h += `${html_encode(truncate_filename(options.name)).replaceAll(' ', ' ')}` + // name editor + h += `` + h += `
`; + + return h; +} + +export default get_html_element_from_options; \ No newline at end of file