diff --git a/service/account_service.go b/controller/account.go similarity index 97% rename from service/account_service.go rename to controller/account.go index 79114da..cef42cf 100644 --- a/service/account_service.go +++ b/controller/account.go @@ -1,4 +1,4 @@ -package service +package controller import ( "crypto/ed25519" @@ -14,7 +14,7 @@ import ( "reflect" ) -type AccountService struct { +type AccountController struct { Ctx iris.Context } @@ -64,7 +64,7 @@ func hashPassword(password string) (string, error) { return string(hashedPassword), nil } -func (a *AccountService) PostRegister() { +func (a *AccountController) PostRegister() { var r RegisterRequest if err := a.Ctx.ReadJSON(&r); err != nil { diff --git a/service/auth_service.go b/controller/auth.go similarity index 97% rename from service/auth_service.go rename to controller/auth.go index 14a7cd8..1ad1013 100644 --- a/service/auth_service.go +++ b/controller/auth.go @@ -1,4 +1,4 @@ -package service +package controller import ( "crypto/ed25519" @@ -22,7 +22,7 @@ func init() { blocklist = jwt.NewBlocklist(1 * time.Hour) } -type AuthService struct { +type AuthController struct { Ctx iris.Context } @@ -132,7 +132,7 @@ func generateAndSaveChallengeToken(accountID uint, maxAge time.Duration) (string } // PostLogin handles the POST /api/auth/login request to authenticate a user and return a JWT token. -func (a *AuthService) PostLogin() { +func (a *AuthController) PostLogin() { var r LoginRequest // Read the login request from the client. @@ -169,7 +169,7 @@ func (a *AuthService) PostLogin() { } // PostChallenge handles the POST /api/auth/pubkey/challenge request to generate a challenge for a user's public key. -func (a *AuthService) PostPubkeyChallenge() { +func (a *AuthController) PostPubkeyChallenge() { var r LoginRequest // Read the login request from the client. @@ -200,7 +200,7 @@ func (a *AuthService) PostPubkeyChallenge() { } // PostKeyLogin handles the POST /api/auth/pubkey/login request to authenticate a user using a public key challenge and return a JWT token. -func (a *AuthService) PostPubkeyLogin() { +func (a *AuthController) PostPubkeyLogin() { var r PubkeyLoginRequest // Read the key login request from the client. @@ -268,7 +268,7 @@ func (a *AuthService) PostPubkeyLogin() { } // PostLogout handles the POST /api/auth/logout request to invalidate a JWT token. -func (a *AuthService) PostLogout() { +func (a *AuthController) PostLogout() { var r LogoutRequest // Read the logout request from the client. diff --git a/service/files_service.go b/controller/files.go similarity index 95% rename from service/files_service.go rename to controller/files.go index a0ed4be..15f46e8 100644 --- a/service/files_service.go +++ b/controller/files.go @@ -1,4 +1,4 @@ -package service +package controller import ( "bytes" @@ -16,7 +16,7 @@ import ( "lukechampine.com/blake3" ) -type FilesService struct { +type FilesController struct { Ctx iris.Context } @@ -33,7 +33,7 @@ func InitFiles() { client.SetDisableWarn(true) } -func (f *FilesService) PostUpload() { +func (f *FilesController) PostUpload() { ctx := f.Ctx file, meta, err := f.Ctx.FormFile("file") @@ -52,7 +52,7 @@ func (f *FilesService) PostUpload() { hashBytes := blake3.Sum256(buf) hashHex := hex.EncodeToString(hashBytes[:]) - fileCid, err := cid.Encode(hashBytes, uint64(meta.Size)) + fileCid, err := cid.EncodeFixed(hashBytes, uint64(meta.Size)) if internalError(ctx, err) { return @@ -123,7 +123,7 @@ func (f *FilesService) PostUpload() { ctx.JSON(&UploadResponse{Cid: fileCid}) } -func (f *FilesService) GetDownload() { +func (f *FilesController) GetDownload() { ctx := f.Ctx cidString := ctx.URLParam("cid") diff --git a/main.go b/main.go index e9c045e..bab6ae7 100644 --- a/main.go +++ b/main.go @@ -3,10 +3,10 @@ package main import ( "embed" "git.lumeweb.com/LumeWeb/portal/config" + "git.lumeweb.com/LumeWeb/portal/controller" "git.lumeweb.com/LumeWeb/portal/db" _ "git.lumeweb.com/LumeWeb/portal/docs" "git.lumeweb.com/LumeWeb/portal/renterd" - "git.lumeweb.com/LumeWeb/portal/service" "git.lumeweb.com/LumeWeb/portal/validator" "github.com/iris-contrib/swagger" "github.com/iris-contrib/swagger/swaggerFiles" @@ -45,7 +45,7 @@ func main() { renterd.Ready() - service.InitFiles() + controller.InitFiles() // Create a new Iris app instance app := iris.New() @@ -61,7 +61,7 @@ func main() { api := app.Party("/api") v1 := api.Party("/v1") - // Register the AccountService with the MVC framework and attach it to the "/api/account" path + // Register the AccountController with the MVC framework and attach it to the "/api/account" path mvc.Configure(v1.Party("/account"), func(app *mvc.Application) { app.Handle(new(service.AccountService)) }) @@ -71,7 +71,7 @@ func main() { }) mvc.Configure(v1.Party("/files"), func(app *mvc.Application) { - app.Handle(new(service.FilesService)) + app.Handle(new(controller.FilesController)) }) swaggerConfig := swagger.Config{