Browse Source

Rename -tus.path to -tusBasePath with default .tus

- Rename CLI flag from -tus.path to -tusBasePath
- Default to .tus (TUS enabled by default)
- Add -filer.tusBasePath option to weed server command
- Properly handle path prefix (prepend / if missing)
pull/7592/head
chrislu 1 month ago
parent
commit
42b173fff9
  1. 3
      test/tus/Makefile
  2. 15
      test/tus/README.md
  3. 2
      weed/command/filer.go
  4. 1
      weed/command/server.go
  5. 3
      weed/server/filer_server.go
  6. 11
      weed/server/filer_server_tus_handlers.go

3
test/tus/Makefile

@ -95,13 +95,12 @@ start-seaweedfs: check-binary
> /tmp/seaweedfs-tus-volume.log 2>&1 &
@sleep 3
# Start filer server with TUS enabled
# Start filer server with TUS enabled (default tusBasePath is .tus)
@echo "Starting filer server..."
@nohup $(SEAWEEDFS_ROOT)/weed/weed filer \
-port=$(FILER_PORT) \
-master=127.0.0.1:$(MASTER_PORT) \
-ip=127.0.0.1 \
-tus.path=/.tus \
> /tmp/seaweedfs-tus-filer.log 2>&1 &
@sleep 5

15
test/tus/README.md

@ -42,17 +42,18 @@ TUS is an open protocol for resumable file uploads over HTTP. It allows clients
## Enabling TUS
TUS protocol support must be explicitly enabled when starting the filer server using the `-tus.path` flag:
TUS protocol support is enabled by default at `/.tus` path. You can customize the path using the `-tusBasePath` flag:
```bash
# Start filer with TUS enabled at /.tus path
weed filer -master=localhost:9333 -tus.path=/.tus
# Start filer with default TUS path (/.tus)
weed filer -master=localhost:9333
# Or use a custom path
weed filer -master=localhost:9333 -tus.path=/uploads/tus
```
# Use a custom path
weed filer -master=localhost:9333 -tusBasePath=uploads/tus
If `-tus.path` is not specified, TUS endpoints are disabled.
# Disable TUS by setting empty path
weed filer -master=localhost:9333 -tusBasePath=
```
## Test Structure

2
weed/command/filer.go

@ -110,7 +110,7 @@ func init() {
f.diskType = cmdFiler.Flag.String("disk", "", "[hdd|ssd|<tag>] hard drive or solid state drive or any tag")
f.allowedOrigins = cmdFiler.Flag.String("allowedOrigins", "*", "comma separated list of allowed origins")
f.exposeDirectoryData = cmdFiler.Flag.Bool("exposeDirectoryData", true, "whether to return directory metadata and content in Filer UI")
f.tusPath = cmdFiler.Flag.String("tus.path", "", "TUS resumable upload endpoint path, e.g., /.tus (disabled if empty)")
f.tusPath = cmdFiler.Flag.String("tusBasePath", ".tus", "TUS resumable upload endpoint base path")
// start s3 on filer
filerStartS3 = cmdFiler.Flag.Bool("s3", false, "whether to start S3 gateway")

1
weed/command/server.go

@ -129,6 +129,7 @@ func init() {
filerOptions.downloadMaxMBps = cmdServer.Flag.Int("filer.downloadMaxMBps", 0, "download max speed for each download request, in MB per second")
filerOptions.diskType = cmdServer.Flag.String("filer.disk", "", "[hdd|ssd|<tag>] hard drive or solid state drive or any tag")
filerOptions.exposeDirectoryData = cmdServer.Flag.Bool("filer.exposeDirectoryData", true, "expose directory data via filer. If false, filer UI will be innaccessible.")
filerOptions.tusPath = cmdServer.Flag.String("filer.tusBasePath", ".tus", "TUS resumable upload endpoint base path")
serverOptions.v.port = cmdServer.Flag.Int("volume.port", 8080, "volume server http listen port")
serverOptions.v.portGrpc = cmdServer.Flag.Int("volume.port.grpc", 0, "volume server grpc listen port")

3
weed/server/filer_server.go

@ -199,6 +199,9 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
// TUS resumable upload protocol handler
if option.TusPath != "" {
tusPath := option.TusPath
if !strings.HasPrefix(tusPath, "/") {
tusPath = "/" + tusPath
}
if !strings.HasSuffix(tusPath, "/") {
tusPath += "/"
}

11
weed/server/filer_server_tus_handlers.go

@ -37,7 +37,10 @@ func (fs *FilerServer) tusHandler(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
tusPrefix := fs.option.TusPath
if tusPrefix == "" {
tusPrefix = "/.tus"
tusPrefix = ".tus"
}
if !strings.HasPrefix(tusPrefix, "/") {
tusPrefix = "/" + tusPrefix
}
// Check if this is an upload location (contains upload ID after {tusPrefix}/.uploads/)
@ -104,7 +107,10 @@ func (fs *FilerServer) tusCreateHandler(w http.ResponseWriter, r *http.Request)
// Get TUS path prefix
tusPrefix := fs.option.TusPath
if tusPrefix == "" {
tusPrefix = "/.tus"
tusPrefix = ".tus"
}
if !strings.HasPrefix(tusPrefix, "/") {
tusPrefix = "/" + tusPrefix
}
// Determine target path from request URL
@ -366,4 +372,3 @@ func parseTusMetadata(header string) map[string]string {
return metadata
}
Loading…
Cancel
Save