Reorganized server assets directory and config; added --debug flag

This commit is contained in:
Michael Mayer 2018-09-13 11:34:56 +02:00
parent b881bbcf17
commit 37912b4b99
15 changed files with 87 additions and 49 deletions

View file

@ -1,4 +1,3 @@
photos/
frontend/node_modules/*
vendor/
server/assets/build/*
server/assets/public/build/*

View file

@ -27,12 +27,14 @@ func main() {
conf.SetValuesFromCliContext(context)
fmt.Printf("NAME VALUE\n")
fmt.Printf("debug %t\n", conf.Debug)
fmt.Printf("config-file %s\n", conf.ConfigFile)
fmt.Printf("darktable-cli %s\n", conf.DarktableCli)
fmt.Printf("originals-path %s\n", conf.OriginalsPath)
fmt.Printf("thumbnails-path %s\n", conf.ThumbnailsPath)
fmt.Printf("import-path %s\n", conf.ImportPath)
fmt.Printf("export-path %s\n", conf.ExportPath)
fmt.Printf("server-assets-path %s\n", conf.ServerAssetsPath)
return nil
},
@ -51,6 +53,11 @@ func main() {
Usage: "HTTP server IP address (optional)",
Value: "",
},
cli.StringFlag{
Name: "mode, m",
Usage: "debug, release or test",
Value: "",
},
},
Action: func(context *cli.Context) error {
conf.SetValuesFromFile(photoprism.GetExpandedFilename(context.GlobalString("config-file")))
@ -63,7 +70,7 @@ func main() {
fmt.Printf("Starting web server at port %d...\n", context.Int("port"))
server.Start(context.String("ip"), context.Int("port"), conf)
server.Start(context.String("ip"), context.Int("port"), context.String("mode"), conf)
fmt.Println("Done.")
@ -274,6 +281,10 @@ func main() {
}
var globalCliFlags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "run in debug mode",
},
cli.StringFlag{
Name: "config-file, c",
Usage: "config filename",
@ -289,6 +300,11 @@ var globalCliFlags = []cli.Flag{
Usage: "originals path",
Value: "~/Photos/Originals",
},
cli.StringFlag{
Name: "thumbnails-path",
Usage: "thumbnails path",
Value: "~/Photos/Thumbnails",
},
cli.StringFlag{
Name: "import-path",
Usage: "import path",
@ -300,9 +316,9 @@ var globalCliFlags = []cli.Flag{
Value: "~/Photos/Export",
},
cli.StringFlag{
Name: "thumbnails-path",
Usage: "thumbnails path",
Value: "~/Photos/Thumbnails",
Name: "server-assets-path",
Usage: "server assets path for templates, js and css",
Value: "~/Photos/Server",
},
cli.StringFlag{
Name: "database-driver",

View file

@ -3,5 +3,6 @@ originals-path: photos/originals
thumbnails-path: photos/thumbnails
import-path: photos/import
export-path: photos/export
server-assets-path: server/assets
database-driver: mysql
database-dsn: photoprism:photoprism@tcp(database:3306)/photoprism?parseTime=true

View file

@ -15,15 +15,17 @@ import (
)
type Config struct {
ConfigFile string
DarktableCli string
OriginalsPath string
ThumbnailsPath string
ImportPath string
ExportPath string
DatabaseDriver string
DatabaseDsn string
db *gorm.DB
Debug bool
ConfigFile string
DarktableCli string
OriginalsPath string
ThumbnailsPath string
ImportPath string
ExportPath string
ServerAssetsPath string
DatabaseDriver string
DatabaseDsn string
db *gorm.DB
}
type ConfigValues map[string]interface{}
@ -57,6 +59,10 @@ func (c *Config) SetValuesFromFile(fileName string) error {
c.ExportPath = GetExpandedFilename(ExportPath)
}
if ServerAssetsPath, err := yamlConfig.Get("server-assets-path"); err == nil {
c.ServerAssetsPath = GetExpandedFilename(ServerAssetsPath)
}
if DarktableCli, err := yamlConfig.Get("darktable-cli"); err == nil {
c.DarktableCli = GetExpandedFilename(DarktableCli)
}
@ -73,32 +79,38 @@ func (c *Config) SetValuesFromFile(fileName string) error {
}
func (c *Config) SetValuesFromCliContext(context *cli.Context) error {
if context.IsSet("originals-path") {
c.OriginalsPath = GetExpandedFilename(context.String("originals-path"))
c.Debug = context.GlobalBool("debug")
if context.GlobalIsSet("originals-path") {
c.OriginalsPath = GetExpandedFilename(context.GlobalString("originals-path"))
}
if context.IsSet("thumbnails-path") {
c.ThumbnailsPath = GetExpandedFilename(context.String("thumbnails-path"))
if context.GlobalIsSet("thumbnails-path") {
c.ThumbnailsPath = GetExpandedFilename(context.GlobalString("thumbnails-path"))
}
if context.IsSet("import-path") {
c.ImportPath = GetExpandedFilename(context.String("import-path"))
if context.GlobalIsSet("import-path") {
c.ImportPath = GetExpandedFilename(context.GlobalString("import-path"))
}
if context.IsSet("export-path") {
c.ExportPath = GetExpandedFilename(context.String("export-path"))
if context.GlobalIsSet("export-path") {
c.ExportPath = GetExpandedFilename(context.GlobalString("export-path"))
}
if context.IsSet("darktable-cli") {
c.DarktableCli = GetExpandedFilename(context.String("darktable-cli"))
if context.GlobalIsSet("server-assets-path") {
c.ServerAssetsPath = GetExpandedFilename(context.GlobalString("server-assets-path"))
}
if context.IsSet("database-driver") {
c.DatabaseDriver = context.String("database-driver")
if context.GlobalIsSet("darktable-cli") {
c.DarktableCli = GetExpandedFilename(context.GlobalString("darktable-cli"))
}
if context.IsSet("database-dsn") {
c.DatabaseDsn = context.String("database-dsn")
if context.GlobalIsSet("database-driver") {
c.DatabaseDriver = context.GlobalString("database-driver")
}
if context.GlobalIsSet("database-dsn") {
c.DatabaseDsn = context.GlobalString("database-dsn")
}
return nil
@ -163,7 +175,7 @@ func (c *Config) GetClientConfig() ConfigValues {
result := ConfigValues{
"title": "PhotoPrism",
"debug": true,
"debug": c.Debug,
"cameras": cameras,
}

View file

@ -18,6 +18,7 @@ var originalsPath = GetExpandedFilename(testDataPath + "/originals")
var thumbnailsPath = GetExpandedFilename(testDataPath + "/thumbnails")
var importPath = GetExpandedFilename(testDataPath + "/import")
var exportPath = GetExpandedFilename(testDataPath + "/export")
var serverAssetsPath = GetExpandedFilename("server/assets")
var databaseDriver = "mysql"
var databaseDsn = "photoprism:photoprism@tcp(database:3306)/photoprism?parseTime=true"
@ -65,13 +66,15 @@ func (c *Config) InitializeTestData(t *testing.T) {
func NewTestConfig() *Config {
return &Config{
DarktableCli: darktableCli,
OriginalsPath: originalsPath,
ThumbnailsPath: thumbnailsPath,
ImportPath: importPath,
ExportPath: exportPath,
DatabaseDriver: databaseDriver,
DatabaseDsn: databaseDsn,
Debug: false,
DarktableCli: darktableCli,
OriginalsPath: originalsPath,
ThumbnailsPath: thumbnailsPath,
ImportPath: importPath,
ExportPath: exportPath,
ServerAssetsPath: serverAssetsPath,
DatabaseDriver: databaseDriver,
DatabaseDsn: databaseDsn,
}
}
@ -90,6 +93,7 @@ func TestConfig_SetValuesFromFile(t *testing.T) {
assert.Equal(t, GetExpandedFilename("photos/thumbnails"), c.ThumbnailsPath)
assert.Equal(t, GetExpandedFilename("photos/import"), c.ImportPath)
assert.Equal(t, GetExpandedFilename("photos/export"), c.ExportPath)
assert.Equal(t, GetExpandedFilename("server/assets"), c.ServerAssetsPath)
assert.Equal(t, databaseDriver, c.DatabaseDriver)
assert.Equal(t, databaseDsn, c.DatabaseDsn)
}

View file

@ -5,7 +5,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
const PATHS = {
app: path.join(__dirname, 'src/app.js'),
css: path.join(__dirname, 'css'),
build: path.join(__dirname, '../server/assets/build'),
build: path.join(__dirname, '../server/assets/public/build'),
};
const cssPlugin = new ExtractTextPlugin({

View file

@ -38,9 +38,9 @@ func TestMediaFile_GetEditedFilename(t *testing.T) {
conf.InitializeTestData(t)
mediaFile1, err := NewMediaFile(conf.ImportPath + "/iphone/IMG_6788.jpg")
mediaFile1, err := NewMediaFile(conf.ImportPath + "/iphone/IMG_6788.JPG")
assert.Nil(t, err)
assert.Equal(t, conf.ImportPath+"/iphone/IMG_E6788.jpg", mediaFile1.GetEditedFilename())
assert.Equal(t, conf.ImportPath+"/iphone/IMG_E6788.JPG", mediaFile1.GetEditedFilename())
/* TODO: Add example files to import.zip
mediaFile2, err := NewMediaFile("/foo/bar/IMG_E1234.jpg")

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 KiB

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -1,3 +0,0 @@
# robotstxt.org/
User-agent: *

View file

@ -7,8 +7,9 @@
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="apple-touch-icon" href="/favicon.png">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="icon" type="image/png" href="/favicon.png" />
<link rel="stylesheet" href="/assets/build/app.css">

View file

@ -10,11 +10,13 @@ import (
)
func ConfigureRoutes(app *gin.Engine, conf *photoprism.Config) {
app.LoadHTMLGlob("server/templates/*")
serverAssetsPath := conf.ServerAssetsPath
app.LoadHTMLGlob(serverAssetsPath + "/templates/*")
app.StaticFile("/favicon.ico", "./server/assets/favicon.ico")
app.StaticFile("/robots.txt", "./server/assets/robots.txt")
app.Static("/assets", "./server/assets")
app.StaticFile("/favicon.ico", serverAssetsPath + "/favicons/favicon.ico")
app.StaticFile("/favicon.png", serverAssetsPath + "/favicons/favicon.png")
app.Static("/assets", serverAssetsPath + "/public")
// JSON-REST API Version 1
v1 := app.Group("/api/v1")

View file

@ -6,7 +6,13 @@ import (
"github.com/photoprism/photoprism"
)
func Start(address string, port int, conf *photoprism.Config) {
func Start(address string, port int, mode string, conf *photoprism.Config) {
if mode != "" {
gin.SetMode(mode)
} else if conf.Debug == false{
gin.SetMode(gin.ReleaseMode)
}
app := gin.Default()
ConfigureRoutes(app, conf)