From 490c5207be7064461fa948c8e03795d4bca18a55 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 20 Jun 2018 02:15:42 +0200 Subject: [PATCH] 1.0.5-rc20-alpha9 : ansi2html helper --- Yavsc.Server/Helpers/Ansi2HtmlEncoder.cs | 42 +++++++++++++++++++++++ Yavsc.Server/Yavsc.Server.nuspec | 1 + Yavsc.Server/{Resources => }/ansi2html.sh | 0 Yavsc/Controllers/IT/GitController.cs | 30 ++++++++++++++++ Yavsc/Startup/Startup.FileServer.cs | 19 +++++++--- Yavsc/Yavsc.nuspec | 5 ++- Yavsc/project.json | 4 +-- cli/project.json | 8 ++--- rc-num.txt | 2 +- 9 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 Yavsc.Server/Helpers/Ansi2HtmlEncoder.cs rename Yavsc.Server/{Resources => }/ansi2html.sh (100%) diff --git a/Yavsc.Server/Helpers/Ansi2HtmlEncoder.cs b/Yavsc.Server/Helpers/Ansi2HtmlEncoder.cs new file mode 100644 index 00000000..1939e4c9 --- /dev/null +++ b/Yavsc.Server/Helpers/Ansi2HtmlEncoder.cs @@ -0,0 +1,42 @@ +// // AnsiToHtmlEncoder.cs +// /* +// paul schneider 19/06/2018 15:58 20182018 6 19 +// */ + +using System.IO; +using System.Diagnostics; +namespace Yavsc.Server.Helpers +{ + public static class AnsiToHtmlEncoder + { + public static Stream GetStream(StreamReader reader) + { + var procStart = new ProcessStartInfo("sh", "ansi2html.sh --bg=dark --palette=linux"); + procStart.UseShellExecute = false; + procStart.RedirectStandardInput = true; + procStart.RedirectStandardOutput = true; + var mem = new MemoryStream(); + StreamWriter writer = new StreamWriter(mem); + + var proc = Process.Start(procStart); + while (!reader.EndOfStream && !proc.StandardOutput.EndOfStream) + { + if (!reader.EndOfStream) + proc.StandardInput.WriteLine(reader.ReadLine()); + if (!proc.StandardOutput.EndOfStream) + writer.WriteLine(proc.StandardOutput.ReadLine()); + } + + mem.Seek(0, SeekOrigin.Begin); + return mem; + } + + public static Stream GetStream(Stream inner) + { + using (var reader = new StreamReader(inner)) + { + return GetStream(reader); + } + } + } +} \ No newline at end of file diff --git a/Yavsc.Server/Yavsc.Server.nuspec b/Yavsc.Server/Yavsc.Server.nuspec index 952a8879..8c848e3b 100644 --- a/Yavsc.Server/Yavsc.Server.nuspec +++ b/Yavsc.Server/Yavsc.Server.nuspec @@ -18,6 +18,7 @@ yavsc + diff --git a/Yavsc.Server/Resources/ansi2html.sh b/Yavsc.Server/ansi2html.sh similarity index 100% rename from Yavsc.Server/Resources/ansi2html.sh rename to Yavsc.Server/ansi2html.sh diff --git a/Yavsc/Controllers/IT/GitController.cs b/Yavsc/Controllers/IT/GitController.cs index 18e0629b..8d6ab638 100644 --- a/Yavsc/Controllers/IT/GitController.cs +++ b/Yavsc/Controllers/IT/GitController.cs @@ -1,6 +1,9 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; +using System; +using System.Diagnostics; +using System.IO; using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Rendering; @@ -20,6 +23,32 @@ namespace Yavsc.Controllers _context = context; } + [Route("~/Git/sources/{*path}")] + public IActionResult Sources (string path) + { + if (path == null) + { + return HttpNotFound(); + } + + /* + GitRepositoryReference gitRepositoryReference = await _context.GitRepositoryReference.SingleAsync(m => m.Path == path); + if (gitRepositoryReference == null) + { + return HttpNotFound(); + } + */ + var info = Startup.GitOptions.FileProvider.GetFileInfo(path); + if (!info.Exists) + return HttpNotFound(); + var stream = info.CreateReadStream(); + if (path.EndsWith(".log")) return File(stream,"text/html"); + if (path.EndsWith(".html")) return File(stream,"text/html"); + if (path.EndsWith(".cshtml")) return File(stream,"text/razor-csharp"); + if (path.EndsWith(".cs")) return File(stream,"text/csharp"); + return File(stream,"application/octet-stream"); + } + // GET: Git public async Task Index() { @@ -50,6 +79,7 @@ namespace Yavsc.Controllers return View(); } + // POST: Git/Create [HttpPost] [ValidateAntiForgeryToken] diff --git a/Yavsc/Startup/Startup.FileServer.cs b/Yavsc/Startup/Startup.FileServer.cs index eb000928..487cb4ba 100644 --- a/Yavsc/Startup/Startup.FileServer.cs +++ b/Yavsc/Startup/Startup.FileServer.cs @@ -6,6 +6,7 @@ using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.StaticFiles; +using Microsoft.Extensions.Logging; using Yavsc.Abstract.FileSystem; using Yavsc.ViewModels.Auth; @@ -30,8 +31,6 @@ namespace Yavsc FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName), RequestPath = new PathString(Constants.UserFilesPath), EnableDirectoryBrowsing = env.IsDevelopment(), - - }; UserFilesOptions.EnableDefaultFiles=true; UserFilesOptions.StaticFileOptions.ServeUnknownFileTypes=true; @@ -58,13 +57,16 @@ namespace Yavsc var gitdirinfo = new DirectoryInfo(Startup.SiteSetup.GitRepository); GitDirName = gitdirinfo.FullName; if (!gitdirinfo.Exists) gitdirinfo.Create(); - GitOptions = new FileServerOptions() { FileProvider = new PhysicalFileProvider(GitDirName), RequestPath = new PathString(Constants.GitPath), - EnableDirectoryBrowsing = env.IsDevelopment() + EnableDirectoryBrowsing = env.IsDevelopment(), }; + GitOptions.DefaultFilesOptions.DefaultFileNames.Add("index.md"); + GitOptions.StaticFileOptions.ServeUnknownFileTypes = true; + logger.LogInformation( $"{GitDirName}"); + GitOptions.StaticFileOptions.OnPrepareResponse+= OnPrepareGitRepoResponse; app.UseFileServer(UserFilesOptions); @@ -73,5 +75,14 @@ namespace Yavsc app.UseFileServer(GitOptions); app.UseStaticFiles(); } + + static void OnPrepareGitRepoResponse(StaticFileResponseContext context) + { + + if (context.File.Name.EndsWith(".ansi.log")) + { + context.Context.Response.Redirect("/Git"+context.Context.Request.Path); + } + } } } diff --git a/Yavsc/Yavsc.nuspec b/Yavsc/Yavsc.nuspec index 057c56e3..26fce502 100644 --- a/Yavsc/Yavsc.nuspec +++ b/Yavsc/Yavsc.nuspec @@ -19,7 +19,10 @@ - + + + + diff --git a/Yavsc/project.json b/Yavsc/project.json index 49e7358f..c6773184 100755 --- a/Yavsc/project.json +++ b/Yavsc/project.json @@ -28,13 +28,13 @@ "emitEntryPoint": true, "outputName": "Yavsc", "compile": { - "include": "*.cs", "exclude": [ "wwwroot", "node_modules", "bower_components", "contrib" - ] + ], + "include": "*.cs" }, "embed": [ "Resources/**/*.resx" diff --git a/cli/project.json b/cli/project.json index 242192e7..e0b3c523 100644 --- a/cli/project.json +++ b/cli/project.json @@ -44,13 +44,13 @@ "Microsoft.Framework.Configuration.Json": "1.0.0-beta8", "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", "Newtonsoft.Json": "9.0.1", - "Yavsc": { "version": "1.0.5-rc20-alpha8", "target": "package" }, - "Yavsc.Abstract": { "version": "1.0.5-rc20-alpha8", "target": "package" }, - "Yavsc.Server": { "version": "1.0.5-rc20-alpha8", "target": "package" } + "Yavsc": { "version": "1.0.5-rc20-alpha9", "target": "package" }, + "Yavsc.Abstract": { "version": "1.0.5-rc20-alpha9", "target": "package" }, + "Yavsc.Server": { "version": "1.0.5-rc20-alpha9", "target": "package" } }, "frameworks": { "dnx451": { "System.Net": "4.0.0" } } -} \ No newline at end of file +} diff --git a/rc-num.txt b/rc-num.txt index 85029bb5..db6058ba 100644 --- a/rc-num.txt +++ b/rc-num.txt @@ -1 +1 @@ -20-alpha8 +20-alpha9