@putkoff/abstract-securefiles 0.0.47 → 0.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/ConfirmButton.d.ts +5 -0
  2. package/dist/CopyButton.d.ts +4 -0
  3. package/dist/FolderSelect.d.ts +6 -0
  4. package/dist/SecureFiles.d.ts +3 -0
  5. package/dist/ServerFiles.d.ts +6 -0
  6. package/dist/ShareDialog.d.ts +6 -0
  7. package/dist/UploadPanel.d.ts +6 -0
  8. package/dist/api.d.ts +46 -0
  9. package/dist/index.cjs +539 -956
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +4 -8
  12. package/dist/index.js +531 -902
  13. package/dist/index.js.map +1 -1
  14. package/dist/types.d.ts +54 -0
  15. package/package.json +15 -11
  16. package/src/ConfirmButton.tsx +35 -0
  17. package/src/CopyButton.tsx +24 -0
  18. package/src/FolderSelect.tsx +68 -0
  19. package/src/SecureFiles.tsx +344 -0
  20. package/src/ServerFiles.tsx +324 -0
  21. package/src/ShareDialog.tsx +148 -0
  22. package/src/UploadPanel.tsx +217 -0
  23. package/src/api.ts +119 -0
  24. package/src/index.ts +4 -8
  25. package/src/styles.css +432 -0
  26. package/src/types.ts +54 -0
  27. package/css.d.ts +0 -2
  28. package/dist/App/SecureFiles.d.ts +0 -4
  29. package/dist/App/index.d.ts +0 -1
  30. package/dist/FileHandlers/FileRow/imports.d.ts +0 -2
  31. package/dist/FileHandlers/FileRow/index.d.ts +0 -1
  32. package/dist/FileHandlers/FileRow/src/index.d.ts +0 -1
  33. package/dist/FileHandlers/FileRow/src/row_utils.d.ts +0 -2
  34. package/dist/FileHandlers/FileTable/imports.d.ts +0 -4
  35. package/dist/FileHandlers/FileTable/index.d.ts +0 -1
  36. package/dist/FileHandlers/FileTable/src/index.d.ts +0 -1
  37. package/dist/FileHandlers/FileTable/src/table_utils.d.ts +0 -2
  38. package/dist/FileHandlers/ShareModal/imports.d.ts +0 -2
  39. package/dist/FileHandlers/ShareModal/index.d.ts +0 -1
  40. package/dist/FileHandlers/ShareModal/src/index.d.ts +0 -1
  41. package/dist/FileHandlers/ShareModal/src/share_utils.d.ts +0 -2
  42. package/dist/FileHandlers/Upload/imports.d.ts +0 -2
  43. package/dist/FileHandlers/Upload/index.d.ts +0 -1
  44. package/dist/FileHandlers/Upload/src/index.d.ts +0 -2
  45. package/dist/FileHandlers/Upload/src/upload_utils.d.ts +0 -2
  46. package/dist/FileHandlers/imports.d.ts +0 -4
  47. package/dist/FileHandlers/index.d.ts +0 -4
  48. package/dist/UI/index.d.ts +0 -28
  49. package/dist/file_utils/imports.d.ts +0 -2
  50. package/dist/file_utils/index.d.ts +0 -1
  51. package/dist/file_utils/src/cookieFetch.d.ts +0 -33
  52. package/dist/file_utils/src/delete_utils/imports.d.ts +0 -1
  53. package/dist/file_utils/src/delete_utils/index.d.ts +0 -1
  54. package/dist/file_utils/src/delete_utils/src/delete_row.d.ts +0 -2
  55. package/dist/file_utils/src/delete_utils/src/delete_select.d.ts +0 -4
  56. package/dist/file_utils/src/delete_utils/src/delete_selected.d.ts +0 -2
  57. package/dist/file_utils/src/delete_utils/src/index.d.ts +0 -3
  58. package/dist/file_utils/src/download_utils/imports.d.ts +0 -2
  59. package/dist/file_utils/src/download_utils/index.d.ts +0 -1
  60. package/dist/file_utils/src/download_utils/src/direct_download.d.ts +0 -3
  61. package/dist/file_utils/src/download_utils/src/download_file.d.ts +0 -6
  62. package/dist/file_utils/src/download_utils/src/download_select.d.ts +0 -2
  63. package/dist/file_utils/src/download_utils/src/index.d.ts +0 -5
  64. package/dist/file_utils/src/download_utils/src/target_downloads.d.ts +0 -4
  65. package/dist/file_utils/src/download_utils/src/trigger_download.d.ts +0 -2
  66. package/dist/file_utils/src/imports.d.ts +0 -2
  67. package/dist/file_utils/src/index.d.ts +0 -6
  68. package/dist/file_utils/src/list_utils/imports.d.ts +0 -1
  69. package/dist/file_utils/src/list_utils/index.d.ts +0 -1
  70. package/dist/file_utils/src/list_utils/src/index.d.ts +0 -1
  71. package/dist/file_utils/src/list_utils/src/list_utils.d.ts +0 -2
  72. package/dist/file_utils/src/select_utils/index.d.ts +0 -1
  73. package/dist/file_utils/src/select_utils/src/index.d.ts +0 -3
  74. package/dist/file_utils/src/select_utils/src/init_select_all.d.ts +0 -2
  75. package/dist/file_utils/src/select_utils/src/sync_header_checkbox.d.ts +0 -5
  76. package/dist/file_utils/src/select_utils/src/toggle_checkboxes.d.ts +0 -2
  77. package/dist/file_utils/src/share_utils/imports.d.ts +0 -1
  78. package/dist/file_utils/src/share_utils/index.d.ts +0 -1
  79. package/dist/file_utils/src/share_utils/src/index.d.ts +0 -1
  80. package/dist/file_utils/src/share_utils/src/share_utils.d.ts +0 -7
  81. package/dist/file_utils/src/upload_utils/imports.d.ts +0 -0
  82. package/dist/file_utils/src/upload_utils/index.d.ts +0 -1
  83. package/dist/file_utils/src/upload_utils/src/index.d.ts +0 -3
  84. package/dist/file_utils/src/upload_utils/src/patch_file_settings.d.ts +0 -2
  85. package/dist/file_utils/src/upload_utils/src/upload_file.d.ts +0 -2
  86. package/dist/file_utils/src/upload_utils/src/upload_files.d.ts +0 -5
  87. package/dist/hooks/imports.d.ts +0 -3
  88. package/dist/hooks/index.d.ts +0 -1
  89. package/dist/hooks/useFiles/imports.d.ts +0 -2
  90. package/dist/hooks/useFiles/index.d.ts +0 -1
  91. package/dist/hooks/useFiles/src/deleteFile.d.ts +0 -3
  92. package/dist/hooks/useFiles/src/index.d.ts +0 -6
  93. package/dist/hooks/useFiles/src/load.d.ts +0 -3
  94. package/dist/hooks/useFiles/src/patchShareSettings.d.ts +0 -3
  95. package/dist/hooks/useFiles/src/toggleShare.d.ts +0 -3
  96. package/dist/hooks/useFiles/src/useFiles.d.ts +0 -13
  97. package/dist/hooks/useFiles/src/useSaveShareSettings.d.ts +0 -7
  98. package/dist/imports.d.ts +0 -6
  99. package/dist/index.css +0 -1
  100. package/dist/styles/index.d.ts +0 -1
  101. package/dist/types/index.d.ts +0 -1
  102. package/dist/types/src/index.d.ts +0 -1
  103. package/dist/types/src/types.d.ts +0 -75
  104. package/index.ts +0 -1
  105. package/postcss.config.cjs +0 -8
  106. package/rollup.config.js +0 -38
  107. package/rollup.config.mjs +0 -35
  108. package/src/App/SecureFiles.tsx +0 -45
  109. package/src/App/index.ts +0 -1
  110. package/src/FileHandlers/FileRow/imports.ts +0 -2
  111. package/src/FileHandlers/FileRow/index.ts +0 -1
  112. package/src/FileHandlers/FileRow/src/index.ts +0 -1
  113. package/src/FileHandlers/FileRow/src/row_utils.tsx +0 -143
  114. package/src/FileHandlers/FileTable/imports.ts +0 -15
  115. package/src/FileHandlers/FileTable/index.ts +0 -1
  116. package/src/FileHandlers/FileTable/src/index.ts +0 -1
  117. package/src/FileHandlers/FileTable/src/table_utils.tsx +0 -251
  118. package/src/FileHandlers/ShareModal/imports.ts +0 -2
  119. package/src/FileHandlers/ShareModal/index.ts +0 -1
  120. package/src/FileHandlers/ShareModal/src/index.ts +0 -1
  121. package/src/FileHandlers/ShareModal/src/share_utils.tsx +0 -155
  122. package/src/FileHandlers/Upload/imports.ts +0 -3
  123. package/src/FileHandlers/Upload/index.ts +0 -1
  124. package/src/FileHandlers/Upload/src/index.ts +0 -2
  125. package/src/FileHandlers/Upload/src/upload_utils.tsx +0 -267
  126. package/src/FileHandlers/imports.ts +0 -17
  127. package/src/FileHandlers/index.ts +0 -4
  128. package/src/UI/index.tsx +0 -122
  129. package/src/custom.d.ts +0 -7
  130. package/src/file_utils/imports.ts +0 -2
  131. package/src/file_utils/index.ts +0 -1
  132. package/src/file_utils/src/cookieFetch.ts +0 -109
  133. package/src/file_utils/src/delete_utils/imports.ts +0 -1
  134. package/src/file_utils/src/delete_utils/index.ts +0 -1
  135. package/src/file_utils/src/delete_utils/src/delete_row.ts +0 -11
  136. package/src/file_utils/src/delete_utils/src/delete_select.ts +0 -10
  137. package/src/file_utils/src/delete_utils/src/delete_selected.ts +0 -15
  138. package/src/file_utils/src/delete_utils/src/index.ts +0 -3
  139. package/src/file_utils/src/download_utils/imports.ts +0 -3
  140. package/src/file_utils/src/download_utils/index.ts +0 -1
  141. package/src/file_utils/src/download_utils/src/direct_download.ts +0 -22
  142. package/src/file_utils/src/download_utils/src/download_file.ts +0 -25
  143. package/src/file_utils/src/download_utils/src/download_select.ts +0 -25
  144. package/src/file_utils/src/download_utils/src/index.ts +0 -5
  145. package/src/file_utils/src/download_utils/src/target_downloads.ts +0 -21
  146. package/src/file_utils/src/download_utils/src/trigger_download.ts +0 -14
  147. package/src/file_utils/src/imports.ts +0 -3
  148. package/src/file_utils/src/index.ts +0 -6
  149. package/src/file_utils/src/list_utils/imports.ts +0 -2
  150. package/src/file_utils/src/list_utils/index.ts +0 -1
  151. package/src/file_utils/src/list_utils/src/index.ts +0 -1
  152. package/src/file_utils/src/list_utils/src/list_utils.ts +0 -28
  153. package/src/file_utils/src/select_utils/index.ts +0 -1
  154. package/src/file_utils/src/select_utils/src/index.ts +0 -3
  155. package/src/file_utils/src/select_utils/src/init_select_all.ts +0 -37
  156. package/src/file_utils/src/select_utils/src/sync_header_checkbox.ts +0 -18
  157. package/src/file_utils/src/select_utils/src/toggle_checkboxes.ts +0 -11
  158. package/src/file_utils/src/share_utils/imports.ts +0 -1
  159. package/src/file_utils/src/share_utils/index.ts +0 -1
  160. package/src/file_utils/src/share_utils/src/index.ts +0 -1
  161. package/src/file_utils/src/share_utils/src/share_utils.ts +0 -20
  162. package/src/file_utils/src/upload_utils/imports.ts +0 -1
  163. package/src/file_utils/src/upload_utils/index.ts +0 -1
  164. package/src/file_utils/src/upload_utils/src/index.ts +0 -3
  165. package/src/file_utils/src/upload_utils/src/patch_file_settings.ts +0 -20
  166. package/src/file_utils/src/upload_utils/src/upload_file.ts +0 -27
  167. package/src/file_utils/src/upload_utils/src/upload_files.ts +0 -19
  168. package/src/hooks/imports.ts +0 -3
  169. package/src/hooks/index.ts +0 -1
  170. package/src/hooks/useFiles/imports.ts +0 -3
  171. package/src/hooks/useFiles/index.ts +0 -1
  172. package/src/hooks/useFiles/src/deleteFile.ts +0 -23
  173. package/src/hooks/useFiles/src/index.ts +0 -6
  174. package/src/hooks/useFiles/src/load.ts +0 -39
  175. package/src/hooks/useFiles/src/logs/clipit_logs.log +0 -0
  176. package/src/hooks/useFiles/src/logs/routes_bp.log +0 -0
  177. package/src/hooks/useFiles/src/patchShareSettings.ts +0 -27
  178. package/src/hooks/useFiles/src/toggleShare.ts +0 -28
  179. package/src/hooks/useFiles/src/useFiles.ts +0 -35
  180. package/src/hooks/useFiles/src/useSaveShareSettings.ts +0 -31
  181. package/src/imports.ts +0 -18
  182. package/src/styles/SecureFiles/App.css +0 -42
  183. package/src/styles/SecureFiles/index.css +0 -10
  184. package/src/styles/SecureFiles/logs/clipit_logs.log +0 -0
  185. package/src/styles/SecureFiles/logs/routes_bp.log +0 -0
  186. package/src/styles/SecureFiles/tailwind.css +0 -3
  187. package/src/styles/SecureFiles/window-manager.css +0 -283
  188. package/src/styles/SecureFilesStyles.module.css +0 -287
  189. package/src/styles/index.ts +0 -1
  190. package/src/types/index.ts +0 -1
  191. package/src/types/src/index.ts +0 -1
  192. package/src/types/src/types.ts +0 -88
  193. package/tailwind.config.cjs +0 -7
  194. package/testit.mjs +0 -11
  195. package/testit.ts +0 -3
  196. package/tsconfig.json +0 -27
  197. /package/src/{global.d.ts → css.d.ts} +0 -0
@@ -1,143 +0,0 @@
1
- import type { FileRowProps } from './../imports';
2
- import { useState, Button, currentUsername } from './../imports';
3
-
4
- export default function FileRow({
5
- file,
6
- onDownload,
7
- onSettings,
8
- onToggleShare,
9
- onDelete,
10
- }: FileRowProps) {
11
- const isOwner =
12
- file.uploader_id?.toLowerCase() === (currentUsername() ?? '').toLowerCase();
13
- const downloadAllowed = isOwner || file.shareable;
14
- const [isDownloading, setIsDownloading] = useState(false);
15
- const [isTogglingShare, setIsTogglingShare] = useState(false);
16
- const [isDeleting, setIsDeleting] = useState(false);
17
-
18
- // Mimic WindowManagerApp's unsaved heuristic
19
- const looksUnsaved =
20
- file.filename.toLowerCase().startsWith('untitled') ||
21
- file.filename.includes('*');
22
-
23
- const handleDownload = async () => {
24
- setIsDownloading(true);
25
- try {
26
- await onDownload();
27
- } finally {
28
- setIsDownloading(false);
29
- }
30
- };
31
-
32
- const handleToggleShare = async () => {
33
- setIsTogglingShare(true);
34
- try {
35
- await onToggleShare();
36
- } finally {
37
- setIsTogglingShare(false);
38
- }
39
- };
40
-
41
- const handleDeleteFile = async () => {
42
- setIsDeleting(true);
43
- try {
44
- await onDelete();
45
- } finally {
46
- setIsDeleting(false);
47
- }
48
- };
49
-
50
- return (
51
- <tr className="wm-row transition-colors duration-75">
52
- {/* Select checkbox */}
53
- <td className="wm-cell w-12 align-middle">
54
- <input
55
- type="checkbox"
56
- className="wm-checkbox"
57
- aria-label={`Select ${file.filename}`}
58
- />
59
- </td>
60
-
61
- {/* Filename */}
62
- <td className={`wm-cell ${looksUnsaved ? 'unsaved' : ''}`}>
63
- {file.filename}
64
- </td>
65
-
66
- {/* Download button or lock */}
67
- <td className="wm-cell w-12 align-middle">
68
- {downloadAllowed ? (
69
- <Button
70
- color="blue"
71
- variant="secondary"
72
- onClick={handleDownload}
73
- disabled={isDownloading}
74
- aria-label={`Download ${file.filename}`}
75
- className="wm-btn-link"
76
- >
77
- {isDownloading ? 'Downloading...' : 'Download'}
78
- </Button>
79
- ) : (
80
- <span
81
- className="text-gray-500 text-lg"
82
- aria-label="Download restricted"
83
- >
84
- 🔒
85
- </span>
86
- )}
87
- </td>
88
-
89
- {/* Settings cog */}
90
- <td className="wm-cell w-12 align-middle">
91
- {isOwner && (
92
- <Button
93
- color="gray"
94
- variant="icon"
95
- onClick={() => {
96
- console.log('⚙︎ clicked', file.id);
97
- onSettings();
98
- }}
99
- aria-label="Open share settings"
100
- className="wm-btn-icon text-lg"
101
- >
102
- ⚙️
103
- </Button>
104
- )}
105
- </td>
106
-
107
- {/* Share toggle */}
108
- <td className="wm-cell w-12 align-middle">
109
- {isOwner && (
110
- <Button
111
- color={file.shareable ? 'blue' : 'gray'}
112
- variant={file.shareable ? 'primary' : 'secondary'}
113
- onClick={handleToggleShare}
114
- disabled={isTogglingShare}
115
- className="btn"
116
- >
117
- {isTogglingShare
118
- ? 'Toggling...'
119
- : file.shareable
120
- ? 'Sharing'
121
- : 'Share'}
122
- </Button>
123
- )}
124
- </td>
125
-
126
- {/* Delete button */}
127
- <td className="wm-cell w-12 align-middle">
128
- {isOwner && (
129
- <Button
130
- color="gray"
131
- variant="icon"
132
- onClick={handleDeleteFile}
133
- disabled={isDeleting}
134
- className="wm-btn-icon text-lg"
135
- >
136
- 🗑
137
- </Button>
138
- )}
139
- </td>
140
- <td className="wm-cell">{file.download_count} / {file.download_limit ?? "∞"}</td>
141
- </tr>
142
- );
143
- }
@@ -1,15 +0,0 @@
1
- export {FileRow} from './../FileRow';
2
- export {ShareModal} from './../ShareModal';
3
- export type {
4
- FileItem ,
5
- FileTableProps
6
- } from './../imports';
7
- export {
8
- useState ,
9
- useFiles ,
10
- downloadFile ,
11
- Spinner ,
12
- Input,
13
- currentUsername,
14
- Button
15
- } from './../imports';
@@ -1 +0,0 @@
1
- export {FileTable} from './src'
@@ -1 +0,0 @@
1
- export {default as FileTable} from './table_utils'
@@ -1,251 +0,0 @@
1
- import type { FileItem, FileTableProps } from './../imports';
2
- import React, { useState, useMemo, ChangeEvent } from 'react';
3
- import {
4
- useFiles,
5
- downloadFile,
6
- Spinner,
7
- ShareModal,
8
- Input,
9
- Button,
10
- currentUsername
11
- } from './../imports';
12
- import { downloadSelected } from './../../../file_utils';
13
-
14
- // Tree node type
15
- interface FileNode {
16
- name: string;
17
- path: string;
18
- children: Map<string, FileNode>;
19
- files: FileItem[];
20
- }
21
-
22
- // Build a directory tree from a flat file list
23
- function buildTree(files: FileItem[]): FileNode {
24
- const root: FileNode = { name: '', path: '', children: new Map(), files: [] };
25
- files.forEach(file => {
26
- const parts = file.filepath.split('/');
27
- let node = root;
28
- parts.slice(0, -1).forEach((seg, idx) => {
29
- const subPath = parts.slice(0, idx + 1).join('/');
30
- if (!node.children.has(seg)) {
31
- node.children.set(seg, { name: seg, path: subPath, children: new Map(), files: [] });
32
- }
33
- node = node.children.get(seg)!;
34
- });
35
- node.files.push(file);
36
- });
37
- return root;
38
- }
39
-
40
- // Collect all file IDs under a node (recursive)
41
- function collectNodeIds(node: FileNode): Array<number | string> {
42
- let ids: Array<number | string> = [];
43
- node.files.forEach(f => ids.push(f.id));
44
- node.children.forEach(child => {
45
- ids = ids.concat(collectNodeIds(child));
46
- });
47
- return ids;
48
- }
49
-
50
- export default function FileTable({
51
- files,
52
- loading,
53
- error,
54
- onToggleShare,
55
- onPatchShare,
56
- onDelete
57
- }: FileTableProps) {
58
- const { load } = useFiles();
59
- const [search, setSearch] = useState('');
60
- const [modalFile, setModalFile] = useState<FileItem | null>(null);
61
- const [selected, setSelected] = useState<Set<number | string>>(new Set());
62
- const [expanded, setExpanded] = useState<Set<string>>(new Set());
63
-
64
- // Upload controls
65
- const [uploadDir, setUploadDir] = useState<string>('');
66
- const [uploadFile, setUploadFile] = useState<File | null>(null);
67
- const handleFileChange = (e: ChangeEvent<HTMLInputElement>) => setUploadFile(e.target.files?.[0] ?? null);
68
- const handleUpload = async () => {
69
- if (!uploadFile) return;
70
- const form = new FormData();
71
- form.append('file', uploadFile);
72
- const dirPart = uploadDir ? `${uploadDir}/` : '';
73
- const url = `/api/secure-files/upload/${dirPart}${encodeURIComponent(uploadFile.name)}`;
74
- await fetch(url, { method: 'POST', credentials: 'include', body: form });
75
- setUploadFile(null);
76
- load();
77
- };
78
-
79
- // Filter files by search term
80
- const filtered = useMemo(
81
- () => files.filter(f => f.filename.toLowerCase().includes(search.trim().toLowerCase())),
82
- [files, search]
83
- );
84
- // Build tree and directory paths list
85
- const tree = useMemo(() => buildTree(filtered), [filtered]);
86
- const allDirPaths = useMemo(() => {
87
- const paths: string[] = [''];
88
- function collect(node: FileNode) {
89
- node.children.forEach(child => {
90
- paths.push(child.path);
91
- collect(child);
92
- });
93
- }
94
- collect(tree);
95
- return paths;
96
- }, [tree]);
97
-
98
- // Selection & expand/collapse logic
99
- const allIds = filtered.map(f => f.id);
100
- const toggleAllSelection = () => selected.size < allIds.length ? setSelected(new Set(allIds)) : setSelected(new Set());
101
- const toggleDirOpen = (path: string) => setExpanded(prev => {
102
- const next = new Set(prev);
103
- next.has(path) ? next.delete(path) : next.add(path);
104
- return next;
105
- });
106
- const expandAll = () => setExpanded(new Set(allDirPaths));
107
- const collapseAll = () => setExpanded(new Set());
108
-
109
- // Recursive renderer: directory row with select-all checkbox, then its files, then subdirectories
110
- const renderNode = (node: FileNode, depth = 0): React.ReactNode[] => {
111
- const rows: React.ReactNode[] = [];
112
- if (node.path) {
113
- const isOpen = expanded.has(node.path);
114
- const nodeIds = collectNodeIds(node);
115
- const allSelected = nodeIds.every(id => selected.has(id));
116
- const someSelected = nodeIds.some(id => selected.has(id));
117
- rows.push(
118
- <tr key={node.path}>
119
- {/* Directory-level checkbox */}
120
- <td className="px-4 py-2 bg-gray-100">
121
- <input
122
- type="checkbox"
123
- checked={allSelected}
124
- ref={el => { if (el) el.indeterminate = !allSelected && someSelected; }}
125
- onChange={() => {
126
- setSelected(prev => {
127
- const next = new Set(prev);
128
- if (allSelected) {
129
- nodeIds.forEach(id => next.delete(id));
130
- } else {
131
- nodeIds.forEach(id => next.add(id));
132
- }
133
- return next;
134
- });
135
- }}
136
- />
137
- </td>
138
- {/* Directory label pushed left */}
139
- <td className="px-4 py-2 bg-gray-100 font-bold" colSpan={5} style={{ textAlign: 'left' }}>
140
- {node.path}
141
- </td>
142
- {/* Expand/collapse ticker on right */}
143
- <td className="px-4 py-2 bg-gray-100 text-right">
144
- <button onClick={() => toggleDirOpen(node.path)}>
145
- {isOpen ? '▾' : '▸'}
146
- </button>
147
- </td>
148
- </tr>
149
- );
150
- if (!isOpen) return rows;
151
- }
152
- // Render files in this directory
153
- node.files.sort((a, b) => a.filename.localeCompare(b.filename)).forEach(f => {
154
- const isOwner = f.uploader_id.toLowerCase() === (currentUsername() ?? '').toLowerCase();
155
- const canDownload = isOwner || f.shareable;
156
- rows.push(
157
- <tr key={f.id}>
158
- <td className="px-4 py-2">
159
- <input
160
- type="checkbox"
161
- checked={selected.has(f.id)}
162
- onChange={() => setSelected(prev => {
163
- const next = new Set(prev);
164
- next.has(f.id) ? next.delete(f.id) : next.add(f.id);
165
- return next;
166
- })}
167
- />
168
- </td>
169
- <td className="px-4 py-2" style={{ paddingLeft: (depth + 1) * 20 }}>
170
- {f.filename}
171
- </td>
172
- <td className="px-4 py-2">
173
- {canDownload ? <Button variant="secondary" onClick={() => downloadFile(f)}>Download</Button> : <span>🔒</span>}
174
- </td>
175
- <td className="px-4 py-2">
176
- {isOwner && <Button variant="icon" onClick={() => setModalFile(f)}>⚙️</Button>}
177
- </td>
178
- <td className="px-4 py-2">
179
- {isOwner && <Button variant={f.shareable ? 'primary' : 'secondary'} onClick={() => onToggleShare(f)}>{f.shareable ? 'Sharing' : 'Share'}</Button>}
180
- </td>
181
- <td className="px-4 py-2">
182
- {isOwner && <Button variant="icon" onClick={() => onDelete(f).then(load)}>🗑</Button>}
183
- </td>
184
- <td className="px-4 py-2">
185
- {f.download_count} / {f.download_limit ?? '∞'}
186
- </td>
187
- </tr>
188
- );
189
- });
190
- // Render subdirectories
191
- Array.from(node.children.values())
192
- .sort((a, b) => a.name.localeCompare(b.name))
193
- .forEach(child => rows.push(...renderNode(child, depth + 1)));
194
- return rows;
195
- };
196
-
197
- // Batch actions
198
- const handleDownloadAll = async () => {
199
- const inputs = filtered.filter(f => selected.has(f.id)).map(f => document.createElement('input'));
200
- inputs.forEach((cb, idx) => cb.value = filtered.filter(f => selected.has(f.id))[idx].filepath);
201
- await downloadSelected(inputs);
202
- };
203
- const handleDeleteAll = async () => { await onDelete(filtered.filter(f => selected.has(f.id))); setSelected(new Set()); await load(); };
204
- const handleShareAll = async () => { for (const f of filtered.filter(f => selected.has(f.id))) await onToggleShare(f); };
205
-
206
- if (loading) return <Spinner />;
207
- if (error) return <p className="text-red-600">{error.message}</p>;
208
-
209
- return (
210
- <>
211
-
212
-
213
- {/* Search & actions */}
214
- <div className="mb-4 flex flex-col md:flex-row md:justify-between gap-4">
215
- <Input label="Search files" type="text" value={search} onChange={(e:any) => setSearch(e.target.value)} placeholder="Enter filename…" className="form-input flex-1" />
216
- <div className="flex gap-2">
217
- <Button onClick={expandAll} disabled={!allDirPaths.length}>Expand All</Button>
218
- <Button onClick={collapseAll} disabled={!allDirPaths.length}>Collapse All</Button>
219
- <Button onClick={handleDownloadAll} disabled={!selected.size}>Download Selected</Button>
220
- <Button color="gray" onClick={handleDeleteAll} disabled={!selected.size}>Delete Selected</Button>
221
- <Button onClick={handleShareAll} disabled={!selected.size}>Share Selected</Button>
222
- </div>
223
- </div>
224
-
225
- {/* File tree table */}
226
- <div className="overflow-x-auto wm-container">
227
- <table className="file-table w-full">
228
- <thead className="wm-thead">
229
- <tr>
230
- <th className="px-4 py-2 w-12"><input type="checkbox" checked={selected.size === filtered.length && filtered.length > 0} onChange={toggleAllSelection} /></th>
231
- <th className="px-4 py-2">Filename</th>
232
- <th className="px-4 py-2">Download</th>
233
- <th className="px-4 py-2">Settings</th>
234
- <th className="px-4 py-2">Share</th>
235
- <th className="px-4 py-2">Delete</th>
236
- <th className="px-4 py-2">Downloads</th>
237
- </tr>
238
- </thead>
239
- <tbody>{renderNode(tree)}</tbody>
240
- </table>
241
- </div>
242
-
243
- <ShareModal file={modalFile} onClose={() => setModalFile(null)} onSave={async patch => {
244
- if (!modalFile) return;
245
- const updated: FileItem = { ...modalFile, ...patch };
246
- await onPatchShare(updated);
247
- setModalFile(null);
248
- }} />
249
- </>
250
- );
251
- }
@@ -1,2 +0,0 @@
1
- export {Button, Checkbox, Input, ClipboardIcon, createPortal, useEffect, useRef, useState} from './../imports'
2
- export type {ShareModalProps} from './../imports'
@@ -1 +0,0 @@
1
- export {ShareModal} from './src';
@@ -1 +0,0 @@
1
- export {default as ShareModal} from './share_utils';
@@ -1,155 +0,0 @@
1
- import type {
2
- ShareModalProps
3
- } from './../../imports';
4
- import {
5
- Button,
6
- Checkbox,
7
- Input,
8
- ClipboardIcon,
9
- createPortal,
10
- useEffect,
11
- useRef,
12
- useState,
13
- } from './../imports';
14
-
15
- export default function ShareModal({ file, onClose, onSave }: ShareModalProps) {
16
- const [fileId, setFileId] = useState<string | number | "">("");
17
- const [enabled, setEnabled] = useState<any>(false);
18
- const [password, setPassword] = useState<any>(undefined);
19
- const [strPassword, setStrPassword] = useState<any>("");
20
- const [download_limit, setDownloadLimit] = useState<number | "">(0);
21
- const [error, setError] = useState("");
22
- const [busy, setBusy] = useState(false);
23
- const modalRef = useRef<HTMLDivElement>(null);
24
-
25
- const shareLink =
26
- file && enabled
27
- ? `/api/secure-files/secure-download/${file.id}`
28
- : "";
29
-
30
- useEffect(() => {
31
- if (!file) return;
32
- setFileId(file.id);
33
- setEnabled(file.shareable);
34
- setPassword(file.share_password);
35
- setStrPassword(file.password_str ?? "");
36
- setDownloadLimit(file.download_limit ?? 0);
37
- setError("");
38
-
39
- modalRef.current?.focus();
40
- }, [file]);
41
-
42
-
43
- useEffect(() => {
44
- const h = (e: KeyboardEvent) => e.key === "Escape" && onClose();
45
- window.addEventListener("keydown", h);
46
- return () => window.removeEventListener("keydown", h);
47
- }, [onClose]);
48
-
49
- if (!file) return null;
50
-
51
- async function handleSave() {
52
- if (strPassword && strPassword.length < 4) {
53
- setError("Password must be at least 4 characters");
54
- return;
55
- }
56
- setBusy(true);
57
- const save_dict = {
58
- id: fileId,
59
- shareable: enabled,
60
- needsPassword: !!strPassword,
61
- share_password: strPassword || null,
62
- password_str: strPassword || null,
63
- download_limit: download_limit === "" ? null : Number(download_limit),
64
- }
65
-
66
- try {
67
- const resp = await onSave(save_dict);
68
-
69
- onClose();
70
- } catch (err) {
71
- setError(`${err} Failed to save settings. Please try again.`);
72
- } finally {
73
- setBusy(false);
74
- }
75
- }
76
-
77
- return createPortal(
78
- <>
79
- <div
80
- className="modal-backdrop z-100"
81
- onClick={(e) => e.target === e.currentTarget && onClose()}
82
- />
83
- <div className="modal-wrapper z-110">
84
- <div
85
- ref={modalRef}
86
- role="dialog"
87
- aria-modal="true"
88
- tabIndex={-1}
89
- className="modal-panel"
90
- >
91
- <h3 className="form-title">
92
- Share settings for <span className="font-mono">{file.filename}</span>
93
- </h3>
94
-
95
- {error && <p className="form-error">{error}</p>}
96
-
97
- <Checkbox
98
- label="Enable sharing"
99
- checked={enabled}
100
- onChange={(e:any) => setEnabled(e.target.checked)}
101
- className="checkbox"
102
- />
103
-
104
- <Input
105
- label="Password (optional)"
106
- type="text"
107
- value={strPassword}
108
- onChange={(e:any) => setStrPassword(e.target.value)}
109
- disabled={!enabled}
110
- className="form-input"
111
- />
112
- <Input
113
- label="Download limit (0 = ∞)"
114
- type="number"
115
- min={0}
116
- value={download_limit}
117
- onChange={(e:any) =>
118
- setDownloadLimit(e.target.value === "" ? "" : Number(e.target.value))
119
- }
120
- disabled={!enabled}
121
- className="form-input"
122
- />
123
-
124
- {enabled && shareLink && (
125
- <Input
126
- label="Share link"
127
- readOnly
128
- value={shareLink}
129
- className="form-input"
130
- trailing={
131
- <Button
132
- variant="icon"
133
- className="btn-icon"
134
- onClick={() => navigator.clipboard.writeText(shareLink)}
135
- >
136
- <ClipboardIcon className="h-5 w-5" />
137
- </Button>
138
- }
139
- />
140
- )}
141
-
142
- <div className="mt-6 flex justify-end gap-2">
143
- <Button color="green" variant="primary" onClick={handleSave} disabled={busy} className="btn-primary">
144
- {busy ? "Saving…" : "Save"}
145
- </Button>
146
- <Button variant="secondary" onClick={onClose} disabled={busy} className="btn-secondary">
147
- Cancel
148
- </Button>
149
- </div>
150
- </div>
151
- </div>
152
- </>,
153
- document.body
154
- );
155
- }
@@ -1,3 +0,0 @@
1
- // src/components/Upload/index.tsx
2
- export {Input,useFiles,Button,uploadFiles,useState, useRef,useCallback,CloudArrowUpIcon,currentUsername} from './../imports';
3
- export type {UploadProps,FileItem,QueuedFile} from './../imports'
@@ -1 +0,0 @@
1
- export {Upload} from './src';
@@ -1,2 +0,0 @@
1
- export {default as Upload} from './upload_utils';
2
- export type {QueuedFile,UploadProps} from './../../../types';