forked from jriou/coller
31 lines
730 B
Go
31 lines
730 B
Go
package server
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Note struct {
|
|
ID string `json:"id" gorm:"primaryKey"`
|
|
Content []byte `json:"content" gorm:"not null"`
|
|
Encrypted bool `json:"encrypted"`
|
|
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
|
|
}
|