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>
This commit is contained in:
parent
b5701b5a4d
commit
1fcde736a8
6 changed files with 9 additions and 9 deletions
|
@ -36,7 +36,7 @@ type NotePayload struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type NoteResponse struct {
|
type NoteResponse struct {
|
||||||
ID string `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ func handleMain() int {
|
||||||
|
|
||||||
logger.Debug("finding note location")
|
logger.Debug("finding note location")
|
||||||
var location string
|
var location string
|
||||||
noteURL := *url + "/" + jsonBody.ID
|
noteURL := *url + "/" + fmt.Sprintf("%d", jsonBody.ID)
|
||||||
if *copier {
|
if *copier {
|
||||||
location = "copier"
|
location = "copier"
|
||||||
if *encryptionKey != "" {
|
if *encryptionKey != "" {
|
||||||
|
|
|
@ -64,7 +64,7 @@ Body (JSON):
|
||||||
* **language** (string): language of the note (must be supported by the server)
|
* **language** (string): language of the note (must be supported by the server)
|
||||||
|
|
||||||
Response (JSON):
|
Response (JSON):
|
||||||
* **id** (string): ID of the note
|
* **id** (int): ID of the note
|
||||||
|
|
||||||
|
|
||||||
### GET /api/note/\<id\>/\<encryptionKey\>
|
### GET /api/note/\<id\>/\<encryptionKey\>
|
||||||
|
|
|
@ -112,7 +112,7 @@ func (d *Database) Get(id string) (*Note, error) {
|
||||||
d.logger.Warn("could not find note", slog.Any("error", trx.Error))
|
d.logger.Warn("could not find note", slog.Any("error", trx.Error))
|
||||||
return nil, trx.Error
|
return nil, trx.Error
|
||||||
}
|
}
|
||||||
if note.ID != "" {
|
if note.ID != 0 {
|
||||||
if note.DeleteAfterRead {
|
if note.DeleteAfterRead {
|
||||||
if err := d.Delete(note.ID); err != nil {
|
if err := d.Delete(note.ID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -142,7 +142,7 @@ func (d *Database) Create(content []byte, password string, encryptionKey string,
|
||||||
}
|
}
|
||||||
|
|
||||||
note = &Note{
|
note = &Note{
|
||||||
ID: d.node.Generate().String(),
|
ID: d.node.Generate().Int64(),
|
||||||
Content: content,
|
Content: content,
|
||||||
ExpiresAt: time.Now().Add(time.Duration(expiration) * time.Second),
|
ExpiresAt: time.Now().Add(time.Duration(expiration) * time.Second),
|
||||||
Encrypted: encrypted,
|
Encrypted: encrypted,
|
||||||
|
@ -179,7 +179,7 @@ func (d *Database) Create(content []byte, password string, encryptionKey string,
|
||||||
return note, nil
|
return note, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) Delete(id string) error {
|
func (d *Database) Delete(id int64) error {
|
||||||
trx := d.db.Where("id = ?", id).Delete(&Note{})
|
trx := d.db.Where("id = ?", id).Delete(&Note{})
|
||||||
defer trx.Commit()
|
defer trx.Commit()
|
||||||
if trx.Error != nil {
|
if trx.Error != nil {
|
||||||
|
|
|
@ -35,7 +35,7 @@ type CreateNotePayload struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateNoteResponse struct {
|
type CreateNoteResponse struct {
|
||||||
ID string `json:"id"`
|
ID int64 `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *CreateNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *CreateNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -160,7 +160,7 @@ func (h *CreateNoteWithFormHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
||||||
scheme = "https://"
|
scheme = "https://"
|
||||||
}
|
}
|
||||||
|
|
||||||
h.PageData.URL = fmt.Sprintf("%s%s/%s", scheme, r.Host, note.ID)
|
h.PageData.URL = fmt.Sprintf("%s%s/%d", scheme, r.Host, note.ID)
|
||||||
if encryptionKey != "" {
|
if encryptionKey != "" {
|
||||||
h.PageData.URL += "/" + encryptionKey
|
h.PageData.URL += "/" + encryptionKey
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Note struct {
|
type Note struct {
|
||||||
ID string `json:"id" gorm:"primaryKey"`
|
ID int64 `json:"id" gorm:"primaryKey"`
|
||||||
Content []byte `json:"content" gorm:"not null"`
|
Content []byte `json:"content" gorm:"not null"`
|
||||||
Encrypted bool `json:"encrypted"`
|
Encrypted bool `json:"encrypted"`
|
||||||
PasswordHash []byte `json:"password_hash"`
|
PasswordHash []byte `json:"password_hash"`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue