All checks were successful
/ pre-commit (push) Successful in 1m33s
Snowflake identifiers are integers, not strings. BREAKING CHANGE: notes that are not using snowflake identifiers will not be compatible anymore. Signed-off-by: Julien Riou <julien@riou.xyz>
32 lines
780 B
Go
32 lines
780 B
Go
package server
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Note struct {
|
|
ID int64 `json:"id" gorm:"primaryKey"`
|
|
Content []byte `json:"content" gorm:"not null"`
|
|
Encrypted bool `json:"encrypted"`
|
|
PasswordHash []byte `json:"password_hash"`
|
|
ExpiresAt time.Time `json:"expires_at" gorm:"index"`
|
|
DeleteAfterRead bool `json:"delete_after_read"`
|
|
Language string `json:"language"`
|
|
}
|
|
|
|
// Compress content before saving to the database
|
|
func (n *Note) BeforeCreate(trx *gorm.DB) (err error) {
|
|
n.Content = Compress(n.Content)
|
|
return nil
|
|
}
|
|
|
|
// Decompress content from the database
|
|
func (n *Note) AfterFind(tx *gorm.DB) (err error) {
|
|
n.Content, err = Decompress(n.Content)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|