1.0.5-rc20-alpha9 : ansi2html helper
This commit is contained in:
42
Yavsc.Server/Helpers/Ansi2HtmlEncoder.cs
Normal file
42
Yavsc.Server/Helpers/Ansi2HtmlEncoder.cs
Normal file
@ -0,0 +1,42 @@
|
||||
// // AnsiToHtmlEncoder.cs
|
||||
// /*
|
||||
// paul schneider <paul@pschneider.fr> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
<tags>yavsc</tags>
|
||||
<dependencies>
|
||||
<dependency id="Yavsc.Abstract" version="$version$" />
|
||||
<dependency id="Microsoft.Extensions.Logging" version="1.0.0-rc1-final" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
@ -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<IActionResult> Index()
|
||||
{
|
||||
@ -50,6 +79,7 @@ namespace Yavsc.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
// POST: Git/Create
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,10 @@
|
||||
<dependencies>
|
||||
<dependency id="Yavsc.Abstract" version="$version$"></dependency>
|
||||
<dependency id="Yavsc.Server" version="$version$"></dependency>
|
||||
</dependencies>
|
||||
<dependency id="Microsoft.Extensions.Logging" version="1.0.0-rc1-final" />
|
||||
<dependency id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.0-rc1-final" />
|
||||
<dependency id="Microsoft.Extensions.Options" version="0.0.1-alpha" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="bin/$config$/dnx451/Yavsc.dll" target="lib/portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10" />
|
||||
|
@ -28,13 +28,13 @@
|
||||
"emitEntryPoint": true,
|
||||
"outputName": "Yavsc",
|
||||
"compile": {
|
||||
"include": "*.cs",
|
||||
"exclude": [
|
||||
"wwwroot",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"contrib"
|
||||
]
|
||||
],
|
||||
"include": "*.cs"
|
||||
},
|
||||
"embed": [
|
||||
"Resources/**/*.resx"
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
20-alpha8
|
||||
20-alpha9
|
||||
|
Reference in New Issue
Block a user