Ejemplo n.º 1
0
        private static Config LoadConfig()
        {
            string musicFolder = Environment.GetEnvironmentVariable("CAMP_MUSIC_FOLDER");
            string localFolder = Environment.GetEnvironmentVariable("CAMP_DATA_FOLDER");
            string jwtSecret   = Environment.GetEnvironmentVariable("CAMP_JWT_SECRET");

            if (string.IsNullOrEmpty(jwtSecret))
            {
                string jwtFile = Path.Combine(localFolder, "jwt.txt");

                if (File.Exists(jwtFile))
                {
                    jwtSecret = File.ReadAllText(jwtFile);
                }
                else
                {
                    jwtSecret = JwtHelper.CreateJwtSecret();
                    File.WriteAllText(jwtFile, jwtSecret);
                }
            }

            var config = new Config
            {
                JwtSecret       = jwtSecret,
                LocalDataFolder = localFolder,
                MusicFolder     = musicFolder,
                PortNumber      = 8000
            };

            string temp = Environment.GetEnvironmentVariable("CAMP_PORT_NUMBER");

            if (!String.IsNullOrEmpty(temp))
            {
                if (int.TryParse(temp, out int result))
                {
                    config.PortNumber = result;
                }
            }

            return(config);
        }