Base Flutter Project
This commit is contained in:
21
internal/config/config.go
Normal file
21
internal/config/config.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"reichard.io/imagini/internal/db"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
db *gorm.DB
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
func NewConfig() {
|
||||
loadedSettings := loadSettings()
|
||||
loadedDB := db.OpenDB(&loadedSettings)
|
||||
newConfig := &Config {
|
||||
settings: &loadedSettings,
|
||||
db: &loadedDB,
|
||||
}
|
||||
}
|
||||
32
internal/config/settings.go
Normal file
32
internal/config/settings.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
DBType string
|
||||
DBName string
|
||||
DBPassword string
|
||||
DataPath string
|
||||
ConfigPath string
|
||||
JWTSecret string
|
||||
}
|
||||
|
||||
func loadSettings() *Settings {
|
||||
return &Settings{
|
||||
DBType: getEnv("DATABASE_TYPE", "SQLite"),
|
||||
DBName: getEnv("DATABASE_NAME", "imagini"),
|
||||
DBPassword: getEnv("DATABASE_PASSWORD", ""),
|
||||
ConfigPath: getEnv("CONFIG_PATH", "/config"),
|
||||
DataPath: getEnv("DATA_PATH", "/data"),
|
||||
JWTSecret: getEnv("JWT_SECRET", "58b9340c0472cf045db226bc445966524e780cd38bc3dd707afce80c95d4de6f"),
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if value, ok := os.LookupEnv(key); ok {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
40
internal/db/db.go
Normal file
40
internal/db/db.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func OpenDB(data) *gorm.DB {
|
||||
database, _ := gorm.Open(sqlite.Open("./db/imagini.db"), &gorm.Config{
|
||||
PrepareStmt: true,
|
||||
})
|
||||
|
||||
// Initialize Database
|
||||
database.AutoMigrate(&ServerSetting{})
|
||||
database.AutoMigrate(&User{})
|
||||
database.AutoMigrate(&MediaItem{})
|
||||
database.AutoMigrate(&Tag{})
|
||||
database.AutoMigrate(&Album{})
|
||||
|
||||
return database
|
||||
}
|
||||
|
||||
func ItemsFromAlbum(userID int, albumID int) []MediaItem {
|
||||
database, _ := gorm.Open(sqlite.Open("./db/imagini.db"), &gorm.Config{})
|
||||
database.Raw(`
|
||||
SELECT
|
||||
MediaItems.*
|
||||
FROM
|
||||
MediaAlbums
|
||||
INNER JOIN MediaItems ON MediaAlbums.mediaID = MediaItems.mediaID
|
||||
WHERE MediaAlbums.albumID = ? AND MediaItems.userID = ?`, albumID, userID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func ItemsFromTags(userID int, tagID int) []MediaItem {
|
||||
return nil
|
||||
}
|
||||
|
||||
func IndexMediaItems(newItems []MediaItem) {
|
||||
}
|
||||
45
internal/db/models.go
Normal file
45
internal/db/models.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ServerSetting struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
Description string
|
||||
Value string
|
||||
}
|
||||
|
||||
type User struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
Email string
|
||||
AuthType string
|
||||
Salt string
|
||||
HashedPWSalt string
|
||||
MediaItems []MediaItem
|
||||
}
|
||||
|
||||
type MediaItem struct {
|
||||
gorm.Model
|
||||
User User
|
||||
EXIFDate time.Time
|
||||
Latitude string
|
||||
Longitude string
|
||||
MediaType uint
|
||||
RelPath string
|
||||
Tags []Tag `gorm:"many2many:media_tags;"`
|
||||
Albums []Album `gorm:"many2many:media_albums;"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
}
|
||||
|
||||
type Album struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
}
|
||||
9
internal/sessions/sessions.go
Normal file
9
internal/sessions/sessions.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user