Skip to content

Commit a3582a3

Browse files
committed
Ok, this should be more or less it
1 parent ad9f19a commit a3582a3

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

pkg/server/cmd/server.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,16 @@ func buildConfig(bundledFiles fs.FS, args []string) *server.ServerConfig {
112112
}
113113
}
114114

115-
serverConfig.ClientBundle = server.NewReadOnlyFallthroughSpacePrimitives(bundledFiles, "dist_client_bundle", time.Now(), nil)
116-
serverConfig.SpacePrimitives = server.NewReadOnlyFallthroughSpacePrimitives(bundledFiles, "dist_plug_bundle", time.Now(), spacePrimitives)
115+
// Extract the last modified time from the main binary, best effort
116+
bundlePathDate := time.Now()
117+
if executablePath, err := os.Executable(); err == nil {
118+
if stat, err := os.Stat(executablePath); err == nil {
119+
bundlePathDate = stat.ModTime()
120+
}
121+
}
122+
123+
serverConfig.ClientBundle = server.NewReadOnlyFallthroughSpacePrimitives(bundledFiles, "dist_client_bundle", bundlePathDate, nil)
124+
serverConfig.SpacePrimitives = server.NewReadOnlyFallthroughSpacePrimitives(bundledFiles, "dist_plug_bundle", bundlePathDate, spacePrimitives)
117125

118126
log.Printf("Starting SilverBullet binding to %s:%d", serverConfig.Hostname, serverConfig.Port)
119127
if serverConfig.Hostname == "127.0.0.1" {

pkg/server/fs.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,22 @@ func buildFsRoutes(spacePrimitives SpacePrimitives, spacePath string) http.Handl
1717
fsRouter := chi.NewRouter()
1818

1919
// File list endpoint
20-
fsRouter.Get("/", func(w http.ResponseWriter, r *http.Request) {
20+
fsRouter.Get("/", handleFsList(spacePrimitives, spacePath))
21+
22+
// File operations
23+
fsRouter.Get("/*", handleFsGet(spacePrimitives))
24+
fsRouter.Put("/*", handleFsPut(spacePrimitives))
25+
fsRouter.Delete("/*", handleFsDelete(spacePrimitives))
26+
fsRouter.Options("/*", func(w http.ResponseWriter, r *http.Request) {
27+
w.Header().Set("Allow", "GET, PUT, DELETE, OPTIONS")
28+
w.WriteHeader(http.StatusOK)
29+
})
30+
31+
return fsRouter
32+
}
33+
34+
func handleFsList(spacePrimitives SpacePrimitives, spacePath string) http.HandlerFunc {
35+
return func(w http.ResponseWriter, r *http.Request) {
2136
if r.Header.Get("X-Sync-Mode") != "" {
2237
// Handle direct requests for JSON representation of file list
2338
files, err := spacePrimitives.FetchFileList()
@@ -27,23 +42,11 @@ func buildFsRoutes(spacePrimitives SpacePrimitives, spacePath string) http.Handl
2742
}
2843
w.Header().Set("X-Space-Path", spacePath)
2944
render.JSON(w, r, files)
30-
3145
} else {
3246
// Otherwise, redirect to the UI
3347
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
3448
}
35-
})
36-
37-
// File operations
38-
fsRouter.Get("/*", handleFsGet(spacePrimitives))
39-
fsRouter.Put("/*", handleFsPut(spacePrimitives))
40-
fsRouter.Delete("/*", handleFsDelete(spacePrimitives))
41-
fsRouter.Options("/*", func(w http.ResponseWriter, r *http.Request) {
42-
w.Header().Set("Allow", "GET, PUT, DELETE, OPTIONS")
43-
w.WriteHeader(http.StatusOK)
44-
})
45-
46-
return fsRouter
49+
}
4750
}
4851

4952
// handleFsGet handles GET requests for individual files

0 commit comments

Comments
 (0)