@putkoff/abstract-securefiles 0.0.25 → 0.0.27
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.
- package/css.d.ts +0 -0
- package/dist/index.cjs +3 -933
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.js +5 -884
- package/dist/index.js.map +1 -1
- package/dist/{App/SecureFiles.d.ts → secure_files.d.ts} +1 -1
- package/index.ts +0 -0
- package/package.json +4 -4
- package/postcss.config.cjs +0 -0
- package/rollup.config.mjs +0 -0
- package/src/index.ts +1 -8
- package/src/{App/SecureFiles.tsx → secure_files.tsx} +4 -3
- package/tailwind.config.cjs +0 -0
- package/tsconfig.json +0 -0
- package/dist/App/index.d.ts +0 -1
- package/dist/FileHandlers/FileRow/imports.d.ts +0 -2
- package/dist/FileHandlers/FileRow/index.d.ts +0 -1
- package/dist/FileHandlers/FileRow/src/index.d.ts +0 -1
- package/dist/FileHandlers/FileRow/src/row_utils.d.ts +0 -2
- package/dist/FileHandlers/FileTable/imports.d.ts +0 -4
- package/dist/FileHandlers/FileTable/index.d.ts +0 -1
- package/dist/FileHandlers/FileTable/src/index.d.ts +0 -1
- package/dist/FileHandlers/FileTable/src/table_utils.d.ts +0 -2
- package/dist/FileHandlers/ShareModal/imports.d.ts +0 -2
- package/dist/FileHandlers/ShareModal/index.d.ts +0 -1
- package/dist/FileHandlers/ShareModal/src/index.d.ts +0 -1
- package/dist/FileHandlers/ShareModal/src/share_utils.d.ts +0 -2
- package/dist/FileHandlers/Upload/imports.d.ts +0 -2
- package/dist/FileHandlers/Upload/index.d.ts +0 -1
- package/dist/FileHandlers/Upload/src/index.d.ts +0 -2
- package/dist/FileHandlers/Upload/src/upload_utils.d.ts +0 -2
- package/dist/FileHandlers/imports.d.ts +0 -4
- package/dist/FileHandlers/index.d.ts +0 -4
- package/dist/UI/index.d.ts +0 -19
- package/dist/file_utils/imports.d.ts +0 -2
- package/dist/file_utils/index.d.ts +0 -1
- package/dist/file_utils/src/delete_utils/imports.d.ts +0 -1
- package/dist/file_utils/src/delete_utils/index.d.ts +0 -1
- package/dist/file_utils/src/delete_utils/src/delete_row.d.ts +0 -2
- package/dist/file_utils/src/delete_utils/src/delete_select.d.ts +0 -1
- package/dist/file_utils/src/delete_utils/src/delete_selected.d.ts +0 -2
- package/dist/file_utils/src/delete_utils/src/index.d.ts +0 -3
- package/dist/file_utils/src/download_utils/imports.d.ts +0 -2
- package/dist/file_utils/src/download_utils/index.d.ts +0 -1
- package/dist/file_utils/src/download_utils/src/direct_download.d.ts +0 -3
- package/dist/file_utils/src/download_utils/src/download_file.d.ts +0 -2
- package/dist/file_utils/src/download_utils/src/download_select.d.ts +0 -2
- package/dist/file_utils/src/download_utils/src/index.d.ts +0 -5
- package/dist/file_utils/src/download_utils/src/target_downloads.d.ts +0 -4
- package/dist/file_utils/src/download_utils/src/trigger_download.d.ts +0 -2
- package/dist/file_utils/src/imports.d.ts +0 -2
- package/dist/file_utils/src/index.d.ts +0 -6
- package/dist/file_utils/src/list_utils/imports.d.ts +0 -2
- package/dist/file_utils/src/list_utils/index.d.ts +0 -1
- package/dist/file_utils/src/list_utils/src/index.d.ts +0 -1
- package/dist/file_utils/src/list_utils/src/list_utils.d.ts +0 -2
- package/dist/file_utils/src/select_utils/index.d.ts +0 -1
- package/dist/file_utils/src/select_utils/src/index.d.ts +0 -3
- package/dist/file_utils/src/select_utils/src/init_select_all.d.ts +0 -2
- package/dist/file_utils/src/select_utils/src/sync_header_checkbox.d.ts +0 -5
- package/dist/file_utils/src/select_utils/src/toggle_checkboxes.d.ts +0 -2
- package/dist/file_utils/src/share_utils/imports.d.ts +0 -2
- package/dist/file_utils/src/share_utils/index.d.ts +0 -1
- package/dist/file_utils/src/share_utils/src/index.d.ts +0 -1
- package/dist/file_utils/src/share_utils/src/share_utils.d.ts +0 -7
- package/dist/file_utils/src/upload_utils/imports.d.ts +0 -1
- package/dist/file_utils/src/upload_utils/index.d.ts +0 -1
- package/dist/file_utils/src/upload_utils/src/index.d.ts +0 -3
- package/dist/file_utils/src/upload_utils/src/patch_file_settings.d.ts +0 -2
- package/dist/file_utils/src/upload_utils/src/upload_file.d.ts +0 -2
- package/dist/file_utils/src/upload_utils/src/upload_files.d.ts +0 -5
- package/dist/hooks/imports.d.ts +0 -3
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/useFiles/imports.d.ts +0 -2
- package/dist/hooks/useFiles/index.d.ts +0 -1
- package/dist/hooks/useFiles/src/deleteFile.d.ts +0 -6
- package/dist/hooks/useFiles/src/index.d.ts +0 -6
- package/dist/hooks/useFiles/src/load.d.ts +0 -6
- package/dist/hooks/useFiles/src/patchShareSettings.d.ts +0 -7
- package/dist/hooks/useFiles/src/toggleShare.d.ts +0 -6
- package/dist/hooks/useFiles/src/useFiles.d.ts +0 -13
- package/dist/hooks/useFiles/src/useSaveShareSettings.d.ts +0 -3
- package/dist/imports.d.ts +0 -5
- package/dist/styles/index.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/types.d.ts +0 -75
- package/src/App/index.ts +0 -1
- package/src/FileHandlers/FileRow/imports.ts +0 -2
- package/src/FileHandlers/FileRow/index.ts +0 -1
- package/src/FileHandlers/FileRow/src/index.ts +0 -1
- package/src/FileHandlers/FileRow/src/row_utils.tsx +0 -143
- package/src/FileHandlers/FileTable/imports.ts +0 -16
- package/src/FileHandlers/FileTable/index.ts +0 -1
- package/src/FileHandlers/FileTable/src/index.ts +0 -1
- package/src/FileHandlers/FileTable/src/table_utils.tsx +0 -251
- package/src/FileHandlers/ShareModal/imports.ts +0 -2
- package/src/FileHandlers/ShareModal/index.ts +0 -1
- package/src/FileHandlers/ShareModal/src/index.ts +0 -1
- package/src/FileHandlers/ShareModal/src/share_utils.tsx +0 -158
- package/src/FileHandlers/Upload/imports.ts +0 -3
- package/src/FileHandlers/Upload/index.ts +0 -1
- package/src/FileHandlers/Upload/src/index.ts +0 -2
- package/src/FileHandlers/Upload/src/upload_utils.tsx +0 -267
- package/src/FileHandlers/imports.ts +0 -20
- package/src/FileHandlers/index.ts +0 -4
- package/src/UI/index.tsx +0 -113
- package/src/custom.d.ts +0 -7
- package/src/file_utils/imports.ts +0 -2
- package/src/file_utils/index.ts +0 -1
- package/src/file_utils/src/delete_utils/imports.ts +0 -1
- package/src/file_utils/src/delete_utils/index.ts +0 -1
- package/src/file_utils/src/delete_utils/src/delete_row.ts +0 -11
- package/src/file_utils/src/delete_utils/src/delete_select.ts +0 -9
- package/src/file_utils/src/delete_utils/src/delete_selected.ts +0 -15
- package/src/file_utils/src/delete_utils/src/index.ts +0 -3
- package/src/file_utils/src/download_utils/imports.ts +0 -3
- package/src/file_utils/src/download_utils/index.ts +0 -1
- package/src/file_utils/src/download_utils/src/direct_download.ts +0 -22
- package/src/file_utils/src/download_utils/src/download_file.ts +0 -24
- package/src/file_utils/src/download_utils/src/download_select.ts +0 -20
- package/src/file_utils/src/download_utils/src/index.ts +0 -5
- package/src/file_utils/src/download_utils/src/target_downloads.ts +0 -21
- package/src/file_utils/src/download_utils/src/trigger_download.ts +0 -14
- package/src/file_utils/src/imports.ts +0 -3
- package/src/file_utils/src/index.ts +0 -6
- package/src/file_utils/src/list_utils/imports.ts +0 -2
- package/src/file_utils/src/list_utils/index.ts +0 -1
- package/src/file_utils/src/list_utils/src/index.ts +0 -1
- package/src/file_utils/src/list_utils/src/list_utils.ts +0 -24
- package/src/file_utils/src/select_utils/index.ts +0 -1
- package/src/file_utils/src/select_utils/src/index.ts +0 -3
- package/src/file_utils/src/select_utils/src/init_select_all.ts +0 -37
- package/src/file_utils/src/select_utils/src/sync_header_checkbox.ts +0 -18
- package/src/file_utils/src/select_utils/src/toggle_checkboxes.ts +0 -11
- package/src/file_utils/src/share_utils/imports.ts +0 -2
- package/src/file_utils/src/share_utils/index.ts +0 -1
- package/src/file_utils/src/share_utils/src/index.ts +0 -1
- package/src/file_utils/src/share_utils/src/share_utils.ts +0 -29
- package/src/file_utils/src/upload_utils/imports.ts +0 -1
- package/src/file_utils/src/upload_utils/index.ts +0 -1
- package/src/file_utils/src/upload_utils/src/index.ts +0 -3
- package/src/file_utils/src/upload_utils/src/patch_file_settings.ts +0 -18
- package/src/file_utils/src/upload_utils/src/upload_file.ts +0 -28
- package/src/file_utils/src/upload_utils/src/upload_files.ts +0 -34
- package/src/global.d.ts +0 -1
- package/src/hooks/imports.ts +0 -3
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useFiles/imports.ts +0 -3
- package/src/hooks/useFiles/index.ts +0 -1
- package/src/hooks/useFiles/src/deleteFile.ts +0 -22
- package/src/hooks/useFiles/src/index.ts +0 -6
- package/src/hooks/useFiles/src/load.ts +0 -52
- package/src/hooks/useFiles/src/logs/routes_bp.log +0 -0
- package/src/hooks/useFiles/src/patchShareSettings.ts +0 -37
- package/src/hooks/useFiles/src/toggleShare.ts +0 -28
- package/src/hooks/useFiles/src/useFiles.ts +0 -35
- package/src/hooks/useFiles/src/useSaveShareSettings.ts +0 -25
- package/src/imports.ts +0 -20
- package/src/styles/SecureFiles/logs/clipit_logs.log +0 -0
- package/src/styles/SecureFiles/logs/routes_bp.log +0 -0
- package/src/styles/SecureFilesStyles.module.css +0 -287
- package/src/styles/index.ts +0 -1
- package/src/types/index.ts +0 -1
- package/src/types/src/index.ts +0 -1
- package/src/types/src/types.ts +0 -88
- package/test/package-lock.json +0 -979
- package/test/package.json +0 -23
- package/test/test_entry.ts +0 -8
- package/test/tsconfig.json +0 -12
- /package/{src/hooks/useFiles/src/logs/clipit_logs.log → package.tmp.json} +0 -0
- /package/src/styles/{SecureFiles/App.css → App.css} +0 -0
- /package/src/styles/{SecureFiles/index.css → index.css} +0 -0
- /package/src/styles/{SecureFiles/tailwind.css → tailwind.css} +0 -0
- /package/src/styles/{SecureFiles/window-manager.css → window-manager.css} +0 -0
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { requireToken, secureFetchIt, FileItem } from './../imports';
|
|
2
|
-
import { triggerDownload } from './trigger_download';
|
|
3
|
-
export async function downloadFile(item: FileItem): Promise<void> {
|
|
4
|
-
const token = localStorage.getItem("token");
|
|
5
|
-
if (!token) throw new Error("No auth token found");
|
|
6
|
-
|
|
7
|
-
const res = await fetch("https://abstractendeavors.com/api/secure-files/secure-download/", {
|
|
8
|
-
method: "POST",
|
|
9
|
-
headers: {
|
|
10
|
-
Authorization: `Bearer ${token}`,
|
|
11
|
-
"Content-Type": "application/json",
|
|
12
|
-
// Don’t over-constrain Accept; let server pick proper content-type
|
|
13
|
-
// Accept: "application/octet-stream",
|
|
14
|
-
},
|
|
15
|
-
body: JSON.stringify(item),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (!res.ok) throw new Error(`Download failed: ${res.status}`);
|
|
19
|
-
|
|
20
|
-
// Stream-friendly: if your triggerDownload revokes URL immediately, wait a tick
|
|
21
|
-
const blob = await res.blob();
|
|
22
|
-
const name = item.filename || "download";
|
|
23
|
-
triggerDownload(blob, name); // ensure this waits ~0-100ms before URL.revokeObjectURL
|
|
24
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {requireToken,secureFetchIt,FileItem} from './../imports';
|
|
2
|
-
import {triggerDownload} from './trigger_download';
|
|
3
|
-
export async function downloadSelect(item: FileItem): Promise<void> {
|
|
4
|
-
const token: string = requireToken();
|
|
5
|
-
const body = item
|
|
6
|
-
const headers = {
|
|
7
|
-
Authorization: `Bearer ${token}`,
|
|
8
|
-
Accept: "application/octet-stream",
|
|
9
|
-
"Content-Type": "application/json"
|
|
10
|
-
}
|
|
11
|
-
const blob = await secureFetchIt( "download", body, "POST", headers, true, true) as Blob;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!blob || blob.size === 0) {
|
|
16
|
-
throw new Error(`Received empty file data for “${item.filename}”`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
triggerDownload(blob, item.filename);
|
|
20
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {downloadSelect} from './download_select';
|
|
2
|
-
import type {FileItem} from './../imports'
|
|
3
|
-
/** Given a checkbox inside a table-row → download that row’s file. */
|
|
4
|
-
export async function downloadRow(cb: HTMLInputElement): Promise<void> {
|
|
5
|
-
const row = cb.closest("tr") as HTMLTableRowElement | null;
|
|
6
|
-
const filepath = cb.value;
|
|
7
|
-
const filename = row?.children[1]?.textContent?.trim() || "downloaded_file";
|
|
8
|
-
if (filepath) await downloadSelect({filepath,filename} as any);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** Bulk download: pass a NodeList or array of checkboxes. */
|
|
12
|
-
export async function downloadSelected(checkboxes: Iterable<HTMLInputElement>): Promise<void> {
|
|
13
|
-
const list = Array.from(checkboxes);
|
|
14
|
-
if (!list.length) {
|
|
15
|
-
alert("No files selected.");
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
for (const cb of list) {
|
|
19
|
-
await downloadRow(cb);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** Helper function to trigger file download */
|
|
2
|
-
export function triggerDownload(blob: Blob, filename: string): void {
|
|
3
|
-
const url = URL.createObjectURL(blob);
|
|
4
|
-
const a = Object.assign(document.createElement("a"), {
|
|
5
|
-
href: url,
|
|
6
|
-
download: filename,
|
|
7
|
-
});
|
|
8
|
-
document.body.appendChild(a);
|
|
9
|
-
a.click();
|
|
10
|
-
a.remove();
|
|
11
|
-
URL.revokeObjectURL(url);
|
|
12
|
-
|
|
13
|
-
console.log(`✅ Successfully downloaded: ${filename}`);
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './list_utils';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { secureFetchIt } from './../imports';
|
|
2
|
-
import type { ApiRow, FileItem } from './../imports';
|
|
3
|
-
/** GET /secure-list */
|
|
4
|
-
export async function listFiles(setFiles: any = null): Promise<any> {
|
|
5
|
-
/** ← your request already returns the raw array */
|
|
6
|
-
const apiRows = await secureFetchIt("/list", null, "GET", null, false, true) as ApiRow[]
|
|
7
|
-
|
|
8
|
-
/** map API → UI ------------------------------------------------ */
|
|
9
|
-
const rows: FileItem[] = apiRows.map((r: ApiRow) => ({
|
|
10
|
-
id: r.id,
|
|
11
|
-
filename: r.filename,
|
|
12
|
-
uploader_id: r.uploader_id,
|
|
13
|
-
filepath: r.filepath,
|
|
14
|
-
created_at: r.created_at,
|
|
15
|
-
download_count: r.download_count,
|
|
16
|
-
download_limit: r.download_limit,
|
|
17
|
-
shareable: Boolean(r.shareable),
|
|
18
|
-
needsPassword: !!r.share_password,
|
|
19
|
-
share_password: r.share_password,
|
|
20
|
-
password_str: r.password_str,
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
setFiles(rows);
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {syncHeaderCheckbox} from './sync_header_checkbox';
|
|
2
|
-
/** Wire up header + row checkboxes once the table is in the DOM. */
|
|
3
|
-
export function initSelectAll(): void {
|
|
4
|
-
const header = document.getElementById(
|
|
5
|
-
"select-all-checkbox"
|
|
6
|
-
) as HTMLInputElement;
|
|
7
|
-
const btn = document.getElementById("select-all") as HTMLButtonElement;
|
|
8
|
-
|
|
9
|
-
// 1) header → toggle all
|
|
10
|
-
header.addEventListener("change", (e) => {
|
|
11
|
-
const on = (e.target as HTMLInputElement).checked;
|
|
12
|
-
document
|
|
13
|
-
.querySelectorAll<HTMLInputElement>(".file-checkbox")
|
|
14
|
-
.forEach((cb) => (cb.checked = on));
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// 2) button → toggle all
|
|
18
|
-
btn.addEventListener("click", () => {
|
|
19
|
-
const cbs = Array.from(
|
|
20
|
-
document.querySelectorAll<HTMLInputElement>(".file-checkbox")
|
|
21
|
-
);
|
|
22
|
-
if (!cbs.length) {
|
|
23
|
-
alert("No files to select.");
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const anyUnchecked = cbs.some((cb) => !cb.checked);
|
|
27
|
-
cbs.forEach((cb) => (cb.checked = anyUnchecked));
|
|
28
|
-
syncHeaderCheckbox();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// 3) row boxes → keep header state
|
|
32
|
-
document
|
|
33
|
-
.querySelectorAll<HTMLInputElement>(".file-checkbox")
|
|
34
|
-
.forEach((cb) => cb.addEventListener("change", syncHeaderCheckbox));
|
|
35
|
-
|
|
36
|
-
syncHeaderCheckbox();
|
|
37
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Classic “select all rows” logic (still handy in non-React views
|
|
3
|
-
* such as the admin dashboard).
|
|
4
|
-
*/
|
|
5
|
-
export function syncHeaderCheckbox(): void {
|
|
6
|
-
const all = document.querySelectorAll<HTMLInputElement>(".file-checkbox");
|
|
7
|
-
const checked = document.querySelectorAll<HTMLInputElement>(
|
|
8
|
-
".file-checkbox:checked"
|
|
9
|
-
);
|
|
10
|
-
const header = document.getElementById(
|
|
11
|
-
"select-all-checkbox"
|
|
12
|
-
) as HTMLInputElement;
|
|
13
|
-
|
|
14
|
-
header.indeterminate =
|
|
15
|
-
checked.length > 0 && checked.length < all.length;
|
|
16
|
-
header.checked = checked.length === all.length;
|
|
17
|
-
}
|
|
18
|
-
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {syncHeaderCheckbox} from './sync_header_checkbox';
|
|
2
|
-
/** Utility for other screens: toggle a list of checkboxes on/off. */
|
|
3
|
-
export function toggleCheckboxes(cbs: HTMLInputElement[]): void {
|
|
4
|
-
if (!cbs.length) {
|
|
5
|
-
alert("No files to select.");
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const anyUnchecked = cbs.some((cb) => !cb.checked);
|
|
9
|
-
cbs.forEach((cb) => (cb.checked = anyUnchecked));
|
|
10
|
-
syncHeaderCheckbox();
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './share_utils';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {FileItem,fetchSharePatch} from './../imports'
|
|
2
|
-
export function getToggleShare(file:any){
|
|
3
|
-
if (file == true || file?.shareable == true){
|
|
4
|
-
return false
|
|
5
|
-
}
|
|
6
|
-
return false
|
|
7
|
-
}
|
|
8
|
-
export function updateFileShare(file:any){
|
|
9
|
-
let updated: FileItem = file
|
|
10
|
-
const boolIt = getToggleShare(updated)
|
|
11
|
-
updated = { ...file, shareable: boolIt };
|
|
12
|
-
return updated;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Custom hook to toggle share settings on a file item
|
|
17
|
-
*/
|
|
18
|
-
export async function toggleShare(file:FileItem){
|
|
19
|
-
|
|
20
|
-
const updated = updateFileShare(file)
|
|
21
|
-
try {
|
|
22
|
-
const resp = await fetchSharePatch(updated);
|
|
23
|
-
|
|
24
|
-
} catch (err: any) {
|
|
25
|
-
console.error('Failed to toggle share settings', err);
|
|
26
|
-
// Optionally revert UI state or show an error message
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { secureFetchIt } from './../imports';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/** Generic PATCH helper kept for other admin forms */
|
|
3
|
-
export async function patchFileSetting(
|
|
4
|
-
fileId: string,
|
|
5
|
-
field: string,
|
|
6
|
-
value: unknown
|
|
7
|
-
): Promise<Record<string, unknown>> {
|
|
8
|
-
const res = await fetch(`/files/${fileId}/settings/${field}`, {
|
|
9
|
-
method: "PATCH",
|
|
10
|
-
headers: { "Content-Type": "application/json" },
|
|
11
|
-
body: JSON.stringify({ value }),
|
|
12
|
-
});
|
|
13
|
-
if (!res.ok) {
|
|
14
|
-
const err = await res.json();
|
|
15
|
-
throw new Error(err.error || res.statusText);
|
|
16
|
-
}
|
|
17
|
-
return (await res.json()) as Record<string, unknown>;
|
|
18
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { secureFetchIt } from './../imports';
|
|
2
|
-
/** Classic file-upload for the fallback HTML page. */
|
|
3
|
-
export async function uploadFile(file:any,subdir:any): Promise<any> {
|
|
4
|
-
const fileInput = file || document.getElementById(
|
|
5
|
-
"file-browser"
|
|
6
|
-
) as HTMLInputElement;
|
|
7
|
-
const subdirInput = subdir || document.getElementById("subdir") as HTMLInputElement;
|
|
8
|
-
const banner = document.getElementById("banner") as HTMLElement;
|
|
9
|
-
|
|
10
|
-
if (!fileInput.files?.length) {
|
|
11
|
-
alert("No file selected.");
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const formData = new FormData();
|
|
16
|
-
formData.append("file", fileInput.files[0]);
|
|
17
|
-
formData.append("subdir", subdirInput.value.trim());
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const json = await secureFetchIt("upload", formData, "POST", null, false,false) as { filepath: string };
|
|
21
|
-
banner.textContent = `Uploaded: ${json.filepath}`;
|
|
22
|
-
fileInput.value = "";
|
|
23
|
-
subdirInput.value = "";
|
|
24
|
-
window.location.reload(); // no-op in React view
|
|
25
|
-
} catch (err: any) {
|
|
26
|
-
console.error("Upload failed", err);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { secureFetchIt } from './../imports';
|
|
2
|
-
|
|
3
|
-
interface UploadResponse {
|
|
4
|
-
filepath: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export async function uploadFiles(file: File, subdir: string = ''): Promise<UploadResponse> {
|
|
8
|
-
if (!(file instanceof File)) {
|
|
9
|
-
throw new Error('Invalid file: Must be a File object.');
|
|
10
|
-
}
|
|
11
|
-
if (typeof subdir !== 'string') {
|
|
12
|
-
throw new Error('Invalid subdir: Must be a string.');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const formData = new FormData();
|
|
16
|
-
formData.append('file', file);
|
|
17
|
-
formData.append('subdir', subdir.trim());
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const json = await secureFetchIt('upload', formData, 'POST', null, false, false);
|
|
21
|
-
|
|
22
|
-
if (!json || typeof json !== 'object') {
|
|
23
|
-
throw new Error('Invalid response from server.');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!('filepath' in json) || typeof json.filepath !== 'string' || !json.filepath) {
|
|
27
|
-
throw new Error('Server response missing or invalid filepath.');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return { filepath: json.filepath };
|
|
31
|
-
} catch (err: any) {
|
|
32
|
-
throw new Error(`Upload failed: ${err?.message ?? 'Unknown error'}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
package/src/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module "*.css";
|
package/src/hooks/imports.ts
DELETED
package/src/hooks/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useFiles';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { useCallback, FileItem, secureFetchIt, removeFile } from './../imports';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to toggle share settings on a file item
|
|
6
|
-
*/
|
|
7
|
-
export const useDeleteFile = (
|
|
8
|
-
setFiles: React.Dispatch<React.SetStateAction<FileItem[]>>
|
|
9
|
-
) => {
|
|
10
|
-
return useCallback(
|
|
11
|
-
async (file: FileItem) => {
|
|
12
|
-
try {
|
|
13
|
-
await removeFile(file)
|
|
14
|
-
window.location.reload();
|
|
15
|
-
} catch (err: any) {
|
|
16
|
-
console.error('Failed to toggle share settings', err);
|
|
17
|
-
// Optionally revert UI state or show an error message
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
[setFiles]
|
|
21
|
-
);
|
|
22
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { secureFetchIt, useCallback, FileItem, ApiRow, alertit } from './../imports'
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook that returns a memoized loadFiles callback
|
|
5
|
-
*/
|
|
6
|
-
export const useLoadFiles = (
|
|
7
|
-
setLoading: React.Dispatch<React.SetStateAction<boolean>>,
|
|
8
|
-
setError: React.Dispatch<React.SetStateAction<Error | null>>,
|
|
9
|
-
setFiles: React.Dispatch<React.SetStateAction<FileItem[]>>
|
|
10
|
-
) => {
|
|
11
|
-
|
|
12
|
-
return useCallback(async () => {
|
|
13
|
-
setLoading(true);
|
|
14
|
-
setError(null);
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
/** ← your request already returns the raw array */
|
|
18
|
-
let apiRows = await secureFetchIt<ApiRow[]>(
|
|
19
|
-
"list",
|
|
20
|
-
null,
|
|
21
|
-
"GET",
|
|
22
|
-
) as any;
|
|
23
|
-
console.log(`all apiRows == ${JSON.stringify(apiRows)}`)
|
|
24
|
-
if (apiRows?.result) {
|
|
25
|
-
apiRows = apiRows.result
|
|
26
|
-
}
|
|
27
|
-
apiRows = apiRows as ApiRow[]
|
|
28
|
-
/** map API → UI ------------------------------------------------ */
|
|
29
|
-
const rows: FileItem[] = apiRows.map((r: ApiRow) => ({
|
|
30
|
-
id: r.id,
|
|
31
|
-
filename: r.filename,
|
|
32
|
-
uploader_id: r.uploader_id,
|
|
33
|
-
filepath: r.filepath,
|
|
34
|
-
created_at: r.created_at,
|
|
35
|
-
download_count: r.download_count,
|
|
36
|
-
download_limit: r.download_limit,
|
|
37
|
-
shareable: Boolean(r.shareable),
|
|
38
|
-
needsPassword: !!r.share_password,
|
|
39
|
-
share_password: r.share_password,
|
|
40
|
-
password_str: r.password_str,
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
setFiles(rows);
|
|
44
|
-
|
|
45
|
-
} catch (err) {
|
|
46
|
-
setError(err instanceof Error ? err
|
|
47
|
-
: new Error("Unknown error loading files"));
|
|
48
|
-
} finally {
|
|
49
|
-
setLoading(false);
|
|
50
|
-
}
|
|
51
|
-
}, [setLoading, setError, setFiles]);
|
|
52
|
-
};
|
|
File without changes
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useCallback, FileItem, fetchSharePatch } from './../imports';
|
|
3
|
-
import { alertit } from '@putkoff/abstract-utilities'
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to toggle share settings on a file item
|
|
6
|
-
*/
|
|
7
|
-
export const usePatchShareSettings = (
|
|
8
|
-
setFiles: React.Dispatch<React.SetStateAction<FileItem[]>>
|
|
9
|
-
) => {
|
|
10
|
-
return useCallback(
|
|
11
|
-
async (file: any) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const body: any = {
|
|
15
|
-
id: file.id, // ← always send id
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// now send whichever settings changed
|
|
19
|
-
body.shareable = file.shareable;
|
|
20
|
-
body.share_password = file.share_password ?? null;
|
|
21
|
-
body.password_str = file.password_str ?? null;
|
|
22
|
-
body.download_limit = file.download_limit ?? null;
|
|
23
|
-
console.log(`file contents == ${JSON.stringify(body)}`)
|
|
24
|
-
try {
|
|
25
|
-
await fetchSharePatch(body);
|
|
26
|
-
setFiles((curr) =>
|
|
27
|
-
curr.map((f) => (f.id === body.id ? body : f))
|
|
28
|
-
);
|
|
29
|
-
} catch (err: any) {
|
|
30
|
-
console.error('Failed to toggle share settings', err);
|
|
31
|
-
// Optionally revert UI state or show an error message
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
[setFiles]
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
export default usePatchShareSettings;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useCallback, FileItem, fetchSharePatch } from './../imports';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to toggle share settings on a file item
|
|
6
|
-
*/
|
|
7
|
-
export const useToggleShare = (
|
|
8
|
-
setFiles: React.Dispatch<React.SetStateAction<FileItem[]>>
|
|
9
|
-
) => {
|
|
10
|
-
return useCallback(
|
|
11
|
-
async (file: FileItem) => {
|
|
12
|
-
const updated: FileItem = { ...file, shareable: !file.shareable };
|
|
13
|
-
if (!updated.shareable) {
|
|
14
|
-
updated.needsPassword = false;
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
await fetchSharePatch(updated);
|
|
18
|
-
setFiles((curr) =>
|
|
19
|
-
curr.map((f) => (f.id === file.id ? updated : f))
|
|
20
|
-
);
|
|
21
|
-
} catch (err: any) {
|
|
22
|
-
console.error('Failed to toggle share settings', err);
|
|
23
|
-
// Optionally revert UI state or show an error message
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
[setFiles]
|
|
27
|
-
);
|
|
28
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
import type {FileItem} from './../imports';
|
|
3
|
-
import { useLoadFiles } from './load';
|
|
4
|
-
import { useToggleShare } from './toggleShare';
|
|
5
|
-
import {useSaveShareSettings} from './useSaveShareSettings';
|
|
6
|
-
import { useDeleteFile } from './deleteFile';
|
|
7
|
-
|
|
8
|
-
export function useFiles() {
|
|
9
|
-
const [files, setFiles] = useState<FileItem[]>([]);
|
|
10
|
-
const [loading, setLoading] = useState<boolean>(false);
|
|
11
|
-
const [error, setError] = useState<Error | null>(null);
|
|
12
|
-
|
|
13
|
-
const loadCallback = useLoadFiles(setLoading, setError, setFiles);
|
|
14
|
-
const toggleShareCallback = useToggleShare(setFiles);
|
|
15
|
-
const patchShareSettingsCallback = useSaveShareSettings(setFiles);
|
|
16
|
-
const deleteFileCallback = useDeleteFile(setFiles);
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
loadCallback();
|
|
20
|
-
}, [loadCallback]);
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
files,
|
|
24
|
-
loading,
|
|
25
|
-
error,
|
|
26
|
-
load: loadCallback,
|
|
27
|
-
toggleShare: toggleShareCallback,
|
|
28
|
-
patchShareSettings: patchShareSettingsCallback,
|
|
29
|
-
deleteFile: deleteFileCallback,
|
|
30
|
-
setFiles,
|
|
31
|
-
setLoading,
|
|
32
|
-
setError,
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// hooks/useSaveShareSettings.ts
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { useCallback, FileItem, fetchSharePatch } from './../imports';
|
|
4
|
-
|
|
5
|
-
export const useSaveShareSettings = (
|
|
6
|
-
setFiles: React.Dispatch<React.SetStateAction<FileItem[]>>
|
|
7
|
-
) => {
|
|
8
|
-
return useCallback(
|
|
9
|
-
async (updated: any) => {
|
|
10
|
-
await fetchSharePatch({
|
|
11
|
-
id: updated.id,
|
|
12
|
-
shareable: updated.shareable,
|
|
13
|
-
share_password: updated.share_password,
|
|
14
|
-
password_str: updated.password_str,
|
|
15
|
-
download_limit: updated.download_limit,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// optimistic UI update – identical to toggleShare
|
|
19
|
-
setFiles(curr =>
|
|
20
|
-
curr.map(f => (f.id === updated.id ? updated : f))
|
|
21
|
-
);
|
|
22
|
-
},
|
|
23
|
-
[setFiles]
|
|
24
|
-
);
|
|
25
|
-
};
|
package/src/imports.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export { createPortal } from "react-dom";
|
|
2
|
-
export { ClipboardIcon, CloudArrowUpIcon } from "@heroicons/react/24/outline";
|
|
3
|
-
export type { QueuedFile, FileItem, FileTableProps, UploadProps, ShareModalProps, FileRowProps, ApiRow, EnhancedInputProps } from './types';
|
|
4
|
-
export {
|
|
5
|
-
currentUsername,
|
|
6
|
-
|
|
7
|
-
alertit,
|
|
8
|
-
Button,
|
|
9
|
-
Checkbox,
|
|
10
|
-
Input,
|
|
11
|
-
Spinner,
|
|
12
|
-
useEffect,
|
|
13
|
-
useRef,
|
|
14
|
-
useState,
|
|
15
|
-
requireToken,
|
|
16
|
-
useCallback, isLoggedIn, fetchIt, stripPrefixes, make_path
|
|
17
|
-
} from "@putkoff/abstract-utilities";
|
|
18
|
-
|
|
19
|
-
export { secureFetchIt, fetchSharePatch } from "@putkoff/abstract-apis";
|
|
20
|
-
|
|
File without changes
|
|
File without changes
|