@valentinkolb/filegate 2.5.2 → 2.5.3
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 +166 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# @valentinkolb/filegate
|
|
2
|
+
|
|
3
|
+
TypeScript client for Filegate. Use it from trusted server runtimes to call the
|
|
4
|
+
Filegate REST API, and from browsers only with scoped direct upload/download
|
|
5
|
+
URLs minted by your application server.
|
|
6
|
+
|
|
7
|
+
Filegate keeps files as normal Linux files on configured mounts. The client
|
|
8
|
+
covers path and ID lookup, direct URLs, upload sessions, transfers, search,
|
|
9
|
+
activity, and stats.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i @valentinkolb/filegate
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Server client
|
|
18
|
+
|
|
19
|
+
Use the default instance when `FILEGATE_URL` and `FILEGATE_TOKEN` are available
|
|
20
|
+
in the server runtime:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { filegate } from "@valentinkolb/filegate/client";
|
|
24
|
+
|
|
25
|
+
process.env.FILEGATE_URL = "http://127.0.0.1:8080";
|
|
26
|
+
process.env.FILEGATE_TOKEN = "dev-token";
|
|
27
|
+
|
|
28
|
+
const roots = await filegate.paths.get();
|
|
29
|
+
const caps = await filegate.capabilities.get();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Use an explicit instance for dependency injection:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { Filegate } from "@valentinkolb/filegate/client";
|
|
36
|
+
|
|
37
|
+
const fg = new Filegate({
|
|
38
|
+
baseUrl: "https://filegate.internal.example",
|
|
39
|
+
token: "<filegate-token>",
|
|
40
|
+
fetchImpl: fetch,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const node = await fg.paths.get("photos/2026");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The client namespaces match the API surface:
|
|
47
|
+
|
|
48
|
+
| Namespace | Meaning |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `paths` | Path-based lookup, upload, and directory listing. |
|
|
51
|
+
| `nodes` | ID-based metadata, content, mkdir, delete, and metadata edits. |
|
|
52
|
+
| `uploads` | One-shot direct upload URLs and resumable upload sessions. |
|
|
53
|
+
| `downloads` | Scoped direct download URLs. |
|
|
54
|
+
| `transfers` | Move and copy operations. |
|
|
55
|
+
| `search` | Indexed path search. |
|
|
56
|
+
| `index` | Index stats and rescan operations. |
|
|
57
|
+
| `stats` | Runtime, mount, cache, filesystem, and process stats. |
|
|
58
|
+
| `capabilities` | Server upload/download limits for adaptive clients. |
|
|
59
|
+
| `versions` | File version history on supported mounts. |
|
|
60
|
+
| `activity` | Recent API activity from the bounded server ring buffer. |
|
|
61
|
+
|
|
62
|
+
## Browser uploads
|
|
63
|
+
|
|
64
|
+
Do not expose the Filegate bearer token to browser code. The browser should ask
|
|
65
|
+
your application server for permission to upload. The application server then
|
|
66
|
+
creates direct Filegate upload URLs or direct upload sessions and returns the
|
|
67
|
+
scoped credentials to the browser.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { upload } from "@valentinkolb/filegate/client";
|
|
71
|
+
|
|
72
|
+
await upload({
|
|
73
|
+
files,
|
|
74
|
+
path: "photos/inbox",
|
|
75
|
+
allow: async (request) => {
|
|
76
|
+
const response = await fetch("/api/filegate/uploads/allow", {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "Content-Type": "application/json" },
|
|
79
|
+
body: JSON.stringify(request),
|
|
80
|
+
});
|
|
81
|
+
return response.json();
|
|
82
|
+
},
|
|
83
|
+
onEvent: (event) => {
|
|
84
|
+
console.log(event.type, event);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The high-level helper uses the transfer shape from the allow response. Small
|
|
90
|
+
files can use direct one-shot URLs. Larger files can use resumable sessions
|
|
91
|
+
with parallel segment uploads. Conflict handling is explicit; `skip-existing`
|
|
92
|
+
is the default.
|
|
93
|
+
|
|
94
|
+
For a single direct upload URL:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { uploadDirect } from "@valentinkolb/filegate/client";
|
|
98
|
+
|
|
99
|
+
await uploadDirect(uploadUrlFromYourServer, file, {
|
|
100
|
+
onSuccess: ({ node }) => console.log(node.id),
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Browser downloads
|
|
105
|
+
|
|
106
|
+
Mint the direct download URL on your application server and redirect the
|
|
107
|
+
browser:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const direct = await fg.downloads.createDirectURL({
|
|
111
|
+
nodeId: "<node-id>",
|
|
112
|
+
expiresInSeconds: 5 * 60,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return Response.redirect(direct.downloadUrl, 303);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Direct file downloads support `GET`, `HEAD`, and byte ranges. Directory
|
|
119
|
+
downloads stream tar archives.
|
|
120
|
+
|
|
121
|
+
## Resumable sessions
|
|
122
|
+
|
|
123
|
+
Use upload sessions when you need resumable, parallel uploads with explicit
|
|
124
|
+
commit:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const session = await fg.uploads.sessions.create({
|
|
128
|
+
path: "videos/input.mov",
|
|
129
|
+
size,
|
|
130
|
+
checksum,
|
|
131
|
+
segmentSize: 16 * 1024 * 1024,
|
|
132
|
+
onConflict: "error",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
for (const segment of session.segments) {
|
|
136
|
+
await fg.uploads.sessions.segments.put({
|
|
137
|
+
sessionId: session.id,
|
|
138
|
+
index: segment.index,
|
|
139
|
+
body: segmentBody,
|
|
140
|
+
checksum: segmentChecksum,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const committed = await fg.uploads.sessions.commit({ sessionId: session.id });
|
|
145
|
+
console.log(committed.node.id);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Segment PUTs are idempotent when the content matches. Commit is explicit and
|
|
149
|
+
safe to retry after success.
|
|
150
|
+
|
|
151
|
+
## Utilities
|
|
152
|
+
|
|
153
|
+
Pure helpers live under `@valentinkolb/filegate/utils` and do not require a
|
|
154
|
+
Filegate token:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { uploads } from "@valentinkolb/filegate/utils";
|
|
158
|
+
|
|
159
|
+
const checksum = await uploads.checksum.sha256(file);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Documentation
|
|
163
|
+
|
|
164
|
+
- Project README: https://github.com/ValentinKolb/filegate#readme
|
|
165
|
+
- TypeScript guide: https://github.com/ValentinKolb/filegate/blob/main/docs/ts-client.md
|
|
166
|
+
- HTTP routes: https://github.com/ValentinKolb/filegate/blob/main/docs/http-routes.md
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valentinkolb/filegate",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "TypeScript client for the Filegate filesystem gateway",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "tsc",
|