|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | import path from "./lib/path.js"
|
21 |
| -import mime from "./lib/mime.js"; |
22 | 21 | import UIAlert from './UI/UIAlert.js'
|
23 | 22 | import UIItem from './UI/UIItem.js'
|
24 | 23 | import UIWindowLogin from './UI/UIWindowLogin.js';
|
25 | 24 | import UIWindowSaveAccount from './UI/UIWindowSaveAccount.js';
|
26 | 25 | import update_username_in_gui from './helpers/update_username_in_gui.js';
|
27 | 26 | import update_title_based_on_uploads from './helpers/update_title_based_on_uploads.js';
|
28 |
| -import content_type_to_icon from './helpers/content_type_to_icon.js'; |
29 | 27 | import truncate_filename from './helpers/truncate_filename.js';
|
30 | 28 | import UIWindowProgress from './UI/UIWindowProgress.js';
|
31 | 29 | import globToRegExp from "./helpers/globToRegExp.js";
|
32 | 30 | import get_html_element_from_options from "./helpers/get_html_element_from_options.js";
|
| 31 | +import item_icon from "./helpers/item_icon.js"; |
33 | 32 |
|
34 | 33 | window.is_auth = ()=>{
|
35 | 34 | if(localStorage.getItem("auth_token") === null || window.auth_token === null)
|
@@ -624,187 +623,6 @@ window.sendItemChangeEventToWatchingApps = function(item_uid, event_data){
|
624 | 623 | }
|
625 | 624 | }
|
626 | 625 |
|
627 |
| -/** |
628 |
| - * Assigns an icon to a filesystem entry based on its properties such as name, type, |
629 |
| - * and whether it's a directory, app, trashed, or specific file type. |
630 |
| - * |
631 |
| - * @function item_icon |
632 |
| - * @global |
633 |
| - * @async |
634 |
| - * @param {Object} fsentry - A filesystem entry object. It may contain various properties |
635 |
| - * like name, type, path, associated_app, thumbnail, is_dir, and metadata, depending on |
636 |
| - * the type of filesystem entry. |
637 |
| - */ |
638 |
| - |
639 |
| -window.item_icon = async (fsentry)=>{ |
640 |
| - // -------------------------------------------------- |
641 |
| - // If this file is Trashed then set the name to the original name of the file before it was trashed |
642 |
| - // -------------------------------------------------- |
643 |
| - if(fsentry.path?.startsWith(window.trash_path + '/')){ |
644 |
| - if(fsentry.metadata){ |
645 |
| - try{ |
646 |
| - let metadata = JSON.parse(fsentry.metadata); |
647 |
| - fsentry.name = (metadata && metadata.original_name) ? metadata.original_name : fsentry.name |
648 |
| - } |
649 |
| - catch(e){ |
650 |
| - // Ignored |
651 |
| - } |
652 |
| - } |
653 |
| - } |
654 |
| - // -------------------------------------------------- |
655 |
| - // thumbnail |
656 |
| - // -------------------------------------------------- |
657 |
| - if(fsentry.thumbnail){ |
658 |
| - return {image: fsentry.thumbnail, type: 'thumb'}; |
659 |
| - } |
660 |
| - // -------------------------------------------------- |
661 |
| - // app icon |
662 |
| - // -------------------------------------------------- |
663 |
| - else if(fsentry.associated_app && fsentry.associated_app?.name){ |
664 |
| - if(fsentry.associated_app.icon) |
665 |
| - return {image: fsentry.associated_app.icon, type: 'icon'}; |
666 |
| - else |
667 |
| - return {image: window.icons['app.svg'], type: 'icon'}; |
668 |
| - } |
669 |
| - // -------------------------------------------------- |
670 |
| - // Trash |
671 |
| - // -------------------------------------------------- |
672 |
| - else if(fsentry.shortcut_to_path && fsentry.shortcut_to_path === window.trash_path){ |
673 |
| - // get trash image, this is needed to get the correct empty vs full trash icon |
674 |
| - let trash_img = $(`.item[data-path="${html_encode(window.trash_path)}" i] .item-icon-icon`).attr('src') |
675 |
| - // if trash_img is undefined that's probably because trash wasn't added anywhere, do a direct lookup to see if trash is empty or no |
676 |
| - if(!trash_img){ |
677 |
| - let trashstat = await puter.fs.stat(window.trash_path); |
678 |
| - if(trashstat.is_empty !== undefined && trashstat.is_empty === true) |
679 |
| - trash_img = window.icons['trash.svg']; |
680 |
| - else |
681 |
| - trash_img = window.icons['trash-full.svg']; |
682 |
| - } |
683 |
| - return {image: trash_img, type: 'icon'}; |
684 |
| - } |
685 |
| - // -------------------------------------------------- |
686 |
| - // Directories |
687 |
| - // -------------------------------------------------- |
688 |
| - else if(fsentry.is_dir){ |
689 |
| - // System Directories |
690 |
| - if(fsentry.path === window.docs_path) |
691 |
| - return {image: window.icons['folder-documents.svg'], type: 'icon'}; |
692 |
| - else if (fsentry.path === window.pictures_path) |
693 |
| - return { image: window.icons['folder-pictures.svg'], type: 'icon' }; |
694 |
| - else if (fsentry.path === window.home_path) |
695 |
| - return { image: window.icons['folder-home.svg'], type: 'icon' }; |
696 |
| - else if (fsentry.path === window.videos_path) |
697 |
| - return { image: window.icons['folder-videos.svg'], type: 'icon' }; |
698 |
| - else if (fsentry.path === window.desktop_path) |
699 |
| - return { image: window.icons['folder-desktop.svg'], type: 'icon' }; |
700 |
| - else if (fsentry.path === window.public_path) |
701 |
| - return { image: window.icons['folder-public.svg'], type: 'icon' }; |
702 |
| - // regular directories |
703 |
| - else |
704 |
| - return {image: window.icons['folder.svg'], type: 'icon'}; |
705 |
| - } |
706 |
| - // -------------------------------------------------- |
707 |
| - // Match icon by file extension |
708 |
| - // -------------------------------------------------- |
709 |
| - // *.doc |
710 |
| - else if(fsentry.name.toLowerCase().endsWith('.doc')){ |
711 |
| - return {image: window.icons['file-doc.svg'], type: 'icon'}; |
712 |
| - } |
713 |
| - // *.docx |
714 |
| - else if(fsentry.name.toLowerCase().endsWith('.docx')){ |
715 |
| - return {image: window.icons['file-docx.svg'], type: 'icon'}; |
716 |
| - } |
717 |
| - // *.exe |
718 |
| - else if(fsentry.name.toLowerCase().endsWith('.exe')){ |
719 |
| - return {image: window.icons['file-exe.svg'], type: 'icon'}; |
720 |
| - } |
721 |
| - // *.gz |
722 |
| - else if(fsentry.name.toLowerCase().endsWith('.gz')){ |
723 |
| - return {image: window.icons['file-gzip.svg'], type: 'icon'}; |
724 |
| - } |
725 |
| - // *.jar |
726 |
| - else if(fsentry.name.toLowerCase().endsWith('.jar')){ |
727 |
| - return {image: window.icons['file-jar.svg'], type: 'icon'}; |
728 |
| - } |
729 |
| - // *.java |
730 |
| - else if(fsentry.name.toLowerCase().endsWith('.java')){ |
731 |
| - return {image: window.icons['file-java.svg'], type: 'icon'}; |
732 |
| - } |
733 |
| - // *.jsp |
734 |
| - else if(fsentry.name.toLowerCase().endsWith('.jsp')){ |
735 |
| - return {image: window.icons['file-jsp.svg'], type: 'icon'}; |
736 |
| - } |
737 |
| - // *.log |
738 |
| - else if(fsentry.name.toLowerCase().endsWith('.log')){ |
739 |
| - return {image: window.icons['file-log.svg'], type: 'icon'}; |
740 |
| - } |
741 |
| - // *.mp3 |
742 |
| - else if(fsentry.name.toLowerCase().endsWith('.mp3')){ |
743 |
| - return {image: window.icons['file-mp3.svg'], type: 'icon'}; |
744 |
| - } |
745 |
| - // *.rb |
746 |
| - else if(fsentry.name.toLowerCase().endsWith('.rb')){ |
747 |
| - return {image: window.icons['file-ruby.svg'], type: 'icon'}; |
748 |
| - } |
749 |
| - // *.rss |
750 |
| - else if(fsentry.name.toLowerCase().endsWith('.rss')){ |
751 |
| - return {image: window.icons['file-rss.svg'], type: 'icon'}; |
752 |
| - } |
753 |
| - // *.rtf |
754 |
| - else if(fsentry.name.toLowerCase().endsWith('.rtf')){ |
755 |
| - return {image: window.icons['file-rtf.svg'], type: 'icon'}; |
756 |
| - } |
757 |
| - // *.sketch |
758 |
| - else if(fsentry.name.toLowerCase().endsWith('.sketch')){ |
759 |
| - return {image: window.icons['file-sketch.svg'], type: 'icon'}; |
760 |
| - } |
761 |
| - // *.sql |
762 |
| - else if(fsentry.name.toLowerCase().endsWith('.sql')){ |
763 |
| - return {image: window.icons['file-sql.svg'], type: 'icon'}; |
764 |
| - } |
765 |
| - // *.tif |
766 |
| - else if(fsentry.name.toLowerCase().endsWith('.tif')){ |
767 |
| - return {image: window.icons['file-tif.svg'], type: 'icon'}; |
768 |
| - } |
769 |
| - // *.tiff |
770 |
| - else if(fsentry.name.toLowerCase().endsWith('.tiff')){ |
771 |
| - return {image: window.icons['file-tiff.svg'], type: 'icon'}; |
772 |
| - } |
773 |
| - // *.wav |
774 |
| - else if(fsentry.name.toLowerCase().endsWith('.wav')){ |
775 |
| - return {image: window.icons['file-wav.svg'], type: 'icon'}; |
776 |
| - } |
777 |
| - // *.cpp |
778 |
| - else if(fsentry.name.toLowerCase().endsWith('.cpp')){ |
779 |
| - return {image: window.icons['file-cpp.svg'], type: 'icon'}; |
780 |
| - } |
781 |
| - // *.pptx |
782 |
| - else if(fsentry.name.toLowerCase().endsWith('.pptx')){ |
783 |
| - return {image: window.icons['file-pptx.svg'], type: 'icon'}; |
784 |
| - } |
785 |
| - // *.psd |
786 |
| - else if(fsentry.name.toLowerCase().endsWith('.psd')){ |
787 |
| - return {image: window.icons['file-psd.svg'], type: 'icon'}; |
788 |
| - } |
789 |
| - // *.py |
790 |
| - else if(fsentry.name.toLowerCase().endsWith('.py')){ |
791 |
| - return {image: window.icons['file-py.svg'], type: 'icon'}; |
792 |
| - } |
793 |
| - // *.xlsx |
794 |
| - else if(fsentry.name.toLowerCase().endsWith('.xlsx')){ |
795 |
| - return {image: window.icons['file-xlsx.svg'], type: 'icon'}; |
796 |
| - } |
797 |
| - // -------------------------------------------------- |
798 |
| - // Determine icon by set or derived mime type |
799 |
| - // -------------------------------------------------- |
800 |
| - else if(fsentry.type){ |
801 |
| - return {image: content_type_to_icon(fsentry.type), type: 'icon'}; |
802 |
| - } |
803 |
| - else{ |
804 |
| - return {image: content_type_to_icon(mime.getType(fsentry.name)), type: 'icon'}; |
805 |
| - } |
806 |
| -} |
807 |
| - |
808 | 626 | /**
|
809 | 627 | * Asynchronously checks if a save account notice should be shown to the user, and if needed, displays the notice.
|
810 | 628 | *
|
@@ -1605,7 +1423,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){
|
1605 | 1423 | associated_app_name: fsentry.associated_app?.name,
|
1606 | 1424 | uid: fsentry.uid,
|
1607 | 1425 | path: fsentry.path,
|
1608 |
| - icon: await window.item_icon(fsentry), |
| 1426 | + icon: await item_icon(fsentry), |
1609 | 1427 | name: (dest_path === window.trash_path) ? $(el_item).attr('data-name') : fsentry.name,
|
1610 | 1428 | is_dir: fsentry.is_dir,
|
1611 | 1429 | size: fsentry.size,
|
@@ -1634,7 +1452,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){
|
1634 | 1452 | immutable: false,
|
1635 | 1453 | uid: dir.uid,
|
1636 | 1454 | path: dir.path,
|
1637 |
| - icon: await window.item_icon(dir), |
| 1455 | + icon: await item_icon(dir), |
1638 | 1456 | name: dir.name,
|
1639 | 1457 | size: dir.size,
|
1640 | 1458 | type: dir.type,
|
@@ -2277,7 +2095,7 @@ window.rename_file = async(options, new_name, old_name, old_path, el_item, el_it
|
2277 | 2095 | $(el_item_name_editor).hide();
|
2278 | 2096 |
|
2279 | 2097 | // Set new icon
|
2280 |
| - const new_icon = (options.is_dir ? window.icons['folder.svg'] : (await window.item_icon(fsentry)).image); |
| 2098 | + const new_icon = (options.is_dir ? window.icons['folder.svg'] : (await item_icon(fsentry)).image); |
2281 | 2099 | $(el_item_icon).find('.item-icon-icon').attr('src', new_icon);
|
2282 | 2100 |
|
2283 | 2101 | // Set new `data-name`
|
|
0 commit comments