Compare commits
4 commits
e5dcc4b884
...
419781988a
Author | SHA1 | Date | |
---|---|---|---|
419781988a | |||
ef655744bb | |||
42c6540ac3 | |||
1999ab7d2c |
11 changed files with 60 additions and 55 deletions
|
@ -2,7 +2,6 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -173,7 +172,7 @@ func getSession(app *model.AppState, r *http.Request) (*model.Session, error) {
|
|||
// check cookies first
|
||||
sessionCookie, err := r.Cookie(model.COOKIE_TOKEN)
|
||||
if err != nil && err != http.ErrNoCookie {
|
||||
return nil, errors.New(fmt.Sprintf("Failed to retrieve session cookie: %v\n", err))
|
||||
return nil, fmt.Errorf("Failed to retrieve session cookie: %v\n", err)
|
||||
}
|
||||
if sessionCookie != nil {
|
||||
token = sessionCookie.Value
|
||||
|
@ -188,7 +187,7 @@ func getSession(app *model.AppState, r *http.Request) (*model.Session, error) {
|
|||
session, err := controller.GetSession(app.DB, token)
|
||||
|
||||
if err != nil && !strings.Contains(err.Error(), "no rows") {
|
||||
return nil, errors.New(fmt.Sprintf("Failed to retrieve session: %v\n", err))
|
||||
return nil, fmt.Errorf("Failed to retrieve session: %v\n", err)
|
||||
}
|
||||
|
||||
if session != nil {
|
||||
|
|
|
@ -50,7 +50,7 @@ func HandleImageUpload(app *model.AppState, data *string, directory string, file
|
|||
return "", nil
|
||||
}
|
||||
|
||||
app.Log.Info(log.TYPE_FILES, "\"%s/%s.%s\" created.", directory, filename, ext)
|
||||
app.Log.Info(log.TYPE_FILES, "\"%s\" created.", imagePath)
|
||||
|
||||
return filename, nil
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
const DB_VERSION int = 4
|
||||
const DB_VERSION int = 5
|
||||
|
||||
func CheckDBVersionAndMigrate(db *sqlx.DB) {
|
||||
db.MustExec("CREATE SCHEMA IF NOT EXISTS arimelody")
|
||||
|
@ -49,16 +50,23 @@ func CheckDBVersionAndMigrate(db *sqlx.DB) {
|
|||
ApplyMigration(db, "003-fail-lock")
|
||||
oldDBVersion = 4
|
||||
|
||||
case 4:
|
||||
ApplyMigration(db, "004-test")
|
||||
oldDBVersion = 5
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Database schema up to date.\n")
|
||||
}
|
||||
|
||||
//go:embed "schema-migration"
|
||||
var schemaFS embed.FS
|
||||
|
||||
func ApplyMigration(db *sqlx.DB, scriptFile string) {
|
||||
fmt.Printf("Applying schema migration %s...\n", scriptFile)
|
||||
|
||||
bytes, err := os.ReadFile("schema-migration/" + scriptFile + ".sql")
|
||||
bytes, err := schemaFS.ReadFile("schema-migration/" + scriptFile + ".sql")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: Failed to open schema file \"%s\": %v\n", scriptFile, err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -2,8 +2,8 @@ package controller
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"image"
|
||||
"image/color"
|
||||
// "image"
|
||||
// "image/color"
|
||||
|
||||
"github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
@ -18,36 +18,35 @@ func GenerateQRCode(data string) (string, error) {
|
|||
}
|
||||
|
||||
// vvv DEPRECATED vvv
|
||||
|
||||
const margin = 4
|
||||
|
||||
type QRCodeECCLevel int64
|
||||
const (
|
||||
LOW QRCodeECCLevel = iota
|
||||
MEDIUM
|
||||
QUARTILE
|
||||
HIGH
|
||||
)
|
||||
|
||||
func drawLargeAlignmentSquare(x int, y int, img *image.Gray) {
|
||||
for yi := range 7 {
|
||||
for xi := range 7 {
|
||||
if (xi == 0 || xi == 6) || (yi == 0 || yi == 6) {
|
||||
img.Set(x + xi, y + yi, color.Black)
|
||||
} else if (xi > 1 && xi < 5) && (yi > 1 && yi < 5) {
|
||||
img.Set(x + xi, y + yi, color.Black)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func drawSmallAlignmentSquare(x int, y int, img *image.Gray) {
|
||||
for yi := range 5 {
|
||||
for xi := range 5 {
|
||||
if (xi == 0 || xi == 4) || (yi == 0 || yi == 4) {
|
||||
img.Set(x + xi, y + yi, color.Black)
|
||||
}
|
||||
}
|
||||
}
|
||||
img.Set(x + 2, y + 2, color.Black)
|
||||
}
|
||||
// const margin = 4
|
||||
//
|
||||
// type QRCodeECCLevel int64
|
||||
// const (
|
||||
// LOW QRCodeECCLevel = iota
|
||||
// MEDIUM
|
||||
// QUARTILE
|
||||
// HIGH
|
||||
// )
|
||||
//
|
||||
// func drawLargeAlignmentSquare(x int, y int, img *image.Gray) {
|
||||
// for yi := range 7 {
|
||||
// for xi := range 7 {
|
||||
// if (xi == 0 || xi == 6) || (yi == 0 || yi == 6) {
|
||||
// img.Set(x + xi, y + yi, color.Black)
|
||||
// } else if (xi > 1 && xi < 5) && (yi > 1 && yi < 5) {
|
||||
// img.Set(x + xi, y + yi, color.Black)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func drawSmallAlignmentSquare(x int, y int, img *image.Gray) {
|
||||
// for yi := range 5 {
|
||||
// for xi := range 5 {
|
||||
// if (xi == 0 || xi == 4) || (yi == 0 || yi == 4) {
|
||||
// img.Set(x + xi, y + yi, color.Black)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// img.Set(x + 2, y + 2, color.Black)
|
||||
// }
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"arimelody-web/model"
|
||||
|
@ -21,7 +20,7 @@ func GetRelease(db *sqlx.DB, id string, full bool) (*model.Release, error) {
|
|||
// get credits
|
||||
credits, err := GetReleaseCredits(db, id)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Credits: %s", err))
|
||||
return nil, fmt.Errorf("Credits: %s", err)
|
||||
}
|
||||
for _, credit := range credits {
|
||||
release.Credits = append(release.Credits, credit)
|
||||
|
@ -30,7 +29,7 @@ func GetRelease(db *sqlx.DB, id string, full bool) (*model.Release, error) {
|
|||
// get tracks
|
||||
tracks, err := GetReleaseTracks(db, id)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Tracks: %s", err))
|
||||
return nil, fmt.Errorf("Tracks: %s", err)
|
||||
}
|
||||
for _, track := range tracks {
|
||||
release.Tracks = append(release.Tracks, track)
|
||||
|
@ -39,7 +38,7 @@ func GetRelease(db *sqlx.DB, id string, full bool) (*model.Release, error) {
|
|||
// get links
|
||||
links, err := GetReleaseLinks(db, id)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Links: %s", err))
|
||||
return nil, fmt.Errorf("Links: %s", err)
|
||||
}
|
||||
for _, link := range links {
|
||||
release.Links = append(release.Links, link)
|
||||
|
@ -71,7 +70,7 @@ func GetAllReleases(db *sqlx.DB, onlyVisible bool, limit int, full bool) ([]*mod
|
|||
// get credits
|
||||
credits, err := GetReleaseCredits(db, release.ID)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Credits: %s", err))
|
||||
return nil, fmt.Errorf("Credits: %s", err)
|
||||
}
|
||||
for _, credit := range credits {
|
||||
release.Credits = append(release.Credits, credit)
|
||||
|
@ -81,7 +80,7 @@ func GetAllReleases(db *sqlx.DB, onlyVisible bool, limit int, full bool) ([]*mod
|
|||
// get tracks
|
||||
tracks, err := GetReleaseTracks(db, release.ID)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Tracks: %s", err))
|
||||
return nil, fmt.Errorf("Tracks: %s", err)
|
||||
}
|
||||
for _, track := range tracks {
|
||||
release.Tracks = append(release.Tracks, track)
|
||||
|
@ -90,7 +89,7 @@ func GetAllReleases(db *sqlx.DB, onlyVisible bool, limit int, full bool) ([]*mod
|
|||
// get links
|
||||
links, err := GetReleaseLinks(db, release.ID)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Links: %s", err))
|
||||
return nil, fmt.Errorf("Links: %s", err)
|
||||
}
|
||||
for _, link := range links {
|
||||
release.Links = append(release.Links, link)
|
||||
|
|
1
controller/schema-migration/004-test.sql
Normal file
1
controller/schema-migration/004-test.sql
Normal file
|
@ -0,0 +1 @@
|
|||
INSERT INTO arimelody.auditlog (level, type, content) VALUES (0, "test", "this is a db schema migration test!");
|
|
@ -2,7 +2,6 @@ package controller
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -19,7 +18,7 @@ const TOKEN_LEN = 64
|
|||
func GetSessionFromRequest(app *model.AppState, r *http.Request) (*model.Session, error) {
|
||||
sessionCookie, err := r.Cookie(model.COOKIE_TOKEN)
|
||||
if err != nil && err != http.ErrNoCookie {
|
||||
return nil, errors.New(fmt.Sprintf("Failed to retrieve session cookie: %v", err))
|
||||
return nil, fmt.Errorf("Failed to retrieve session cookie: %v", err)
|
||||
}
|
||||
|
||||
var session *model.Session
|
||||
|
@ -29,7 +28,7 @@ func GetSessionFromRequest(app *model.AppState, r *http.Request) (*model.Session
|
|||
session, err = GetSession(app.DB, sessionCookie.Value)
|
||||
|
||||
if err != nil && !strings.Contains(err.Error(), "no rows") {
|
||||
return nil, errors.New(fmt.Sprintf("Failed to retrieve session: %v", err))
|
||||
return nil, fmt.Errorf("Failed to retrieve session: %v", err)
|
||||
}
|
||||
|
||||
if session != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue