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