@valentinkolb/filegate 0.0.5 → 0.0.6
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 +12 -33
- package/package.json +2 -2
- package/src/index.ts +6 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Filegate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Secure file proxy for building custom file management systems. Streaming uploads, chunked transfers, Unix permissions.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
Browser/App Your Backend Filegate Filesystem
|
|
@@ -16,7 +16,7 @@ Browser/App Your Backend Filegate Filesystem
|
|
|
16
16
|
|<-------------------| | |
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Filegate
|
|
19
|
+
Filegate runs behind your backend, not as a public-facing service. Your backend handles authentication and authorization, then proxies requests to Filegate. You control access logic - Filegate handles file operations.
|
|
20
20
|
|
|
21
21
|
## Features
|
|
22
22
|
|
|
@@ -27,6 +27,7 @@ Filegate is designed to work behind your backend, not as a public-facing service
|
|
|
27
27
|
- Glob-based file search
|
|
28
28
|
- Type-safe client with full TypeScript support
|
|
29
29
|
- OpenAPI documentation
|
|
30
|
+
- Minimal dependencies (Hono, Zod - no database required)
|
|
30
31
|
|
|
31
32
|
## Quick Start
|
|
32
33
|
|
|
@@ -83,34 +84,6 @@ if (result.ok) {
|
|
|
83
84
|
}
|
|
84
85
|
```
|
|
85
86
|
|
|
86
|
-
## Architecture
|
|
87
|
-
|
|
88
|
-
Filegate follows a proxy architecture where your backend mediates all file operations:
|
|
89
|
-
|
|
90
|
-
```
|
|
91
|
-
+------------------+ +------------------+ +------------------+
|
|
92
|
-
| | | | | |
|
|
93
|
-
| Your Client |<----->| Your Backend |<----->| Filegate |
|
|
94
|
-
| (Browser/App) | | (Auth, Logic) | | (File Ops) |
|
|
95
|
-
| | | | | |
|
|
96
|
-
+------------------+ +------------------+ +------------------+
|
|
97
|
-
|
|
|
98
|
-
v
|
|
99
|
-
+------------------+
|
|
100
|
-
| |
|
|
101
|
-
| Filesystem |
|
|
102
|
-
| |
|
|
103
|
-
+------------------+
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
**Your Client** handles the UI and user interactions. It communicates with your backend.
|
|
107
|
-
|
|
108
|
-
**Your Backend** handles authentication, authorization, and business logic. It decides who can access what and proxies requests to Filegate.
|
|
109
|
-
|
|
110
|
-
**Filegate** handles the actual file operations: reading, writing, streaming, chunked uploads, permissions. It only accepts requests with a valid token.
|
|
111
|
-
|
|
112
|
-
This separation means you have full control over access patterns while Filegate handles the complexity of file operations.
|
|
113
|
-
|
|
114
87
|
## Core Concepts
|
|
115
88
|
|
|
116
89
|
### Base Paths
|
|
@@ -131,7 +104,7 @@ Symlinks that point outside base paths are also blocked.
|
|
|
131
104
|
|
|
132
105
|
### File Ownership
|
|
133
106
|
|
|
134
|
-
Filegate
|
|
107
|
+
Filegate can set Unix file ownership on uploaded files:
|
|
135
108
|
|
|
136
109
|
```typescript
|
|
137
110
|
await client.upload.single({
|
|
@@ -144,7 +117,11 @@ await client.upload.single({
|
|
|
144
117
|
});
|
|
145
118
|
```
|
|
146
119
|
|
|
147
|
-
|
|
120
|
+
If ownership is not specified, files are created with the user running Filegate (typically root in Docker).
|
|
121
|
+
|
|
122
|
+
Filegate does not validate whether the specified uid/gid exists on the system, nor does it verify that the requesting user matches the specified ownership. Your backend is responsible for this validation.
|
|
123
|
+
|
|
124
|
+
This feature is intended for scenarios like NFS shares exposed through Filegate, where preserving the original permission structure is required.
|
|
148
125
|
|
|
149
126
|
### Chunked Uploads
|
|
150
127
|
|
|
@@ -154,6 +131,8 @@ For large files, use chunked uploads. They support:
|
|
|
154
131
|
- Per-chunk checksum verification
|
|
155
132
|
- Automatic assembly when complete
|
|
156
133
|
|
|
134
|
+
The [Browser Utilities](#browser-utilities) help with checksum calculation, chunking, and progress tracking. They work both in the browser and on the server.
|
|
135
|
+
|
|
157
136
|
```typescript
|
|
158
137
|
// Start or resume upload
|
|
159
138
|
const start = await client.upload.chunked.start({
|
|
@@ -325,7 +304,7 @@ if (result.ok) {
|
|
|
325
304
|
|
|
326
305
|
## Browser Utilities
|
|
327
306
|
|
|
328
|
-
|
|
307
|
+
Utilities for chunked uploads that work both in the browser and on the server. They handle file chunking, SHA-256 checksum calculation, progress tracking, and retry logic.
|
|
329
308
|
|
|
330
309
|
```typescript
|
|
331
310
|
import { chunks, formatBytes } from "@valentinkolb/filegate/utils";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valentinkolb/filegate",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Secure
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Secure file proxy for building custom file management systems. Streaming uploads, chunked transfers, Unix permissions.",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
+
import { HTTPException } from "hono/http-exception";
|
|
2
3
|
import { Scalar } from "@scalar/hono-api-reference";
|
|
3
4
|
import { generateSpecs } from "hono-openapi";
|
|
4
5
|
import { createMarkdownFromOpenApi } from "@scalar/openapi-to-markdown";
|
|
@@ -69,6 +70,11 @@ app.notFound((c) => c.json({ error: "not found" }, 404));
|
|
|
69
70
|
|
|
70
71
|
// Error handler
|
|
71
72
|
app.onError((err, c) => {
|
|
73
|
+
// HTTPException (from bearerAuth, etc.) - return the proper response
|
|
74
|
+
if (err instanceof HTTPException) {
|
|
75
|
+
return err.getResponse();
|
|
76
|
+
}
|
|
77
|
+
|
|
72
78
|
console.error("[Filegate] Error:", err);
|
|
73
79
|
return c.json({ error: "internal error" }, 500);
|
|
74
80
|
});
|