@putkoff/abstract-utilities 0.1.105 → 0.1.107
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/dist/cjs/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
- package/dist/cjs/functions/index.d.ts +1 -1
- package/dist/cjs/functions/ui_utils/imports.d.ts +0 -2
- package/dist/cjs/index.d.ts +0 -2
- package/dist/cjs/index.js +103 -556
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
- package/dist/esm/functions/index.d.ts +1 -1
- package/dist/esm/functions/ui_utils/imports.d.ts +0 -2
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +101 -535
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
- package/dist/functions/index.d.ts +1 -1
- package/dist/functions/ui_utils/imports.d.ts +0 -2
- package/dist/hooks/useFiles/imports.d.ts +9 -5
- package/dist/hooks/useFiles/src/index.d.ts +1 -0
- package/dist/hooks/useFiles/src/patchShareSettings.d.ts +1 -4
- package/dist/hooks/useFiles/src/useFiles.d.ts +2 -2
- package/dist/hooks/useFiles/src/useSaveShareSettings.d.ts +2 -0
- package/dist/index.d.ts +24 -117
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
/** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
|
|
10
10
|
export declare function get_app_config_url(endpoint: any): string;
|
|
11
11
|
export declare function fetchIt(endpoint: string, body?: unknown, method?: string | null, headers?: Record<string, string> | null, blob?: boolean | null, no_api?: boolean, requireAuth?: boolean): Promise<unknown>;
|
|
12
|
-
export declare function secureFetchIt<T>(endpoint: string, body?: unknown, method?: string, headers?: Record<string, string> | null, blob?: false, noApi?: boolean,
|
|
12
|
+
export declare function secureFetchIt<T>(endpoint: string, body?: unknown, method?: string, headers?: Record<string, string> | null, blob?: false, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<T>;
|
|
13
13
|
export declare function secureFetchIt(endpoint: string, body?: unknown, method?: string, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<Blob>;
|
|
14
14
|
export declare function requestPatch(url: string, body?: unknown): Promise<Response>;
|
|
15
15
|
export declare function fetchSharePatch(file: unknown): Promise<void>;
|
|
@@ -2,5 +2,3 @@ import React from 'react';
|
|
|
2
2
|
export declare const useState: typeof React.useState, useEffect: typeof React.useEffect, useCallback: typeof React.useCallback;
|
|
3
3
|
export { fetchIt } from './../fetch_utils';
|
|
4
4
|
export { currentUsername, isTokenExpired, getToken } from './../auth_utils';
|
|
5
|
-
export { uploadFile, downloadFile } from './../../file_utils';
|
|
6
|
-
export { useFiles } from './../../hooks/useFiles';
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,87 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export { useCallback, useRef, useState } from 'react';
|
|
1
|
+
export { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
3
|
|
|
5
|
-
/******************************************************************************
|
|
6
|
-
Copyright (c) Microsoft Corporation.
|
|
7
|
-
|
|
8
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
-
purpose with or without fee is hereby granted.
|
|
10
|
-
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function __rest(s, e) {
|
|
23
|
-
var t = {};
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
25
|
-
t[p] = s[p];
|
|
26
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
27
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
28
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
29
|
-
t[p[i]] = s[p[i]];
|
|
30
|
-
}
|
|
31
|
-
return t;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
35
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
45
|
-
var e = new Error(message);
|
|
46
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/** Helper function to trigger file download */
|
|
50
|
-
function triggerDownload(blob, filename) {
|
|
51
|
-
const url = URL.createObjectURL(blob);
|
|
52
|
-
const a = Object.assign(document.createElement("a"), {
|
|
53
|
-
href: url,
|
|
54
|
-
download: filename,
|
|
55
|
-
});
|
|
56
|
-
document.body.appendChild(a);
|
|
57
|
-
a.click();
|
|
58
|
-
a.remove();
|
|
59
|
-
URL.revokeObjectURL(url);
|
|
60
|
-
console.log(`✅ Successfully downloaded: ${filename}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Non-React “direct download” used by some old links (kept for parity) */
|
|
64
|
-
function directDownload(relPath, filename) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const token = localStorage.getItem("token");
|
|
67
|
-
if (!token)
|
|
68
|
-
throw new Error("No auth token found");
|
|
69
|
-
const res = yield fetch("/secure-files/download", {
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: {
|
|
72
|
-
Authorization: `Bearer ${token}`,
|
|
73
|
-
"Content-Type": "application/json",
|
|
74
|
-
Accept: "application/octet-stream",
|
|
75
|
-
},
|
|
76
|
-
body: JSON.stringify({ rel_path: relPath }),
|
|
77
|
-
});
|
|
78
|
-
if (!res.ok)
|
|
79
|
-
throw new Error(`Download failed: ${res.status}`);
|
|
80
|
-
const blob = yield res.blob();
|
|
81
|
-
triggerDownload(blob, filename);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
4
|
/**
|
|
86
5
|
***Changes**:
|
|
87
6
|
*- Updated import path for `InputProps` to `../../types/interfaces`.
|
|
@@ -178,6 +97,105 @@ function decodeJwt(token) {
|
|
|
178
97
|
return JSON.parse(jsonText);
|
|
179
98
|
}
|
|
180
99
|
|
|
100
|
+
const PROTOCOL = 'https://';
|
|
101
|
+
const DOMAIN_NAME = 'abstractendeavors';
|
|
102
|
+
const BASE_URL = `${PROTOCOL}${DOMAIN_NAME}.com`;
|
|
103
|
+
const SUB_DIR = 'secure-files';
|
|
104
|
+
const PROD_PREFIX = `/${SUB_DIR}/`;
|
|
105
|
+
const API_PREFIX = `/${SUB_DIR}/api`;
|
|
106
|
+
const DEV_PREFIX = `/${SUB_DIR}-dev/`;
|
|
107
|
+
|
|
108
|
+
function get_window() {
|
|
109
|
+
try {
|
|
110
|
+
if (typeof window !== 'undefined') {
|
|
111
|
+
return window;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
alert(err);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function get_window_location() {
|
|
120
|
+
try {
|
|
121
|
+
const Window = get_window();
|
|
122
|
+
if (!Window) {
|
|
123
|
+
return BASE_URL;
|
|
124
|
+
}
|
|
125
|
+
return Window.location;
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
alert(err);
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
function get_window_pathname() {
|
|
133
|
+
try {
|
|
134
|
+
const Window = get_window();
|
|
135
|
+
if (!Window) {
|
|
136
|
+
return DEV_PREFIX;
|
|
137
|
+
}
|
|
138
|
+
return Window.location.pathname;
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
alert(err);
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
function get_window_parts() {
|
|
146
|
+
try {
|
|
147
|
+
return get_window_location();
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
alert(err);
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/******************************************************************************
|
|
156
|
+
Copyright (c) Microsoft Corporation.
|
|
157
|
+
|
|
158
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
159
|
+
purpose with or without fee is hereby granted.
|
|
160
|
+
|
|
161
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
162
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
163
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
164
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
165
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
166
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
167
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
168
|
+
***************************************************************************** */
|
|
169
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
function __rest(s, e) {
|
|
173
|
+
var t = {};
|
|
174
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
175
|
+
t[p] = s[p];
|
|
176
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
177
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
178
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
179
|
+
t[p[i]] = s[p[i]];
|
|
180
|
+
}
|
|
181
|
+
return t;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
185
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
186
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
187
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
188
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
189
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
190
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
195
|
+
var e = new Error(message);
|
|
196
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
197
|
+
};
|
|
198
|
+
|
|
181
199
|
function assertPath(path) {
|
|
182
200
|
if (typeof path !== 'string') {
|
|
183
201
|
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
|
|
@@ -1211,336 +1229,6 @@ function fetchSharePatch(file) {
|
|
|
1211
1229
|
});
|
|
1212
1230
|
}
|
|
1213
1231
|
|
|
1214
|
-
function downloadFile(item) {
|
|
1215
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1216
|
-
const token = requireToken();
|
|
1217
|
-
const { filepath, filename } = item;
|
|
1218
|
-
const body = { rel_path: filepath };
|
|
1219
|
-
const headers = {
|
|
1220
|
-
Authorization: `Bearer ${token}`,
|
|
1221
|
-
Accept: "application/octet-stream",
|
|
1222
|
-
"Content-Type": "application/json"
|
|
1223
|
-
};
|
|
1224
|
-
const blob = yield secureFetchIt("download", body, "POST", headers, true, true);
|
|
1225
|
-
if (!blob || blob.size === 0) {
|
|
1226
|
-
throw new Error(`Received empty file data for “${filename}”`);
|
|
1227
|
-
}
|
|
1228
|
-
triggerDownload(blob, filename);
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
function downloadSelect(relPath, filename) {
|
|
1233
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1234
|
-
const token = requireToken();
|
|
1235
|
-
const body = { rel_path: relPath };
|
|
1236
|
-
const headers = {
|
|
1237
|
-
Authorization: `Bearer ${token}`,
|
|
1238
|
-
Accept: "application/octet-stream",
|
|
1239
|
-
"Content-Type": "application/json"
|
|
1240
|
-
};
|
|
1241
|
-
const blob = yield secureFetchIt("download", body, "POST", headers, true, true);
|
|
1242
|
-
if (!blob || blob.size === 0) {
|
|
1243
|
-
throw new Error(`Received empty file data for “${filename}”`);
|
|
1244
|
-
}
|
|
1245
|
-
triggerDownload(blob, filename);
|
|
1246
|
-
});
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
/** Given a checkbox inside a table-row → download that row’s file. */
|
|
1250
|
-
function downloadRow(cb) {
|
|
1251
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1252
|
-
var _a, _b;
|
|
1253
|
-
const row = cb.closest("tr");
|
|
1254
|
-
const relPath = cb.value;
|
|
1255
|
-
const filename = ((_b = (_a = row === null || row === void 0 ? void 0 : row.children[1]) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || "downloaded_file";
|
|
1256
|
-
if (relPath)
|
|
1257
|
-
yield downloadSelect(relPath, filename);
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
/** Bulk download: pass a NodeList or array of checkboxes. */
|
|
1261
|
-
function downloadSelected(checkboxes) {
|
|
1262
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1263
|
-
const list = Array.from(checkboxes);
|
|
1264
|
-
if (!list.length) {
|
|
1265
|
-
alert("No files selected.");
|
|
1266
|
-
return;
|
|
1267
|
-
}
|
|
1268
|
-
for (const cb of list) {
|
|
1269
|
-
yield downloadRow(cb);
|
|
1270
|
-
}
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
/**
|
|
1275
|
-
* Classic “select all rows” logic (still handy in non-React views
|
|
1276
|
-
* such as the admin dashboard).
|
|
1277
|
-
*/
|
|
1278
|
-
function syncHeaderCheckbox() {
|
|
1279
|
-
const all = document.querySelectorAll(".file-checkbox");
|
|
1280
|
-
const checked = document.querySelectorAll(".file-checkbox:checked");
|
|
1281
|
-
const header = document.getElementById("select-all-checkbox");
|
|
1282
|
-
header.indeterminate =
|
|
1283
|
-
checked.length > 0 && checked.length < all.length;
|
|
1284
|
-
header.checked = checked.length === all.length;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
/** Wire up header + row checkboxes once the table is in the DOM. */
|
|
1288
|
-
function initSelectAll() {
|
|
1289
|
-
const header = document.getElementById("select-all-checkbox");
|
|
1290
|
-
const btn = document.getElementById("select-all");
|
|
1291
|
-
// 1) header → toggle all
|
|
1292
|
-
header.addEventListener("change", (e) => {
|
|
1293
|
-
const on = e.target.checked;
|
|
1294
|
-
document
|
|
1295
|
-
.querySelectorAll(".file-checkbox")
|
|
1296
|
-
.forEach((cb) => (cb.checked = on));
|
|
1297
|
-
});
|
|
1298
|
-
// 2) button → toggle all
|
|
1299
|
-
btn.addEventListener("click", () => {
|
|
1300
|
-
const cbs = Array.from(document.querySelectorAll(".file-checkbox"));
|
|
1301
|
-
if (!cbs.length) {
|
|
1302
|
-
alert("No files to select.");
|
|
1303
|
-
return;
|
|
1304
|
-
}
|
|
1305
|
-
const anyUnchecked = cbs.some((cb) => !cb.checked);
|
|
1306
|
-
cbs.forEach((cb) => (cb.checked = anyUnchecked));
|
|
1307
|
-
syncHeaderCheckbox();
|
|
1308
|
-
});
|
|
1309
|
-
// 3) row boxes → keep header state
|
|
1310
|
-
document
|
|
1311
|
-
.querySelectorAll(".file-checkbox")
|
|
1312
|
-
.forEach((cb) => cb.addEventListener("change", syncHeaderCheckbox));
|
|
1313
|
-
syncHeaderCheckbox();
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
/** Utility for other screens: toggle a list of checkboxes on/off. */
|
|
1317
|
-
function toggleCheckboxes(cbs) {
|
|
1318
|
-
if (!cbs.length) {
|
|
1319
|
-
alert("No files to select.");
|
|
1320
|
-
return;
|
|
1321
|
-
}
|
|
1322
|
-
const anyUnchecked = cbs.some((cb) => !cb.checked);
|
|
1323
|
-
cbs.forEach((cb) => (cb.checked = anyUnchecked));
|
|
1324
|
-
syncHeaderCheckbox();
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
/** Generic PATCH helper kept for other admin forms */
|
|
1328
|
-
function patchFileSetting(fileId, field, value) {
|
|
1329
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1330
|
-
const res = yield fetch(`/files/${fileId}/settings/${field}`, {
|
|
1331
|
-
method: "PATCH",
|
|
1332
|
-
headers: { "Content-Type": "application/json" },
|
|
1333
|
-
body: JSON.stringify({ value }),
|
|
1334
|
-
});
|
|
1335
|
-
if (!res.ok) {
|
|
1336
|
-
const err = yield res.json();
|
|
1337
|
-
throw new Error(err.error || res.statusText);
|
|
1338
|
-
}
|
|
1339
|
-
return (yield res.json());
|
|
1340
|
-
});
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
/** Classic file-upload for the fallback HTML page. */
|
|
1344
|
-
function uploadFile(file, subdir) {
|
|
1345
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1346
|
-
var _a, _b;
|
|
1347
|
-
const fileInput = file || document.getElementById("file-browser");
|
|
1348
|
-
const subdirInput = subdir || document.getElementById("subdir");
|
|
1349
|
-
const banner = document.getElementById("banner");
|
|
1350
|
-
if (!((_a = fileInput.files) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
1351
|
-
alert("No file selected.");
|
|
1352
|
-
return;
|
|
1353
|
-
}
|
|
1354
|
-
const formData = new FormData();
|
|
1355
|
-
formData.append("file", fileInput.files[0]);
|
|
1356
|
-
formData.append("subdir", subdirInput.value.trim());
|
|
1357
|
-
try {
|
|
1358
|
-
const json = yield secureFetchIt("upload", formData, "POST", null, false, true);
|
|
1359
|
-
banner.textContent = `Uploaded: ${json.filepath}`;
|
|
1360
|
-
fileInput.value = "";
|
|
1361
|
-
subdirInput.value = "";
|
|
1362
|
-
window.location.reload(); // no-op in React view
|
|
1363
|
-
}
|
|
1364
|
-
catch (err) {
|
|
1365
|
-
console.error("Upload failed", err);
|
|
1366
|
-
alert((_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : "Upload failed.");
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
function uploadFiles(file_1) {
|
|
1372
|
-
return __awaiter(this, arguments, void 0, function* (file, subdir = '') {
|
|
1373
|
-
var _a;
|
|
1374
|
-
if (!(file instanceof File)) {
|
|
1375
|
-
throw new Error('Invalid file: Must be a File object.');
|
|
1376
|
-
}
|
|
1377
|
-
if (typeof subdir !== 'string') {
|
|
1378
|
-
throw new Error('Invalid subdir: Must be a string.');
|
|
1379
|
-
}
|
|
1380
|
-
const formData = new FormData();
|
|
1381
|
-
formData.append('file', file);
|
|
1382
|
-
formData.append('subdir', subdir.trim());
|
|
1383
|
-
try {
|
|
1384
|
-
const json = yield secureFetchIt('upload', formData, 'POST', null, false, false);
|
|
1385
|
-
if (!json || typeof json !== 'object') {
|
|
1386
|
-
throw new Error('Invalid response from server.');
|
|
1387
|
-
}
|
|
1388
|
-
if (!('filepath' in json) || typeof json.filepath !== 'string' || !json.filepath) {
|
|
1389
|
-
throw new Error('Server response missing or invalid filepath.');
|
|
1390
|
-
}
|
|
1391
|
-
return { filepath: json.filepath };
|
|
1392
|
-
}
|
|
1393
|
-
catch (err) {
|
|
1394
|
-
throw new Error(`Upload failed: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown error'}`);
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
function removeFile(item) {
|
|
1400
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1401
|
-
const token = requireToken();
|
|
1402
|
-
const body = item;
|
|
1403
|
-
const headers = {
|
|
1404
|
-
Authorization: `Bearer ${token}`,
|
|
1405
|
-
Accept: "application/octet-stream",
|
|
1406
|
-
"Content-Type": "application/json"
|
|
1407
|
-
};
|
|
1408
|
-
const resp = yield secureFetchIt("remove", body, "POST", headers, false, true);
|
|
1409
|
-
if (!resp || resp === false || (resp === null || resp === void 0 ? void 0 : resp.result) === false) {
|
|
1410
|
-
throw new Error(`could not delete data: “${item.filename}”`);
|
|
1411
|
-
}
|
|
1412
|
-
});
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
/** Bulk download: pass a NodeList or array of checkboxes. */
|
|
1416
|
-
function removeSelected(checkboxes) {
|
|
1417
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1418
|
-
const list = Array.from(checkboxes);
|
|
1419
|
-
if (!list.length) {
|
|
1420
|
-
alert("No files selected.");
|
|
1421
|
-
return;
|
|
1422
|
-
}
|
|
1423
|
-
for (const cb of list) {
|
|
1424
|
-
yield removeFile(cb);
|
|
1425
|
-
}
|
|
1426
|
-
});
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
/** Given a checkbox inside a table-row → download that row’s file. */
|
|
1430
|
-
function removeRow(cb) {
|
|
1431
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1432
|
-
const row = cb.closest("tr");
|
|
1433
|
-
alertit(row);
|
|
1434
|
-
if (row && (row === null || row === void 0 ? void 0 : row.id))
|
|
1435
|
-
yield removeFile(row);
|
|
1436
|
-
});
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
/** GET /secure-list */
|
|
1440
|
-
function listFiles() {
|
|
1441
|
-
return __awaiter(this, arguments, void 0, function* (setFiles = null) {
|
|
1442
|
-
/** ← your request already returns the raw array */
|
|
1443
|
-
const apiRows = yield secureFetchIt("list", null, "GET", null, false, true);
|
|
1444
|
-
/** map API → UI ------------------------------------------------ */
|
|
1445
|
-
const rows = apiRows.map((r) => ({
|
|
1446
|
-
id: r.id,
|
|
1447
|
-
filename: r.filename,
|
|
1448
|
-
uploader_id: r.uploader_id,
|
|
1449
|
-
filepath: r.filepath,
|
|
1450
|
-
created_at: r.created_at,
|
|
1451
|
-
download_count: r.download_count,
|
|
1452
|
-
download_limit: r.download_limit,
|
|
1453
|
-
shareable: Boolean(r.shareable),
|
|
1454
|
-
needsPassword: !!r.share_password,
|
|
1455
|
-
share_password: r.share_password,
|
|
1456
|
-
}));
|
|
1457
|
-
setFiles(rows);
|
|
1458
|
-
});
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
function getToggleShare(file) {
|
|
1462
|
-
if (file == true || (file === null || file === void 0 ? void 0 : file.shareable) == true) {
|
|
1463
|
-
return false;
|
|
1464
|
-
}
|
|
1465
|
-
return false;
|
|
1466
|
-
}
|
|
1467
|
-
function updateFileShare(file) {
|
|
1468
|
-
let updated = file;
|
|
1469
|
-
const boolIt = getToggleShare(updated);
|
|
1470
|
-
updated = Object.assign(Object.assign({}, file), { shareable: boolIt });
|
|
1471
|
-
return updated;
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Custom hook to toggle share settings on a file item
|
|
1475
|
-
*/
|
|
1476
|
-
function toggleShare(file) {
|
|
1477
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1478
|
-
const updated = updateFileShare(file);
|
|
1479
|
-
try {
|
|
1480
|
-
const resp = yield fetchSharePatch(updated);
|
|
1481
|
-
}
|
|
1482
|
-
catch (err) {
|
|
1483
|
-
console.error('Failed to toggle share settings', err);
|
|
1484
|
-
// Optionally revert UI state or show an error message
|
|
1485
|
-
}
|
|
1486
|
-
});
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
const PROTOCOL = 'https://';
|
|
1490
|
-
const DOMAIN_NAME = 'abstractendeavors';
|
|
1491
|
-
const BASE_URL = `${PROTOCOL}${DOMAIN_NAME}.com`;
|
|
1492
|
-
const SUB_DIR = 'secure-files';
|
|
1493
|
-
const PROD_PREFIX = `/${SUB_DIR}/`;
|
|
1494
|
-
const API_PREFIX = `/${SUB_DIR}/api`;
|
|
1495
|
-
const DEV_PREFIX = `/${SUB_DIR}-dev/`;
|
|
1496
|
-
|
|
1497
|
-
function get_window() {
|
|
1498
|
-
try {
|
|
1499
|
-
if (typeof window !== 'undefined') {
|
|
1500
|
-
return window;
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
catch (err) {
|
|
1504
|
-
alert(err);
|
|
1505
|
-
}
|
|
1506
|
-
return null;
|
|
1507
|
-
}
|
|
1508
|
-
function get_window_location() {
|
|
1509
|
-
try {
|
|
1510
|
-
const Window = get_window();
|
|
1511
|
-
if (!Window) {
|
|
1512
|
-
return BASE_URL;
|
|
1513
|
-
}
|
|
1514
|
-
return Window.location;
|
|
1515
|
-
}
|
|
1516
|
-
catch (err) {
|
|
1517
|
-
alert(err);
|
|
1518
|
-
}
|
|
1519
|
-
return null;
|
|
1520
|
-
}
|
|
1521
|
-
function get_window_pathname() {
|
|
1522
|
-
try {
|
|
1523
|
-
const Window = get_window();
|
|
1524
|
-
if (!Window) {
|
|
1525
|
-
return DEV_PREFIX;
|
|
1526
|
-
}
|
|
1527
|
-
return Window.location.pathname;
|
|
1528
|
-
}
|
|
1529
|
-
catch (err) {
|
|
1530
|
-
alert(err);
|
|
1531
|
-
}
|
|
1532
|
-
return null;
|
|
1533
|
-
}
|
|
1534
|
-
function get_window_parts() {
|
|
1535
|
-
try {
|
|
1536
|
-
return get_window_location();
|
|
1537
|
-
}
|
|
1538
|
-
catch (err) {
|
|
1539
|
-
alert(err);
|
|
1540
|
-
}
|
|
1541
|
-
return null;
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
1232
|
function Button(_a) {
|
|
1545
1233
|
var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
|
|
1546
1234
|
const base = 'rounded px-3 py-1 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors duration-150';
|
|
@@ -1576,127 +1264,5 @@ function Spinner() {
|
|
|
1576
1264
|
return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1577
1265
|
}
|
|
1578
1266
|
|
|
1579
|
-
|
|
1580
|
-
* Custom hook that returns a memoized loadFiles callback
|
|
1581
|
-
*/
|
|
1582
|
-
const useLoadFiles = (setLoading, setError, setFiles) => {
|
|
1583
|
-
return useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1584
|
-
setLoading(true);
|
|
1585
|
-
setError(null);
|
|
1586
|
-
try {
|
|
1587
|
-
/** ← your request already returns the raw array */
|
|
1588
|
-
const apiRows = yield secureFetchIt("list", null, "GET", null, false, true);
|
|
1589
|
-
/** map API → UI ------------------------------------------------ */
|
|
1590
|
-
const rows = apiRows.map((r) => ({
|
|
1591
|
-
id: r.id,
|
|
1592
|
-
filename: r.filename,
|
|
1593
|
-
uploader_id: r.uploader_id,
|
|
1594
|
-
filepath: r.filepath,
|
|
1595
|
-
created_at: r.created_at,
|
|
1596
|
-
download_count: r.download_count,
|
|
1597
|
-
download_limit: r.download_limit,
|
|
1598
|
-
shareable: Boolean(r.shareable),
|
|
1599
|
-
needsPassword: !!r.share_password,
|
|
1600
|
-
share_password: r.share_password,
|
|
1601
|
-
}));
|
|
1602
|
-
setFiles(rows);
|
|
1603
|
-
}
|
|
1604
|
-
catch (err) {
|
|
1605
|
-
setError(err instanceof Error ? err
|
|
1606
|
-
: new Error("Unknown error loading files"));
|
|
1607
|
-
}
|
|
1608
|
-
finally {
|
|
1609
|
-
setLoading(false);
|
|
1610
|
-
}
|
|
1611
|
-
}), [setLoading, setError, setFiles]);
|
|
1612
|
-
};
|
|
1613
|
-
|
|
1614
|
-
/**
|
|
1615
|
-
* Custom hook to toggle share settings on a file item
|
|
1616
|
-
*/
|
|
1617
|
-
const useToggleShare = (setFiles) => {
|
|
1618
|
-
return useCallback((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1619
|
-
const updated = Object.assign(Object.assign({}, file), { shareable: !file.shareable });
|
|
1620
|
-
if (!updated.shareable) {
|
|
1621
|
-
updated.needsPassword = false;
|
|
1622
|
-
updated.share_password = null;
|
|
1623
|
-
updated.download_limit = null;
|
|
1624
|
-
}
|
|
1625
|
-
try {
|
|
1626
|
-
yield fetchSharePatch(updated);
|
|
1627
|
-
setFiles((curr) => curr.map((f) => (f.id === file.id ? updated : f)));
|
|
1628
|
-
}
|
|
1629
|
-
catch (err) {
|
|
1630
|
-
console.error('Failed to toggle share settings', err);
|
|
1631
|
-
// Optionally revert UI state or show an error message
|
|
1632
|
-
}
|
|
1633
|
-
}), [setFiles]);
|
|
1634
|
-
};
|
|
1635
|
-
|
|
1636
|
-
/**
|
|
1637
|
-
* Custom hook for optimistic share-setting patch updates
|
|
1638
|
-
*/
|
|
1639
|
-
/**
|
|
1640
|
-
* Custom hook to toggle share settings on a file item
|
|
1641
|
-
*/
|
|
1642
|
-
const usePatchShareSettings = (setFiles) => {
|
|
1643
|
-
return useCallback((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1644
|
-
if (!file.shareable) {
|
|
1645
|
-
file.needsPassword = false;
|
|
1646
|
-
file.share_password = null;
|
|
1647
|
-
file.download_limit = null;
|
|
1648
|
-
}
|
|
1649
|
-
try {
|
|
1650
|
-
yield fetchSharePatch(file);
|
|
1651
|
-
setFiles((curr) => curr.map((f) => (f.id === file.id ? file : f)));
|
|
1652
|
-
}
|
|
1653
|
-
catch (err) {
|
|
1654
|
-
console.error('Failed to toggle share settings', err);
|
|
1655
|
-
// Optionally revert UI state or show an error message
|
|
1656
|
-
}
|
|
1657
|
-
}), [setFiles]);
|
|
1658
|
-
};
|
|
1659
|
-
|
|
1660
|
-
/**
|
|
1661
|
-
* Custom hook to toggle share settings on a file item
|
|
1662
|
-
*/
|
|
1663
|
-
const useDeleteFile = (setFiles) => {
|
|
1664
|
-
return useCallback((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1665
|
-
try {
|
|
1666
|
-
yield removeFile(file);
|
|
1667
|
-
window.location.reload();
|
|
1668
|
-
}
|
|
1669
|
-
catch (err) {
|
|
1670
|
-
console.error('Failed to toggle share settings', err);
|
|
1671
|
-
// Optionally revert UI state or show an error message
|
|
1672
|
-
}
|
|
1673
|
-
}), [setFiles]);
|
|
1674
|
-
};
|
|
1675
|
-
|
|
1676
|
-
function useFiles() {
|
|
1677
|
-
const [files, setFiles] = useState([]);
|
|
1678
|
-
const [loading, setLoading] = useState(false);
|
|
1679
|
-
const [error, setError] = useState(null);
|
|
1680
|
-
const loadCallback = useLoadFiles(setLoading, setError, setFiles);
|
|
1681
|
-
const toggleShareCallback = useToggleShare(setFiles);
|
|
1682
|
-
const patchShareSettingsCallback = usePatchShareSettings(setFiles);
|
|
1683
|
-
const deleteFileCallback = useDeleteFile(setFiles);
|
|
1684
|
-
useEffect(() => {
|
|
1685
|
-
loadCallback();
|
|
1686
|
-
}, [loadCallback]);
|
|
1687
|
-
return {
|
|
1688
|
-
files,
|
|
1689
|
-
loading,
|
|
1690
|
-
error,
|
|
1691
|
-
load: loadCallback,
|
|
1692
|
-
toggleShare: toggleShareCallback,
|
|
1693
|
-
patchShareSettings: patchShareSettingsCallback,
|
|
1694
|
-
deleteFile: deleteFileCallback,
|
|
1695
|
-
setFiles,
|
|
1696
|
-
setLoading,
|
|
1697
|
-
setError,
|
|
1698
|
-
};
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, currentUsername, currentUsernames, decodeJwt, directDownload, downloadFile, downloadRow, downloadSelect, downloadSelected, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getComponentsUtilsDirectory, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFunctionsDir, getFunctionsUtilsDirectory, getHooksUtilsDirectory, getLibUtilsDirectory, getPublicDir, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToggleShare, getToken, get_app_config_url, get_basename, get_dirname, get_extname, get_filename, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, initSelectAll, isLoggedIn, isTokenExpired, listFiles, make_path, make_sanitized_path, normalizeUrl, patchFileSetting, removeFile, removeRow, removeSelected, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, syncHeaderCheckbox, toggleCheckboxes, toggleShare, triggerDownload, truncateString, updateFileShare, uploadFile, uploadFiles, useDeleteFile, useFiles, useLoadFiles, usePatchShareSettings, useToggleShare };
|
|
1267
|
+
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getComponentsUtilsDirectory, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFunctionsDir, getFunctionsUtilsDirectory, getHooksUtilsDirectory, getLibUtilsDirectory, getPublicDir, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, get_app_config_url, get_basename, get_dirname, get_extname, get_filename, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isTokenExpired, make_path, make_sanitized_path, normalizeUrl, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
|
|
1702
1268
|
//# sourceMappingURL=index.js.map
|