private void AppendFlatten(Dir dir, TinfoilIndex tinfoilIndex) { var urlCombiner = _urlCombinerFactory.Create(dir.CorrespondingUrl); var localDirPath = dir.Path; if (!Directory.Exists(localDirPath)) { return; } var filePaths = Directory.GetFiles(localDirPath, "*.*", SearchOption.AllDirectories); foreach (var filePath in filePaths) { if (!_fileFilter.IsFileAllowed(filePath)) { continue; } var relFilePath = filePath[localDirPath.Length..]; // SubString from dirPath.Length to the end
public async Task OnRequest(HttpContext context) { var request = context.Request; var rootUrlCombiner = _urlCombinerFactory.Create(new Uri(context.Request.GetEncodedUrl(), UriKind.Absolute)); var decodedRelPath = request.Path.Value !; // NOTE: good to read this article https://stackoverflow.com/questions/66471763/inconsistent-url-decoding-of-httprequest-path-in-asp-net-core if (string.Equals(decodedRelPath, "/favicon.ico", StringComparison.OrdinalIgnoreCase)) { context.Response.StatusCode = 200; await context.Response.Body.WriteAsync(Resources.Favicon); return; } var physicalPath = _physicalPathConverter.Convert(decodedRelPath, out var isRoot); if (isRoot) { var dirs = _servedDirAliasMap.Select(dirWithAlias => new Dir { Path = dirWithAlias.DirPath, CorrespondingUrl = rootUrlCombiner.CombineLocalPath(dirWithAlias.Alias) }).ToArray(); var tinfoilIndex = _cachedTinfoilIndexBuilder.Build(decodedRelPath, dirs, _appSettings.IndexType, _appSettings.MessageOfTheDay); var json = _jsonSerializer.Serialize(tinfoilIndex); context.Response.StatusCode = 200; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(json, Encoding.UTF8); } else if (Directory.Exists(physicalPath) && request.Method == "GET" || request.Method == "HEAD") { var tinfoilIndex = _cachedTinfoilIndexBuilder.Build(decodedRelPath, new[] { new Dir