refactor: un-export all s5 http handlers
This commit is contained in:
parent
3c55ed2853
commit
5598660176
|
@ -126,7 +126,7 @@ func NewHttpHandler(params HttpHandlerParams) (HttpHandlerResult, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) SmallFileUpload(jc jape.Context) {
|
func (h *HttpHandler) smallFileUpload(jc jape.Context) {
|
||||||
var rs io.ReadSeeker
|
var rs io.ReadSeeker
|
||||||
var bufferSize int64
|
var bufferSize int64
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ func (h *HttpHandler) SmallFileUpload(jc jape.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountRegisterChallenge(jc jape.Context) {
|
func (h *HttpHandler) accountRegisterChallenge(jc jape.Context) {
|
||||||
var pubkey string
|
var pubkey string
|
||||||
if jc.DecodeForm("pubKey", &pubkey) != nil {
|
if jc.DecodeForm("pubKey", &pubkey) != nil {
|
||||||
return
|
return
|
||||||
|
@ -320,7 +320,7 @@ func (h *HttpHandler) AccountRegisterChallenge(jc jape.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountRegister(jc jape.Context) {
|
func (h *HttpHandler) accountRegister(jc jape.Context) {
|
||||||
var request AccountRegisterRequest
|
var request AccountRegisterRequest
|
||||||
|
|
||||||
if jc.Decode(&request) != nil {
|
if jc.Decode(&request) != nil {
|
||||||
|
@ -458,7 +458,7 @@ func (h *HttpHandler) AccountRegister(jc jape.Context) {
|
||||||
setAuthCookie(jwt, jc)
|
setAuthCookie(jwt, jc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountLoginChallenge(jc jape.Context) {
|
func (h *HttpHandler) accountLoginChallenge(jc jape.Context) {
|
||||||
var pubkey string
|
var pubkey string
|
||||||
if jc.DecodeForm("pubKey", &pubkey) != nil {
|
if jc.DecodeForm("pubKey", &pubkey) != nil {
|
||||||
return
|
return
|
||||||
|
@ -512,7 +512,7 @@ func (h *HttpHandler) AccountLoginChallenge(jc jape.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountLogin(jc jape.Context) {
|
func (h *HttpHandler) accountLogin(jc jape.Context) {
|
||||||
var request AccountLoginRequest
|
var request AccountLoginRequest
|
||||||
|
|
||||||
if jc.Decode(&request) != nil {
|
if jc.Decode(&request) != nil {
|
||||||
|
@ -602,7 +602,7 @@ func (h *HttpHandler) AccountLogin(jc jape.Context) {
|
||||||
setAuthCookie(jwt, jc)
|
setAuthCookie(jwt, jc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountInfo(jc jape.Context) {
|
func (h *HttpHandler) accountInfo(jc jape.Context) {
|
||||||
_, user := h.accounts.AccountExists(jc.Request.Context().Value(middleware.S5AuthUserIDKey).(uint64))
|
_, user := h.accounts.AccountExists(jc.Request.Context().Value(middleware.S5AuthUserIDKey).(uint64))
|
||||||
|
|
||||||
info := &AccountInfoResponse{
|
info := &AccountInfoResponse{
|
||||||
|
@ -622,7 +622,7 @@ func (h *HttpHandler) AccountInfo(jc jape.Context) {
|
||||||
jc.Encode(info)
|
jc.Encode(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountStats(jc jape.Context) {
|
func (h *HttpHandler) accountStats(jc jape.Context) {
|
||||||
_, user := h.accounts.AccountExists(jc.Request.Context().Value(middleware.S5AuthUserIDKey).(uint64))
|
_, user := h.accounts.AccountExists(jc.Request.Context().Value(middleware.S5AuthUserIDKey).(uint64))
|
||||||
|
|
||||||
info := &AccountStatsResponse{
|
info := &AccountStatsResponse{
|
||||||
|
@ -649,7 +649,7 @@ func (h *HttpHandler) AccountStats(jc jape.Context) {
|
||||||
jc.Encode(info)
|
jc.Encode(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountPins(jc jape.Context) {
|
func (h *HttpHandler) accountPins(jc jape.Context) {
|
||||||
var cursor uint64
|
var cursor uint64
|
||||||
|
|
||||||
if jc.DecodeForm("cursor", &cursor) != nil {
|
if jc.DecodeForm("cursor", &cursor) != nil {
|
||||||
|
@ -683,7 +683,7 @@ func (h *HttpHandler) AccountPins(jc jape.Context) {
|
||||||
_, _ = jc.ResponseWriter.Write(result)
|
_, _ = jc.ResponseWriter.Write(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountPinDelete(jc jape.Context) {
|
func (h *HttpHandler) accountPinDelete(jc jape.Context) {
|
||||||
var cid string
|
var cid string
|
||||||
if jc.DecodeParam("cid", &cid) != nil {
|
if jc.DecodeParam("cid", &cid) != nil {
|
||||||
return
|
return
|
||||||
|
@ -712,7 +712,7 @@ func (h *HttpHandler) AccountPinDelete(jc jape.Context) {
|
||||||
jc.ResponseWriter.WriteHeader(http.StatusNoContent)
|
jc.ResponseWriter.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) AccountPin(jc jape.Context) {
|
func (h *HttpHandler) accountPin(jc jape.Context) {
|
||||||
var cid string
|
var cid string
|
||||||
if jc.DecodeParam("cid", &cid) != nil {
|
if jc.DecodeParam("cid", &cid) != nil {
|
||||||
return
|
return
|
||||||
|
@ -745,7 +745,7 @@ func (h *HttpHandler) AccountPin(jc jape.Context) {
|
||||||
jc.ResponseWriter.WriteHeader(http.StatusNoContent)
|
jc.ResponseWriter.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) DirectoryUpload(jc jape.Context) {
|
func (h *HttpHandler) directoryUpload(jc jape.Context) {
|
||||||
var tryFiles []string
|
var tryFiles []string
|
||||||
var errorPages map[int]string
|
var errorPages map[int]string
|
||||||
var name string
|
var name string
|
||||||
|
@ -941,7 +941,7 @@ func (h *HttpHandler) DirectoryUpload(jc jape.Context) {
|
||||||
jc.Encode(&AppUploadResponse{CID: cidStr})
|
jc.Encode(&AppUploadResponse{CID: cidStr})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) DebugDownloadUrls(jc jape.Context) {
|
func (h *HttpHandler) debugDownloadUrls(jc jape.Context) {
|
||||||
var cid string
|
var cid string
|
||||||
if jc.DecodeParam("cid", &cid) != nil {
|
if jc.DecodeParam("cid", &cid) != nil {
|
||||||
return
|
return
|
||||||
|
@ -1023,7 +1023,7 @@ func (h *HttpHandler) DebugDownloadUrls(jc jape.Context) {
|
||||||
_, _ = jc.ResponseWriter.Write([]byte(strings.Join(output, "\n")))
|
_, _ = jc.ResponseWriter.Write([]byte(strings.Join(output, "\n")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) RegistryQuery(jc jape.Context) {
|
func (h *HttpHandler) registryQuery(jc jape.Context) {
|
||||||
var pk string
|
var pk string
|
||||||
|
|
||||||
if jc.DecodeForm("pk", &pk) != nil {
|
if jc.DecodeForm("pk", &pk) != nil {
|
||||||
|
@ -1052,7 +1052,8 @@ func (h *HttpHandler) RegistryQuery(jc jape.Context) {
|
||||||
Signature: base64.RawURLEncoding.EncodeToString(entry.Signature()),
|
Signature: base64.RawURLEncoding.EncodeToString(entry.Signature()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func (h *HttpHandler) RegistrySet(jc jape.Context) {
|
|
||||||
|
func (h *HttpHandler) registrySet(jc jape.Context) {
|
||||||
var request RegistrySetRequest
|
var request RegistrySetRequest
|
||||||
|
|
||||||
if jc.Decode(&request) != nil {
|
if jc.Decode(&request) != nil {
|
||||||
|
@ -1082,7 +1083,7 @@ func (h *HttpHandler) RegistrySet(jc jape.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) RegistrySubscription(jc jape.Context) {
|
func (h *HttpHandler) registrySubscription(jc jape.Context) {
|
||||||
// Create a context for the WebSocket operations
|
// Create a context for the WebSocket operations
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -1168,7 +1169,7 @@ func (h *HttpHandler) getNode() *libs5node.Node {
|
||||||
return h.protocol.Node()
|
return h.protocol.Node()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) DownloadBlob(jc jape.Context) {
|
func (h *HttpHandler) downloadBlob(jc jape.Context) {
|
||||||
var cid string
|
var cid string
|
||||||
|
|
||||||
if jc.DecodeParam("cid", &cid) != nil {
|
if jc.DecodeParam("cid", &cid) != nil {
|
||||||
|
@ -1198,7 +1199,7 @@ func (h *HttpHandler) DownloadBlob(jc jape.Context) {
|
||||||
http.Redirect(jc.ResponseWriter, jc.Request, next.Location().BytesURL(), http.StatusFound)
|
http.Redirect(jc.ResponseWriter, jc.Request, next.Location().BytesURL(), http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) DebugStorageLocations(jc jape.Context) {
|
func (h *HttpHandler) debugStorageLocations(jc jape.Context) {
|
||||||
var hash string
|
var hash string
|
||||||
|
|
||||||
if jc.DecodeParam("hash", &hash) != nil {
|
if jc.DecodeParam("hash", &hash) != nil {
|
||||||
|
@ -1298,7 +1299,7 @@ func (h *HttpHandler) DebugStorageLocations(jc jape.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) DownloadMetadata(jc jape.Context) {
|
func (h *HttpHandler) downloadMetadata(jc jape.Context) {
|
||||||
var cid string
|
var cid string
|
||||||
|
|
||||||
if jc.DecodeParam("cid", &cid) != nil {
|
if jc.DecodeParam("cid", &cid) != nil {
|
||||||
|
@ -1338,7 +1339,7 @@ func (h *HttpHandler) DownloadMetadata(jc jape.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandler) DownloadFile(jc jape.Context) {
|
func (h *HttpHandler) downloadFile(jc jape.Context) {
|
||||||
var cid string
|
var cid string
|
||||||
|
|
||||||
if jc.DecodeParam("cid", &cid) != nil {
|
if jc.DecodeParam("cid", &cid) != nil {
|
||||||
|
|
38
api/s5/s5.go
38
api/s5/s5.go
|
@ -160,17 +160,17 @@ func getRoutes(s *S5API) map[string]jape.Handler {
|
||||||
|
|
||||||
return map[string]jape.Handler{
|
return map[string]jape.Handler{
|
||||||
// Account API
|
// Account API
|
||||||
"GET /s5/account/register": s.httpHandler.AccountRegisterChallenge,
|
"GET /s5/account/register": s.httpHandler.accountRegisterChallenge,
|
||||||
"POST /s5/account/register": s.httpHandler.AccountRegister,
|
"POST /s5/account/register": s.httpHandler.accountRegister,
|
||||||
"GET /s5/account/login": s.httpHandler.AccountLoginChallenge,
|
"GET /s5/account/login": s.httpHandler.accountLoginChallenge,
|
||||||
"POST /s5/account/login": s.httpHandler.AccountLogin,
|
"POST /s5/account/login": s.httpHandler.accountLogin,
|
||||||
"GET /s5/account": middleware.ApplyMiddlewares(s.httpHandler.AccountInfo, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/account": middleware.ApplyMiddlewares(s.httpHandler.accountInfo, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"GET /s5/account/stats": middleware.ApplyMiddlewares(s.httpHandler.AccountStats, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/account/stats": middleware.ApplyMiddlewares(s.httpHandler.accountStats, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"GET /s5/account/pins.bin": middleware.ApplyMiddlewares(s.httpHandler.AccountPins, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/account/pins.bin": middleware.ApplyMiddlewares(s.httpHandler.accountPins, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
|
|
||||||
// Upload API
|
// Upload API
|
||||||
"POST /s5/upload": middleware.ApplyMiddlewares(s.httpHandler.SmallFileUpload, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"POST /s5/upload": middleware.ApplyMiddlewares(s.httpHandler.smallFileUpload, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"POST /s5/upload/directory": middleware.ApplyMiddlewares(s.httpHandler.DirectoryUpload, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"POST /s5/upload/directory": middleware.ApplyMiddlewares(s.httpHandler.directoryUpload, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
|
|
||||||
// Tus API
|
// Tus API
|
||||||
"POST /s5/upload/tus": tusHandler,
|
"POST /s5/upload/tus": tusHandler,
|
||||||
|
@ -181,22 +181,22 @@ func getRoutes(s *S5API) map[string]jape.Handler {
|
||||||
"OPTIONS /s5/upload/tus/:id": wrappedTusHandler,
|
"OPTIONS /s5/upload/tus/:id": wrappedTusHandler,
|
||||||
|
|
||||||
// Download API
|
// Download API
|
||||||
"GET /s5/blob/:cid": middleware.ApplyMiddlewares(s.httpHandler.DownloadBlob, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/blob/:cid": middleware.ApplyMiddlewares(s.httpHandler.downloadBlob, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"GET /s5/metadata/:cid": s.httpHandler.DownloadMetadata,
|
"GET /s5/metadata/:cid": s.httpHandler.downloadMetadata,
|
||||||
"GET /s5/download/:cid": middleware.ApplyMiddlewares(s.httpHandler.DownloadFile, cors.Default().Handler),
|
"GET /s5/download/:cid": middleware.ApplyMiddlewares(s.httpHandler.downloadFile, cors.Default().Handler),
|
||||||
|
|
||||||
// Pins API
|
// Pins API
|
||||||
"POST /s5/pin/:cid": middleware.ApplyMiddlewares(s.httpHandler.AccountPin, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"POST /s5/pin/:cid": middleware.ApplyMiddlewares(s.httpHandler.accountPin, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"DELETE /s5/delete/:cid": middleware.ApplyMiddlewares(s.httpHandler.AccountPinDelete, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"DELETE /s5/delete/:cid": middleware.ApplyMiddlewares(s.httpHandler.accountPinDelete, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
|
|
||||||
// Debug API
|
// Debug API
|
||||||
"GET /s5/debug/download_urls/:cid": middleware.ApplyMiddlewares(s.httpHandler.DebugDownloadUrls, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/debug/download_urls/:cid": middleware.ApplyMiddlewares(s.httpHandler.debugDownloadUrls, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"GET /s5/debug/storage_locations/:hash": middleware.ApplyMiddlewares(s.httpHandler.DebugStorageLocations, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/debug/storage_locations/:hash": middleware.ApplyMiddlewares(s.httpHandler.debugStorageLocations, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
|
|
||||||
// Registry API
|
// Registry API
|
||||||
"GET /s5/registry": middleware.ApplyMiddlewares(s.httpHandler.RegistryQuery, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/registry": middleware.ApplyMiddlewares(s.httpHandler.registryQuery, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"POST /s5/registry": middleware.ApplyMiddlewares(s.httpHandler.RegistrySet, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"POST /s5/registry": middleware.ApplyMiddlewares(s.httpHandler.registrySet, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
"GET /s5/registry/subscription": middleware.ApplyMiddlewares(s.httpHandler.RegistrySubscription, middleware.AuthMiddleware(s.identity, s.accounts)),
|
"GET /s5/registry/subscription": middleware.ApplyMiddlewares(s.httpHandler.registrySubscription, middleware.AuthMiddleware(s.identity, s.accounts)),
|
||||||
|
|
||||||
"GET /swagger.json": byteHandler(jsonDoc),
|
"GET /swagger.json": byteHandler(jsonDoc),
|
||||||
"GET /swagger": swaggerRedirect,
|
"GET /swagger": swaggerRedirect,
|
||||||
|
|
Loading…
Reference in New Issue