public async Task <IActionResult> GetFileInfo(string filename)
        {
            filename = HttpUtility.UrlDecode(filename);

            string resolvedPath = "n/a";

            try
            {
                resolvedPath = await ResolvePath(filename);

                if (!System.IO.File.Exists(resolvedPath))
                {
                    _logger.LogWarning($"[{nameof(GetFileInfo)}] Could not find file {filename} (resolved to {resolvedPath})");
                    return(NotFound(HttpUtility.UrlPathEncode(filename)));
                }

                using CommandConnection connection = await BuildConnection();

                var info = await connection.GetFileInfo(resolvedPath);

                string json = JsonSerializer.Serialize(info, JsonHelper.DefaultJsonOptions);
                return(Content(json, "application/json"));
            }
            catch (Exception e)
            {
                if (e is AggregateException ae)
                {
                    e = ae.InnerException;
                }
                if (e is IncompatibleVersionException)
                {
                    _logger.LogError($"[{nameof(GetFileInfo)}] Incompatible DCS version");
                    return(StatusCode(502, "Incompatible DCS version"));
                }
                if (e is SocketException)
                {
                    _logger.LogError($"[{nameof(GetFileInfo)}] DCS is not started");
                    return(StatusCode(503, "Failed to connect to Duet, please check your connection (DCS is not started)"));
                }
                _logger.LogWarning(e, $"[{nameof(GetFileInfo)}] Failed to retrieve file info for {filename} (resolved to {resolvedPath})");
                return(StatusCode(500, e.Message));
            }
        }
        public async Task <IActionResult> GetFileinfo(string filename)
        {
            filename = HttpUtility.UrlDecode(filename);

            string resolvedPath = "n/a";

            try
            {
                resolvedPath = await ResolvePath(filename);

                if (!System.IO.File.Exists(resolvedPath))
                {
                    _logger.LogWarning($"[{nameof(GetFileinfo)}] Could not find file {filename} (resolved to {resolvedPath})");
                    return(NotFound(HttpUtility.UrlPathEncode(filename)));
                }

                using (CommandConnection connection = await BuildConnection())
                {
                    var info = await connection.GetFileInfo(resolvedPath);

                    string json = JsonConvert.SerializeObject(info, JsonHelper.DefaultSettings);
                    return(Content(json, "application/json"));
                }
            }
            catch (AggregateException ae) when(ae.InnerException is IncompatibleVersionException)
            {
                _logger.LogError($"[{nameof(GetFileinfo)}] Incompatible DCS version");
                return(StatusCode(502, ae.InnerException.Message));
            }
            catch (AggregateException ae) when(ae.InnerException is SocketException)
            {
                _logger.LogError($"[{nameof(GetFileinfo)}] DCS is unavailable");
                return(StatusCode(503, ae.InnerException.Message));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, $"[{nameof(GetFileinfo)}] Failed to retrieve file info for {filename} (resolved to {resolvedPath})");
                return(StatusCode(500, e.Message));
            }
        }