diff --git a/README.md b/README.md index bb66083..0e0d4b2 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ that I took in Fall 2017 at UPT. The scope of this project is to implement a simple server that handles multiple clients and allows the clients to execute commands on it. +## Commands + +//todo + ## Configuration The server can be configured via command line flags with the -ConfigPath option, @@ -17,13 +21,25 @@ Sample Configuration File: "address": "localhost", "port": "8080", "maxDirDepth": 30, - "absoluteServePath": "/Users/denis/Dropbox/Pictures/CuteAvatars" + "absoluteServePath": "/Users/denis/Dropbox/Pictures/CuteAvatars", + "pic": { + "x": 0, + "y": 0 + } } ``` The **config.json** file contains the following settings: -Address - The address on which to serve -Port - The port -MaxDirDepth - The maximum depth the user can go into directories. A value of 30 means the user can cd into max 30 dirs. -AbsoluteServePath - The path from where to serve the files. +address - The address on which to serve + +port - The port + +maxDirDepth - The maximum depth the user can go into directories. A value of 30 means the user can cd into max 30 dirs. + +absoluteServePath - The path from where to serve the files. + +pic - The X and Y max size for the pic command. A value of 0 means original size + +If one of the settings are changed, the server will reload the configuration. +Except for the absoluteServePath. \ No newline at end of file diff --git a/server/server/commands.go b/server/server/commands.go index 0477e7b..588096d 100644 --- a/server/server/commands.go +++ b/server/server/commands.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" + "github.com/spf13/viper" "github.com/zyxar/image2ascii/ascii" ) @@ -21,8 +22,8 @@ func SendAsciiPic(c Client, path string) error { } defer f.Close() opt := ascii.Options{ - Width: 0, - Height: 0, + Width: viper.GetInt("pic.x"), + Height: viper.GetInt("pic.y"), Color: false, Invert: false, Flipx: false, diff --git a/server/server/config.go b/server/server/config.go index 107f8ab..84ba379 100644 --- a/server/server/config.go +++ b/server/server/config.go @@ -6,6 +6,7 @@ import ( "flag" + "github.com/fsnotify/fsnotify" "github.com/spf13/viper" ) @@ -31,6 +32,8 @@ func setDefaultConfiguration() { viper.SetDefault("configPath", ConfigPath) viper.SetDefault("maxDirDepth", 30) viper.SetDefault("absoluteServePath", "./") + viper.SetDefault("pic.x", 0) + viper.SetDefault("pic.y", 0) } // InitializedConfiguration initializes the configuration for the application. @@ -39,7 +42,12 @@ func InitializedConfiguration() { flag.Parse() setDefaultConfiguration() - loadConfigFromFile() - BasePath = viper.GetString("AbsoluteServePath") + + viper.WatchConfig() + viper.OnConfigChange(func(e fsnotify.Event) { + log.Println("Reloaded configuration file successfully!") + }) + + BasePath = viper.GetString("absoluteServePath") }