MCPcopy
hub / github.com/pocketbase/pocketbase / bindFileApi

Function bindFileApi

apis/file.go:26–46  ·  view source on GitHub ↗

bindFileApi registers the file api endpoints and the corresponding handlers.

(app core.App, rg *router.RouterGroup[*core.RequestEvent])

Source from the content-addressed store, hash-verified

24
25// bindFileApi registers the file api endpoints and the corresponding handlers.
26func bindFileApi(app core.App, rg *router.RouterGroup[*core.RequestEvent]) {
27 maxWorkers := cast.ToInt64(os.Getenv("PB_THUMBS_MAX_WORKERS"))
28 if maxWorkers <= 0 {
29 maxWorkers = int64(runtime.NumCPU() + 2) // the value is arbitrary chosen and may change in the future
30 }
31
32 maxWait := cast.ToInt64(os.Getenv("PB_THUMBS_MAX_WAIT"))
33 if maxWait <= 0 {
34 maxWait = 60
35 }
36
37 api := fileApi{
38 thumbGenPending: new(singleflight.Group),
39 thumbGenSem: semaphore.NewWeighted(maxWorkers),
40 thumbGenMaxWait: time.Duration(maxWait) * time.Second,
41 }
42
43 sub := rg.Group("/files")
44 sub.POST("/token", api.fileToken).Bind(RequireAuth())
45 sub.GET("/{collection}/{recordId}/{filename}", api.download).Bind(collectionPathRateLimit("", "file"))
46}
47
48type fileApi struct {
49 // thumbGenSem is a semaphore to prevent too much concurrent

Callers 1

NewRouterFunction · 0.85

Calls 6

RequireAuthFunction · 0.85
collectionPathRateLimitFunction · 0.85
GroupMethod · 0.80
POSTMethod · 0.80
GETMethod · 0.80
BindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…