Compare commits

..

No commits in common. "419781988aede87258eb06cb702db88c7c591dec" and "e5dcc4b8847b08f0fb6efb8587660a16da5955cd" have entirely different histories.

11 changed files with 55 additions and 60 deletions

View file

@ -2,6 +2,7 @@ package api
import (
"context"
"errors"
"fmt"
"net/http"
"os"
@ -172,7 +173,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, fmt.Errorf("Failed to retrieve session cookie: %v\n", err)
return nil, errors.New(fmt.Sprintf("Failed to retrieve session cookie: %v\n", err))
}
if sessionCookie != nil {
token = sessionCookie.Value
@ -187,7 +188,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, fmt.Errorf("Failed to retrieve session: %v\n", err)
return nil, errors.New(fmt.Sprintf("Failed to retrieve session: %v\n", err))
}
if session != nil {

View file

@ -50,7 +50,7 @@ func HandleImageUpload(app *model.AppState, data *string, directory string, file
return "", nil
}
app.Log.Info(log.TYPE_FILES, "\"%s\" created.", imagePath)
app.Log.Info(log.TYPE_FILES, "\"%s/%s.%s\" created.", directory, filename, ext)
return filename, nil
}

View file

@ -1,7 +1,6 @@
package controller
import (
"embed"
"fmt"
"os"
"time"
@ -9,7 +8,7 @@ import (
"github.com/jmoiron/sqlx"
)
const DB_VERSION int = 5
const DB_VERSION int = 4
func CheckDBVersionAndMigrate(db *sqlx.DB) {
db.MustExec("CREATE SCHEMA IF NOT EXISTS arimelody")
@ -50,23 +49,16 @@ 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 := schemaFS.ReadFile("schema-migration/" + scriptFile + ".sql")
bytes, err := os.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)

View file

@ -2,8 +2,8 @@ package controller
import (
"encoding/base64"
// "image"
// "image/color"
"image"
"image/color"
"github.com/skip2/go-qrcode"
)
@ -18,35 +18,36 @@ 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)
}

View file

@ -1,6 +1,7 @@
package controller
import (
"errors"
"fmt"
"arimelody-web/model"
@ -20,7 +21,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, fmt.Errorf("Credits: %s", err)
return nil, errors.New(fmt.Sprintf("Credits: %s", err))
}
for _, credit := range credits {
release.Credits = append(release.Credits, credit)
@ -29,7 +30,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, fmt.Errorf("Tracks: %s", err)
return nil, errors.New(fmt.Sprintf("Tracks: %s", err))
}
for _, track := range tracks {
release.Tracks = append(release.Tracks, track)
@ -38,7 +39,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, fmt.Errorf("Links: %s", err)
return nil, errors.New(fmt.Sprintf("Links: %s", err))
}
for _, link := range links {
release.Links = append(release.Links, link)
@ -70,7 +71,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, fmt.Errorf("Credits: %s", err)
return nil, errors.New(fmt.Sprintf("Credits: %s", err))
}
for _, credit := range credits {
release.Credits = append(release.Credits, credit)
@ -80,7 +81,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, fmt.Errorf("Tracks: %s", err)
return nil, errors.New(fmt.Sprintf("Tracks: %s", err))
}
for _, track := range tracks {
release.Tracks = append(release.Tracks, track)
@ -89,7 +90,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, fmt.Errorf("Links: %s", err)
return nil, errors.New(fmt.Sprintf("Links: %s", err))
}
for _, link := range links {
release.Links = append(release.Links, link)

View file

@ -1 +0,0 @@
INSERT INTO arimelody.auditlog (level, type, content) VALUES (0, "test", "this is a db schema migration test!");

View file

@ -2,6 +2,7 @@ package controller
import (
"database/sql"
"errors"
"fmt"
"net/http"
"strings"
@ -18,7 +19,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, fmt.Errorf("Failed to retrieve session cookie: %v", err)
return nil, errors.New(fmt.Sprintf("Failed to retrieve session cookie: %v", err))
}
var session *model.Session
@ -28,7 +29,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, fmt.Errorf("Failed to retrieve session: %v", err)
return nil, errors.New(fmt.Sprintf("Failed to retrieve session: %v", err))
}
if session != nil {