2024-01-12 04:13:10 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2024-01-19 22:08:05 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/api/middleware"
|
2024-01-16 16:42:50 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/api/s5"
|
2024-01-12 04:13:10 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/protocols"
|
2024-01-25 23:25:10 +00:00
|
|
|
"github.com/rs/cors"
|
2024-01-16 16:42:50 +00:00
|
|
|
"go.sia.tech/jape"
|
2024-01-12 04:13:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ interfaces.API = (*S5API)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type S5API struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewS5() *S5API {
|
|
|
|
return &S5API{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s S5API) Initialize(portal interfaces.Portal, protocol interfaces.Protocol) error {
|
|
|
|
s5protocol := protocol.(*protocols.S5Protocol)
|
2024-01-16 16:42:50 +00:00
|
|
|
s5http := s5.NewHttpHandler(portal)
|
2024-01-17 13:16:03 +00:00
|
|
|
registerProtocolSubdomain(portal, s5protocol.Node().Services().HTTP().GetHttpRouter(getRoutes(s5http, portal)), "s5")
|
2024-01-12 04:13:10 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2024-01-16 16:42:50 +00:00
|
|
|
|
2024-01-17 13:16:03 +00:00
|
|
|
func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Handler {
|
2024-01-19 22:08:05 +00:00
|
|
|
|
|
|
|
tusHandler := middleware.BuildS5TusApi(portal)
|
|
|
|
|
2024-01-16 16:42:50 +00:00
|
|
|
return map[string]jape.Handler{
|
2024-01-17 18:04:32 +00:00
|
|
|
// Account API
|
2024-01-16 18:57:33 +00:00
|
|
|
"GET /s5/account/register": h.AccountRegisterChallenge,
|
|
|
|
"POST /s5/account/register": h.AccountRegister,
|
|
|
|
"GET /s5/account/login": h.AccountLoginChallenge,
|
|
|
|
"POST /s5/account/login": h.AccountLogin,
|
2024-01-22 21:59:14 +00:00
|
|
|
"GET /s5/account": middleware.ApplyMiddlewares(h.AccountInfo, middleware.AuthMiddleware(portal)),
|
|
|
|
"GET /s5/account/stats": middleware.ApplyMiddlewares(h.AccountStats, middleware.AuthMiddleware(portal)),
|
|
|
|
"GET /s5/account/pins.bin": middleware.ApplyMiddlewares(h.AccountPins, middleware.AuthMiddleware(portal)),
|
2024-01-17 18:04:32 +00:00
|
|
|
|
|
|
|
// Upload API
|
2024-01-22 21:59:14 +00:00
|
|
|
"POST /s5/upload": middleware.ApplyMiddlewares(h.SmallFileUpload, middleware.AuthMiddleware(portal)),
|
|
|
|
"POST /s5/upload/directory": middleware.ApplyMiddlewares(h.DirectoryUpload, middleware.AuthMiddleware(portal)),
|
2024-01-17 18:04:32 +00:00
|
|
|
|
2024-01-19 22:08:55 +00:00
|
|
|
// Tus API
|
|
|
|
"POST /s5/upload/tus": tusHandler,
|
|
|
|
"HEAD /s5/upload/tus/:id": tusHandler,
|
|
|
|
"POST /s5/upload/tus/:id": tusHandler,
|
|
|
|
"PATCH /s5/upload/tus/:id": tusHandler,
|
|
|
|
|
2024-01-18 02:23:33 +00:00
|
|
|
// Download API
|
2024-01-22 21:59:14 +00:00
|
|
|
"GET /s5/blob/:cid": middleware.ApplyMiddlewares(h.DownloadBlob, middleware.AuthMiddleware(portal)),
|
2024-01-18 17:18:45 +00:00
|
|
|
"GET /s5/metadata/:cid": h.DownloadMetadata,
|
2024-01-24 22:07:50 +00:00
|
|
|
// "GET /s5/download/:cid": middleware.ApplyMiddlewares(h.DownloadFile, middleware.AuthMiddleware(portal)),
|
2024-01-25 23:25:10 +00:00
|
|
|
"GET /s5/download/:cid": middleware.ApplyMiddlewares(h.DownloadFile, cors.Default().Handler),
|
2024-01-18 02:23:33 +00:00
|
|
|
|
2024-01-17 18:04:32 +00:00
|
|
|
// Pins API
|
2024-01-22 21:59:14 +00:00
|
|
|
"POST /s5/pin/:cid": middleware.ApplyMiddlewares(h.AccountPin, middleware.AuthMiddleware(portal)),
|
|
|
|
"DELETE /s5/delete/:cid": middleware.ApplyMiddlewares(h.AccountPinDelete, middleware.AuthMiddleware(portal)),
|
2024-01-17 20:36:21 +00:00
|
|
|
|
|
|
|
// Debug API
|
2024-01-22 21:59:14 +00:00
|
|
|
"GET /s5/debug/download_urls/:cid": middleware.ApplyMiddlewares(h.DebugDownloadUrls, middleware.AuthMiddleware(portal)),
|
|
|
|
"GET /s5/debug/storage_locations/:hash": middleware.ApplyMiddlewares(h.DebugStorageLocations, middleware.AuthMiddleware(portal)),
|
2024-01-17 21:05:11 +00:00
|
|
|
|
2024-01-19 22:08:05 +00:00
|
|
|
// Registry API
|
2024-01-22 21:59:14 +00:00
|
|
|
"GET /s5/registry": middleware.ApplyMiddlewares(h.RegistryQuery, middleware.AuthMiddleware(portal)),
|
|
|
|
"POST /s5/registry": middleware.ApplyMiddlewares(h.RegistrySet, middleware.AuthMiddleware(portal)),
|
|
|
|
"GET /s5/registry/subscription": middleware.ApplyMiddlewares(h.RegistrySubscription, middleware.AuthMiddleware(portal)),
|
2024-01-16 16:42:50 +00:00
|
|
|
}
|
|
|
|
}
|