@valentinkolb/filegate 2.1.0 → 2.2.0
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/README.md +4 -1
- package/package.json +1 -1
- package/src/client.ts +3 -0
- package/src/handlers/files.ts +4 -4
- package/src/schemas.ts +5 -0
package/README.md
CHANGED
|
@@ -311,6 +311,9 @@ const client = new Filegate({
|
|
|
311
311
|
// Get file or directory info
|
|
312
312
|
await client.info({ path: "/data/file.txt", showHidden: false });
|
|
313
313
|
|
|
314
|
+
// Get directory info with recursive sizes (slower)
|
|
315
|
+
await client.info({ path: "/data/uploads", computeSizes: true });
|
|
316
|
+
|
|
314
317
|
// Download file (returns streaming Response)
|
|
315
318
|
await client.download({ path: "/data/file.txt" });
|
|
316
319
|
|
|
@@ -450,7 +453,7 @@ All `/files/*` endpoints require `Authorization: Bearer <token>`.
|
|
|
450
453
|
| GET | `/docs` | OpenAPI documentation (Scalar UI) |
|
|
451
454
|
| GET | `/openapi.json` | OpenAPI specification |
|
|
452
455
|
| GET | `/llms.txt` | LLM-friendly markdown documentation |
|
|
453
|
-
| GET | `/files/info` | Get file or directory info |
|
|
456
|
+
| GET | `/files/info` | Get file or directory info. Use `?computeSizes=true` for recursive dir sizes |
|
|
454
457
|
| GET | `/files/content` | Download file or directory (TAR). Use `?inline=true` to view in browser |
|
|
455
458
|
| PUT | `/files/content` | Upload file |
|
|
456
459
|
| POST | `/files/mkdir` | Create directory |
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface ClientOptions {
|
|
|
33
33
|
export interface InfoOptions {
|
|
34
34
|
path: string;
|
|
35
35
|
showHidden?: boolean;
|
|
36
|
+
/** If true, compute recursive sizes for directories (slower, default: false) */
|
|
37
|
+
computeSizes?: boolean;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
// --- Download ---
|
|
@@ -243,6 +245,7 @@ export class Filegate {
|
|
|
243
245
|
path: opts.path,
|
|
244
246
|
showHidden: String(opts.showHidden ?? false),
|
|
245
247
|
});
|
|
248
|
+
if (opts.computeSizes) params.set("computeSizes", "true");
|
|
246
249
|
const res = await this._fetch(`${this.url}/files/info?${params}`, { headers: this.hdrs() });
|
|
247
250
|
return this.handleResponse(res);
|
|
248
251
|
}
|
package/src/handlers/files.ts
CHANGED
|
@@ -108,7 +108,7 @@ app.get(
|
|
|
108
108
|
}),
|
|
109
109
|
v("query", InfoQuerySchema),
|
|
110
110
|
async (c) => {
|
|
111
|
-
const { path, showHidden } = c.req.valid("query");
|
|
111
|
+
const { path, showHidden, computeSizes } = c.req.valid("query");
|
|
112
112
|
|
|
113
113
|
const result = await validatePath(path, { allowBasePath: true });
|
|
114
114
|
if (!result.ok) return c.json({ error: result.error }, result.status);
|
|
@@ -126,17 +126,17 @@ app.get(
|
|
|
126
126
|
|
|
127
127
|
const entries = await readdir(result.realPath, { withFileTypes: true });
|
|
128
128
|
|
|
129
|
-
// Parallel file info retrieval
|
|
129
|
+
// Parallel file info retrieval (computeSizes only when requested)
|
|
130
130
|
const items = (
|
|
131
131
|
await Promise.all(
|
|
132
132
|
entries
|
|
133
133
|
.filter((e) => showHidden || !e.name.startsWith("."))
|
|
134
|
-
.map((e) => getFileInfo(join(result.realPath, e.name), result.realPath,
|
|
134
|
+
.map((e) => getFileInfo(join(result.realPath, e.name), result.realPath, computeSizes).catch(() => null)),
|
|
135
135
|
)
|
|
136
136
|
).filter((item): item is FileInfo => item !== null);
|
|
137
137
|
|
|
138
138
|
const info = await getFileInfo(result.realPath);
|
|
139
|
-
const totalSize = items.reduce((sum, item) => sum + item.size, 0);
|
|
139
|
+
const totalSize = computeSizes ? items.reduce((sum, item) => sum + item.size, 0) : 0;
|
|
140
140
|
return c.json({ ...info, size: totalSize, items, total: items.length });
|
|
141
141
|
},
|
|
142
142
|
);
|
package/src/schemas.ts
CHANGED
|
@@ -58,6 +58,11 @@ export const InfoQuerySchema = z
|
|
|
58
58
|
.optional()
|
|
59
59
|
.transform((v) => v === "true")
|
|
60
60
|
.describe("If 'true', include hidden files (starting with dot) in directory listings"),
|
|
61
|
+
computeSizes: z
|
|
62
|
+
.string()
|
|
63
|
+
.optional()
|
|
64
|
+
.transform((v) => v === "true")
|
|
65
|
+
.describe("If 'true', compute recursive sizes for directories (slower, default: false)"),
|
|
61
66
|
})
|
|
62
67
|
.describe("Query parameters for file/directory info");
|
|
63
68
|
|