Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Convert id to unsigned types

Smaug#6739a7cd04b0d79f
diff --git a/backend/controllers/authentication.controller.go b/backend/controllers/authentication.controller.go
index 3055d701..3798e0b3 100644
--- a/backend/controllers/authentication.controller.go
+++ b/backend/controllers/authentication.controller.go
@@ -171,7 +171,7 @@ func (ctr *Controller) Logout(c *gin.Context) (int, any) {
func (ctr *Controller) signAccessToken(user *models.User) (string, error) {
claims := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
- "sub": strconv.FormatInt(user.Id, 10), // Subject (user identifier)
+ "sub": strconv.FormatUint(user.Id, 10), // Subject (user identifier)
"iss": "alexandrie", // Issuer
"exp": time.Now().Add(time.Duration(time.Second * time.Duration(ctr.app.Config.Auth.RefreshTokenExpiry))).Unix(), // Expiration time
"iat": time.Now().Unix(), // Issued at
diff --git a/backend/controllers/uploads.controller.go b/backend/controllers/uploads.controller.go
index b5526c9a..9a84bbe6 100644
--- a/backend/controllers/uploads.controller.go
+++ b/backend/controllers/uploads.controller.go
@@ -124,7 +124,7 @@ func (ctr *Controller) UploadFile(c *gin.Context) (int, any) {
// @Failure 400 {object} Error
// @Failure 401 {object} Error
func (ctr *Controller) DeleteUpload(c *gin.Context) (int, any) {
- id, err := strconv.ParseInt(c.Param("id"), 10, 64)
+ id, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
return http.StatusBadRequest, errors.New("invalid id format")
}
diff --git a/backend/middlewares/authentification.go b/backend/middlewares/authentification.go
index dd057264..7fbda862 100644
--- a/backend/middlewares/authentification.go
+++ b/backend/middlewares/authentification.go
@@ -37,7 +37,7 @@ func Auth() gin.HandlerFunc {
}
// Set the token claims to the context
- user_id, err := strconv.ParseInt(claims.Subject, 10, 64)
+ user_id, err := strconv.ParseUint(claims.Subject, 10, 64)
if err != nil {
c.JSON(http.StatusUnauthorized, utils.Error("Invalid user ID"))
c.Abort() // Stop further processing if unauthorized
diff --git a/backend/models/category.model.go b/backend/models/category.model.go
index fb856f23..f85c7595 100644
--- a/backend/models/category.model.go
+++ b/backend/models/category.model.go
@@ -1,12 +1,12 @@
package models
type Category struct {
- Id int64 `json:"id" form:"id" binding:"omitempty"`
- Name string `json:"name" form:"name" binding:"required,max=50"`
- Icon string `json:"icon" form:"icon" binding:"omitempty,max=30000"`
- Order int `json:"order" form:"order" binding:"omitempty"`
- Role int `json:"role" form:"role" binding:"omitempty"` // 0 category; 1 workspace;
- WorkspaceId *int64 `json:"workspace_id" form:"workspace_id" binding:"omitempty"`
- ParentId *int64 `json:"parent_id" form:"parent_id" binding:"omitempty"`
- AuthorId int64 `json:"author_id" form:"author_id" binding:"omitempty"`
+ Id uint64 `json:"id" form:"id" binding:"omitempty"`
+ Name string `json:"name" form:"name" binding:"required,max=50"`
+ Icon string `json:"icon" form:"icon" binding:"omitempty,max=30000"`
+ Order int `json:"order" form:"order" binding:"omitempty"`
+ Role int `json:"role" form:"role" binding:"omitempty"` // 0 category; 1 workspace;
+ WorkspaceId *uint64 `json:"workspace_id" form:"workspace_id" binding:"omitempty"`
+ ParentId *uint64 `json:"parent_id" form:"parent_id" binding:"omitempty"`
+ AuthorId uint64 `json:"author_id" form:"author_id" binding:"omitempty"`
}
diff --git a/backend/models/document.model.go b/backend/models/document.model.go
index 499237a4..22002c47 100644
--- a/backend/models/document.model.go
+++ b/backend/models/document.model.go
@@ -1,16 +1,16 @@
package models
type Document struct {
- Id int64 `json:"id" form:"id" binding:"omitempty"`
+ Id uint64 `json:"id" form:"id" binding:"omitempty"`
Name string `json:"name" form:"name" binding:"required,max=50"`
Description *string `json:"description" form:"description" binding:"omitempty,max=250"`
Tags *string `json:"tags" form:"tags" binding:"omitempty,max=250"`
- Category *int64 `json:"category" form:"category" binding:"omitempty"`
- ParentId *int64 `json:"parent_id" form:"parent_id" binding:"omitempty"`
+ Category *uint64 `json:"category" form:"category" binding:"omitempty"`
+ ParentId *uint64 `json:"parent_id" form:"parent_id" binding:"omitempty"`
Accessibility int `json:"accessibility" form:"accessibility" binding:"required"` // 0: Public; 1: Private; 2: Unlisted;
ContentMarkdown *string `json:"content_markdown" form:"content_markdown"`
ContentHtml *string `json:"content_html" form:"content_html"`
- AuthorId int64 `json:"author_id" form:"author_id" binding:"required"`
+ AuthorId uint64 `json:"author_id" form:"author_id" binding:"required"`
CreatedTimestamp int64 `json:"created_timestamp" form:"created_timestamp" binding:"omitempty"`
UpdatedTimestamp int64 `json:"updated_timestamp" form:"updated_timestamp" binding:"omitempty"`
}
diff --git a/backend/models/log.model.go b/backend/models/log.model.go
index c423143e..0c5f68ce 100644
--- a/backend/models/log.model.go
+++ b/backend/models/log.model.go
@@ -1,8 +1,8 @@
package models
type Log struct {
- Id int64 `json:"id"`
- UserId int64 `json:"user_id"`
+ Id uint64 `json:"id"`
+ UserId uint64 `json:"user_id"`
IpAddr string `json:"ip_address"`
UserAgent string `json:"user_agent"`
Location string `json:"location"`
diff --git a/backend/models/ressource.model.go b/backend/models/ressource.model.go
index b06fcc7e..8da18e1e 100644
--- a/backend/models/ressource.model.go
+++ b/backend/models/ressource.model.go
@@ -1,12 +1,12 @@
package models
type Ressource struct {
- Id int64 `json:"id" form:"id" binding:"omitempty"`
+ Id uint64 `json:"id" form:"id" binding:"omitempty"`
Filename string `json:"filename" form:"filename" binding:"required,max=50"`
Filesize int64 `json:"filesize" form:"filesize" binding:"omitempty"`
Filetype string `json:"filetype" form:"filetype" binding:"omitempty"`
OriginalPath string `json:"original_path" form:"original_path" binding:"omitempty"`
TransformedPath string `json:"transformed_path" form:"transformed_path" binding:"omitempty"`
- AuthorId int64 `json:"author_id" form:"author_id" binding:"omitempty"`
+ AuthorId uint64 `json:"author_id" form:"author_id" binding:"omitempty"`
CreatedTimestamp int64 `json:"created_timestamp" form:"created_timestamp" binding:"omitempty"`
}
diff --git a/backend/models/session.model.go b/backend/models/session.model.go
index b8254a65..f8fda101 100644
--- a/backend/models/session.model.go
+++ b/backend/models/session.model.go
@@ -1,8 +1,8 @@
package models
type Session struct {
- Id int64 `json:"id"`
- UserId int64 `json:"user_id"`
+ Id uint64 `json:"id"`
+ UserId uint64 `json:"user_id"`
RefreshToken string `json:"refresh_token"`
ExpireToken int64 `json:"expire_token"`
LastRefreshTimestamp int64 `json:"last_refresh_timestamp"`
diff --git a/backend/models/user.model.go b/backend/models/user.model.go
index ac01fb75..002e6a96 100644
--- a/backend/models/user.model.go
+++ b/backend/models/user.model.go
@@ -1,7 +1,7 @@
package models
type User struct {
- Id int64 `json:"id" form:"id" binding:"omitempty"`
+ Id uint64 `json:"id" form:"id" binding:"omitempty"`
Username string `json:"username" form:"username" binding:"required,min=5,max=30"`
Firstname *string `json:"firstname" form:"firstname" binding:"omitempty"`
Lastname *string `json:"lastname" form:"lastname" binding:"omitempty"`
diff --git a/backend/services/category.service.go b/backend/services/category.service.go
index 348f46c9..c11ad177 100644
--- a/backend/services/category.service.go
+++ b/backend/services/category.service.go
@@ -6,14 +6,14 @@ import (
)
type CategoryService interface {
- GetAllCategories(userId int64) ([]*models.Category, error)
+ GetAllCategories(userId uint64) ([]*models.Category, error)
}
func NewCategoryService(db *sql.DB) CategoryService {
return &Service{db: db}
}
-func (s *Service) GetAllCategories(userId int64) ([]*models.Category, error) {
+func (s *Service) GetAllCategories(userId uint64) ([]*models.Category, error) {
var categories []*models.Category
rows, err := s.db.Query("SELECT * FROM categories WHERE author_id = ? ORDER BY `order`", userId)
if err != nil {
diff --git a/backend/services/document.service.go b/backend/services/document.service.go
index 6f140810..21636525 100644
--- a/backend/services/document.service.go
+++ b/backend/services/document.service.go
@@ -6,14 +6,14 @@ import (
)
type DocumentService interface {
- GetAllDocuments(userId int64) ([]*models.Document, error)
+ GetAllDocuments(userId uint64) ([]*models.Document, error)
}
func NewDocumentService(db *sql.DB) DocumentService {
return &Service{db: db}
}
-func (s *Service) GetAllDocuments(userId int64) ([]*models.Document, error) {
+func (s *Service) GetAllDocuments(userId uint64) ([]*models.Document, error) {
var documents []*models.Document
rows, err := s.db.Query("SELECT id, name, description, tags, category, parent_id, accessibility, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ? ORDER BY name", userId)
if err != nil {
diff --git a/backend/services/log.service.go b/backend/services/log.service.go
index 57aebc22..0b404a9a 100644
--- a/backend/services/log.service.go
+++ b/backend/services/log.service.go
@@ -12,8 +12,8 @@ import (
)
type LogService interface {
- GetConnections(userId int64) ([]*models.Log, error)
- GetLastConnection(userId int64) (*models.Log, error)
+ GetConnections(userId uint64) ([]*models.Log, error)
+ GetLastConnection(userId uint64) (*models.Log, error)
GetLocationFromIp(ip string) string
CreateConnectionLog(log *models.Log) (*models.Log, error)
DeleteOldLogs() error
@@ -25,7 +25,7 @@ func NewLogService(db *sql.DB) LogService {
return &Service{db: db}
}
-func (s *Service) GetConnections(userId int64) ([]*models.Log, error) {
+func (s *Service) GetConnections(userId uint64) ([]*models.Log, error) {
var logs []*models.Log
rows, err := s.db.Query("SELECT * FROM connections_logs WHERE user_id = ?", userId)
if err != nil {
@@ -42,7 +42,7 @@ func (s *Service) GetConnections(userId int64) ([]*models.Log, error) {
return logs, nil
}
-func (s *Service) GetLastConnection(userId int64) (*models.Log, error) {
+func (s *Service) GetLastConnection(userId uint64) (*models.Log, error) {
var log models.Log
err := s.db.QueryRow("SELECT * FROM connections_logs WHERE user_id = ? ORDER BY timestamp DESC LIMIT 1", userId).Scan(&log.Id, &log.IpAddr, &log.Location, &log.Timestamp, &log.Type, &log.UserAgent, &log.UserId)
if err != nil {
diff --git a/backend/services/ressource.service.go b/backend/services/ressource.service.go
index a3b95237..3ff21ee8 100644
--- a/backend/services/ressource.service.go
+++ b/backend/services/ressource.service.go
@@ -6,18 +6,18 @@ import (
)
type RessourceService interface {
- GetAllUploadsByUserId(userId int64) ([]*models.Ressource, error)
- GetRessourceById(id int64) (*models.Ressource, error)
- GetUserUploadsSize(userId int64) (int64, error)
+ GetAllUploadsByUserId(userId uint64) ([]*models.Ressource, error)
+ GetRessourceById(id uint64) (*models.Ressource, error)
+ GetUserUploadsSize(userId uint64) (int64, error)
CreateRessource(ressource *models.Ressource) (*models.Ressource, error)
- DeleteRessource(id int64) error
+ DeleteRessource(id uint64) error
}
func NewRessourceService(db *sql.DB) RessourceService {
return &Service{db: db}
}
-func (s *Service) GetAllUploadsByUserId(userId int64) ([]*models.Ressource, error) {
+func (s *Service) GetAllUploadsByUserId(userId uint64) ([]*models.Ressource, error) {
var ressources []*models.Ressource
rows, err := s.db.Query("SELECT * from ressources WHERE author_id = ?", userId)
if err != nil {
@@ -35,7 +35,7 @@ func (s *Service) GetAllUploadsByUserId(userId int64) ([]*models.Ressource, erro
return ressources, nil
}
-func (s *Service) GetRessourceById(id int64) (*models.Ressource, error) {
+func (s *Service) GetRessourceById(id uint64) (*models.Ressource, error) {
var ressource models.Ressource
err := s.db.QueryRow("SELECT * FROM ressources WHERE id = ?", id).Scan(&ressource.Id, &ressource.Filename, &ressource.Filesize, &ressource.Filetype, &ressource.OriginalPath, &ressource.TransformedPath, &ressource.AuthorId, &ressource.CreatedTimestamp)
if err != nil {
@@ -44,7 +44,7 @@ func (s *Service) GetRessourceById(id int64) (*models.Ressource, error) {
return &ressource, nil
}
-func (s *Service) GetUserUploadsSize(userId int64) (int64, error) {
+func (s *Service) GetUserUploadsSize(userId uint64) (int64, error) {
var totalSize *int64
err := s.db.QueryRow("SELECT SUM(file_size) FROM ressources WHERE author_id = ?", userId).Scan(&totalSize)
if err != nil {
@@ -64,7 +64,7 @@ func (s *Service) CreateRessource(ressource *models.Ressource) (*models.Ressourc
return ressource, nil
}
-func (s *Service) DeleteRessource(id int64) error {
+func (s *Service) DeleteRessource(id uint64) error {
_, err := s.db.Exec("DELETE FROM ressources WHERE id = ?", id)
return err
}
diff --git a/backend/services/session.service.go b/backend/services/session.service.go
index bab4ba17..eb89c74a 100644
--- a/backend/services/session.service.go
+++ b/backend/services/session.service.go
@@ -10,7 +10,7 @@ type AuthService interface {
CreateSession(session *models.Session) (*models.Session, error)
GetSession(refreshToken string) (models.Session, error)
UpdateSession(session *models.Session) (*models.Session, error)
- DeleteSession(id int64) error
+ DeleteSession(id uint64) error
DeleteOldSessions() error
}
@@ -44,7 +44,7 @@ func (s *Service) UpdateSession(session *models.Session) (*models.Session, error
return session, nil
}
-func (s *Service) DeleteSession(id int64) error {
+func (s *Service) DeleteSession(id uint64) error {
_, err := s.db.Exec("DELETE FROM sessions WHERE id = ?", id)
if err != nil {
return err
diff --git a/backend/services/user.service.go b/backend/services/user.service.go
index 3ca6a80d..fa0e146e 100644
--- a/backend/services/user.service.go
+++ b/backend/services/user.service.go
@@ -7,13 +7,13 @@ import (
type UserService interface {
GetAllUsers() ([]*models.User, error)
- GetUserById(id int64) (*models.User, error)
+ GetUserById(id uint64) (*models.User, error)
GetUserByUsername(username string) (*models.User, error)
CheckUsernameExists(username string) bool
CreateUser(user *models.User) (*models.User, error)
- UpdateUser(id int64, user *models.User) (*models.User, error)
- UpdatePassword(id int64, password string) error
- DeleteUser(id int64) error
+ UpdateUser(id uint64, user *models.User) (*models.User, error)
+ UpdatePassword(id uint64, password string) error
+ DeleteUser(id uint64) error
}
func NewUserService(db *sql.DB) UserService {
@@ -72,7 +72,7 @@ func (s *Service) GetUserByUsername(username string) (*models.User, error) {
return &user, nil
}
-func (s *Service) GetUserById(id int64) (*models.User, error) {
+func (s *Service) GetUserById(id uint64) (*models.User, error) {
var user models.User
err := s.db.QueryRow("SELECT id, username, firstname, lastname, role, avatar, email, created_timestamp, updated_timestamp FROM users WHERE id = ?", id).Scan(
&user.Id, &user.Username, &user.Firstname, &user.Lastname,
@@ -86,7 +86,7 @@ func (s *Service) GetUserById(id int64) (*models.User, error) {
return &user, nil
}
-func (s *Service) UpdateUser(id int64, user *models.User) (*models.User, error) {
+func (s *Service) UpdateUser(id uint64, user *models.User) (*models.User, error) {
_, err := s.db.Exec("UPDATE users SET username=?, firstname=?, lastname=?, role=?, avatar=?, email=?, updated_timestamp=? WHERE id=?",
user.Username, user.Firstname, user.Lastname, user.Role, user.Avatar, user.Email, user.UpdatedTimestamp, id)
if err != nil {
@@ -95,12 +95,12 @@ func (s *Service) UpdateUser(id int64, user *models.User) (*models.User, error)
return user, nil
}
-func (s *Service) UpdatePassword(id int64, password string) error {
+func (s *Service) UpdatePassword(id uint64, password string) error {
_, err := s.db.Exec("UPDATE users SET password=? WHERE id=?", password, id)
return err
}
-func (s *Service) DeleteUser(id int64) error {
+func (s *Service) DeleteUser(id uint64) error {
_, err := s.db.Exec("DELETE FROM users WHERE id=?", id)
return err
}
diff --git a/backend/tests/helpers.go b/backend/tests/helpers.go
index ab193d7e..fab41cfc 100644
--- a/backend/tests/helpers.go
+++ b/backend/tests/helpers.go
@@ -18,7 +18,7 @@ const USER_ID = "564704938298982405"
type APIResponse struct {
Status string `json:"status"`
- Timestamp int64 `json:"timestamp"`
+ Timestamp uint64 `json:"timestamp"`
Message string `json:"message,omitempty"`
Result any `json:"result,omitempty"`
StatusCode int
diff --git a/backend/utils/permissions.go b/backend/utils/permissions.go
index ad0a39aa..0c3d70b2 100644
--- a/backend/utils/permissions.go
+++ b/backend/utils/permissions.go
@@ -32,12 +32,12 @@ func CheckUserRequestPermission(ctx *gin.Context, requiredRole int) bool {
return false
}
-func GetUserIdParam(param string, ctx *gin.Context) (int64, error) {
+func GetUserIdParam(param string, ctx *gin.Context) (uint64, error) {
if param == "" {
return 0, errors.New("user ID parameter is empty")
}
if param != "@me" {
- id_param, err := strconv.ParseInt(ctx.Param("id"), 10, 64)
+ id_param, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
if err != nil {
return 0, errors.New("invalid user ID parameter")
}
@@ -46,19 +46,19 @@ func GetUserIdParam(param string, ctx *gin.Context) (int64, error) {
return GetUserIdCtx(ctx)
}
-func GetUserIdCtx(ctx *gin.Context) (int64, error) {
+func GetUserIdCtx(ctx *gin.Context) (uint64, error) {
userId, exists := ctx.Get("user_id")
if !exists {
return 0, errors.New("user ID not found in context")
}
- id, ok := userId.(int64)
+ id, ok := userId.(uint64)
if !ok {
return 0, errors.ErrUnsupported
}
return id, nil
}
-func SelfOrPermission(ctx *gin.Context, allowed int, key ...string) (int64, error) {
+func SelfOrPermission(ctx *gin.Context, allowed int, key ...string) (uint64, error) {
// Check if the c.Param("id") is "@me" or c.Param("id") is the same as the user ID in the context
// If not, check if the user has the required permission
// If one of the above is true, return the user ID from the context
diff --git a/backend/utils/snowflake.go b/backend/utils/snowflake.go
index 9bfe6d11..191c98fc 100644
--- a/backend/utils/snowflake.go
+++ b/backend/utils/snowflake.go
@@ -41,7 +41,7 @@ func NewSnowflake(epoch int64) *Snowflake {
}
// Generate creates a new unique snowflake ID
-func (s *Snowflake) Generate() int64 {
+func (s *Snowflake) Generate() uint64 {
timestamp := time.Now().UnixMilli()
s.mutex.Lock()
defer s.mutex.Unlock()
@@ -58,10 +58,10 @@ func (s *Snowflake) Generate() int64 {
}
}
- return ((timestamp - s.epoch) << timestampShift) |
+ return uint64(((timestamp - s.epoch) << timestampShift) |
(s.workerID << workerIDShift) |
(s.processID << processIDShift) |
- s.increment
+ s.increment)
}
// Deconstruct splits a snowflake ID into its components