packaging+fs

vnext
Paul Schneider 5 years ago
parent 9a17dcf017
commit 0a6bb634b9
21 changed files with 95 additions and 66 deletions

@ -4,7 +4,7 @@ mono:
- beta
sudo: false
install:
- curl --insecure -sSL https://freespeech.pschneider.fr/files/Paul/dnx-install.sh | bash
- curl --insecure -sSL https://lua.pschneider.fr/files/Paul/pub/dnx-install.sh | bash
- DNX_USER_HOME=`pwd -P`/dnx . ./dnx/dnvm/dnvm.sh
- cd src/OAuth.AspNet.Token && dnu restore
- cd ../OAuth.AspNet.AuthServer && dnu restore

@ -1,14 +1,17 @@
using System.IO;
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Text;
using Yavsc.ViewModels.UserFiles;
namespace Yavsc.Abstract.FileSystem
using System;
using System.Threading;
using Yavsc.ViewModels;
namespace Yavsc.Helpers
{
public static class AbstractFileSystemHelpers
{
public static string UserBillsDirName { set; get; }
public static string UserFilesDirName { set; get; }
@ -20,12 +23,12 @@ namespace Yavsc.Abstract.FileSystem
if (!IsValidDirectoryName(name) || name.Equals("..") || name.Equals("."))
return false;
}
if (path[path.Length-1]==FileSystemConstants.RemoteDirectorySeparator) return false;
if (path[path.Length-1]==RemoteDirectorySeparator) return false;
return true;
}
public static bool IsValidDirectoryName(this string name)
{
return !name.Any(c => !FileSystemConstants.ValidFileNameChars.Contains(c));
return !name.Any(c => !ValidFileNameChars.Contains(c));
}
// Ensure this path is canonical,
// No "dirto/./this", neither "dirt/to/that/"
@ -37,24 +40,27 @@ namespace Yavsc.Abstract.FileSystem
StringBuilder sb = new StringBuilder();
foreach (var c in fileName)
{
if (FileSystemConstants.ValidFileNameChars.Contains(c))
if (ValidFileNameChars.Contains(c))
sb.Append(c);
else sb.Append('_');
}
return sb.ToString();
}
public static UserDirectoryInfo GetUserFiles(this ClaimsPrincipal user, string subdir)
public static UserDirectoryInfo GetUserFiles(string userName, string subdir)
{
UserDirectoryInfo di = new UserDirectoryInfo(UserFilesDirName, user.Identity.Name, subdir);
UserDirectoryInfo di = new UserDirectoryInfo(UserFilesDirName, userName, subdir);
return di;
}
}
public static class FileSystemConstants
{
public const char RemoteDirectorySeparator = '/';
public static char[] ValidFileNameChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_~. ".ToCharArray();
public static Func<string,string,long,string>
SignFileNameFormat = new Func<string,string,long,string> ((signType,billingCode,estimateId) => $"sign-{billingCode}-{signType}-{estimateId}.png");
}
}

@ -0,0 +1,9 @@
using Yavsc.Abstract.FileSystem;
namespace Yavsc.ViewModels.UserFiles
{
public class DirectoryShortInfo: IDirectoryShortInfo {
public string Name { get; set; }
public bool IsEmpty { get; set; }
}
}

@ -2,6 +2,7 @@ using System;
using System.IO;
using System.Linq;
using Yavsc.Abstract.FileSystem;
using Yavsc.Helpers;
namespace Yavsc.ViewModels.UserFiles
{
@ -49,9 +50,4 @@ namespace Yavsc.ViewModels.UserFiles
}
}
}
public class DirectoryShortInfo: IDirectoryShortInfo {
public string Name { get; set; }
public bool IsEmpty { get; set; }
}
}

@ -11,7 +11,7 @@ namespace Yavsc.ApiControllers
{
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Yavsc.Abstract.FileSystem;
using Yavsc.Helpers;
using Yavsc.Exceptions;
using Yavsc.Models.FileSystem;
@ -48,7 +48,7 @@ namespace Yavsc.ApiControllers
if (subdir !=null)
if (!subdir.IsValidYavscPath())
return new BadRequestResult();
var files = User.GetUserFiles(subdir);
var files = AbstractFileSystemHelpers.GetUserFiles(User.Identity.Name, subdir);
return Ok(files);
}
@ -89,7 +89,7 @@ namespace Yavsc.ApiControllers
return Ok(received);
}
[Route("/api/addquota/{len}")]
[Route("/api/fs/addquota/{len}")]
[Authorize("AdministratorOnly")]
public IActionResult AddQuota(int len)
{
@ -102,6 +102,19 @@ namespace Yavsc.ApiControllers
return Ok(len);
}
[Route("/api/fs/move")]
[Authorize()]
public IActionResult Move(string from, string to)
{
var uid = User.GetUserId();
var user = dbContext.Users.Single(
u => u.Id == uid
);
return Ok();
}
[HttpDelete]
public async Task <IActionResult> Delete (string id)
{

@ -2,26 +2,25 @@ using System.IO;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc;
using System.Web.Routing;
using System.Linq;
using Microsoft.Data.Entity;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.OptionsModel;
using System;
using System.Security.Claims;
using System.Linq;
using Microsoft.Data.Entity;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.OptionsModel;
using Newtonsoft.Json;
using System;
using System.Security.Claims;
using Yavsc.Helpers;
using Yavsc.ViewModels;
namespace Yavsc.ApiControllers
{
using Models;
using Helpers;
using Services;
using Models.Messaging;
using ViewModels.Auth;
using Newtonsoft.Json;
using Yavsc.ViewModels;
using Yavsc.Abstract.FileSystem;
[Route("api/bill"), Authorize]
public class BillingController : Controller
@ -144,7 +143,7 @@ namespace Yavsc.ApiControllers
return new ChallengeResult();
}
var filename = FileSystemHelpers.SignFileNameFormat("pro",billingCode,id);
var filename = AbstractFileSystemHelpers.SignFileNameFormat("pro", billingCode, id);
FileInfo fi = new FileInfo(Path.Combine(AbstractFileSystemHelpers.UserBillsDirName, filename));
if (!fi.Exists) return HttpNotFound(new { Error = "Professional signature not found" });
return File(fi.OpenRead(), "application/x-pdf", filename); ;
@ -179,7 +178,7 @@ namespace Yavsc.ApiControllers
return new ChallengeResult();
}
var filename = FileSystemHelpers.SignFileNameFormat("pro",billingCode,id);
var filename = AbstractFileSystemHelpers.SignFileNameFormat("pro", billingCode, id);
FileInfo fi = new FileInfo(Path.Combine(AbstractFileSystemHelpers.UserBillsDirName, filename));
if (!fi.Exists) return HttpNotFound(new { Error = "Professional signature not found" });
return File(fi.OpenRead(), "application/x-pdf", filename); ;

@ -9,6 +9,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Microsoft.Extensions.OptionsModel;
using Yavsc.Helpers;
namespace Yavsc.Controllers
{
@ -16,7 +17,6 @@ namespace Yavsc.Controllers
using Models.Billing;
using Models.Workflow;
using ViewModels.Auth;
using Yavsc.Abstract.FileSystem;
[Authorize]
public class EstimateController : Controller
@ -163,7 +163,9 @@ namespace Yavsc.Controllers
return HttpNotFound();
}
ViewBag.Files = User.GetUserFiles(null);
ViewBag.Files = Yavsc.Helpers.FileSystemHelpers.GetFileName(null);
// Yavsc.Helpers.GetUserFiles(User, null);
return View(estimate);
}

@ -1,18 +1,13 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net.Mime;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.Logging;
using Yavsc.Abstract.FileSystem;
using Yavsc.Exceptions;
using Yavsc.Models;
using Yavsc.Models.FileSystem;
@ -23,14 +18,10 @@ namespace Yavsc.Helpers
{
public static class FileSystemHelpers
{
public static Func<string,string,long,string>
SignFileNameFormat = new Func<string,string,long,string> ((signType,billingCode,estimateId) => $"sign-{billingCode}-{signType}-{estimateId}.png");
public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, string billingCode, long estimateId, IFormFile formFile, string signtype)
public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, string billingCode, long estimateId, IFormFile formFile, string signtype)
{
var item = new FileRecievedInfo();
item.FileName = SignFileNameFormat("pro",billingCode,estimateId);
item.FileName = AbstractFileSystemHelpers.SignFileNameFormat("pro",billingCode,estimateId);
item.MimeType = formFile.ContentDisposition;
var destFileName = Path.Combine(Startup.SiteSetup.Bills, item.FileName);
@ -129,7 +120,7 @@ public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, st
long usage = user.DiskUsage;
var item = new FileRecievedInfo();
item.FileName = Yavsc.Abstract.FileSystem.AbstractFileSystemHelpers.FilterFileName (destFileName);
item.FileName = AbstractFileSystemHelpers.FilterFileName (destFileName);
item.MimeType = contentType;
item.DestDir = root;
var fi = new FileInfo(Path.Combine(root, item.FileName));
@ -165,9 +156,8 @@ public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, st
public static HtmlString FileLink(this RemoteFileInfo info, string username, string subpath)
{
return new HtmlString( Startup.UserFilesOptions.RequestPath+"/"+ username +
"/" + (( subpath == null ) ? "" : "/" + subpath ) +
info.Name );
return new HtmlString(
$"{Startup.UserFilesOptions.RequestPath}/{username}/{subpath}/{info.Name}" );
}
public static FileRecievedInfo ReceiveAvatar(this ApplicationUser user, IFormFile formFile)
{

@ -2094,5 +2094,11 @@ namespace Yavsc {
return ResourceManager.GetString("LiveFlow", resourceCulture);
}
}
public static string Instrumentation {
get {
return ResourceManager.GetString("Instrumentation", resourceCulture);
}
}
}
}

@ -7,7 +7,7 @@ using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.StaticFiles;
using Microsoft.Extensions.Logging;
using Yavsc.Abstract.FileSystem;
using Yavsc.Helpers;
using Yavsc.Services;
using Yavsc.ViewModels.Auth;

@ -36,6 +36,7 @@ namespace Yavsc
using Services;
using Yavsc.Abstract.FileSystem;
using Yavsc.AuthorizationHandlers;
using Yavsc.Helpers;
using static System.Environment;
public partial class Startup

@ -81,7 +81,8 @@ namespace Yavsc.ViewComponents
}
ViewComponentContext.ViewContext.Writer = oldWriter;
var genrtrData = new PdfGenerationViewModel{
var genrtrData = new PdfGenerationViewModel
{
Temp = Startup.Temp,
TeXSource = tex,
DestDir = AbstractFileSystemHelpers.UserBillsDirName,

@ -1,10 +1,10 @@
using Microsoft.AspNet.Mvc;
using System.Threading.Tasks;
using Yavsc.Helpers;
using Yavsc.ViewModels.UserFiles;
namespace Yavsc.ViewComponents
{
using System.Threading.Tasks;
using Yavsc.Abstract.FileSystem;
using Yavsc.ViewModels.UserFiles;
public class DirectoryViewComponent : ViewComponent
{

@ -7,6 +7,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.FileSystem;
@ -41,7 +42,7 @@ namespace Yavsc.ViewModels.Streaming
long usage = user.DiskUsage;
var item = new FileRecievedInfo();
item.FileName = Yavsc.Abstract.FileSystem.AbstractFileSystemHelpers.FilterFileName (destFileName);
item.FileName = AbstractFileSystemHelpers.FilterFileName (destFileName);
item.MimeType = contentType;
item.DestDir = root;
var fi = new FileInfo(Path.Combine(root, item.FileName));

@ -132,9 +132,11 @@
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
"System.Json": "4.0.20126.16343",
"OAuth.AspNet.Token": {
"target": "project",
"type": "build"
},
"OAuth.AspNet.AuthServer": {
"target": "project",
"type": "build"
},
"PayPalMerchant-net451": {
@ -142,9 +144,11 @@
},
"Gapi.net45": "1.0.1",
"Yavsc.Abstract": {
"target": "project",
"type": "build"
},
"Yavsc.Server": {
"target": "project",
"type": "build"
},
"GoogleTranslate": "1.0.5"

@ -1,4 +1,4 @@
.navbar-link,.navbar-brand,.navbar-nav.dropdown>a{background-color:rgba(0,0,0,.2);border-radius:2em;}.navbar-link:hover,.navbar-brand:hover,.navbar-link:focus,.navbar-brand:focus{background-color:rgba(0,0,0,.4);}.navbar-inverse.navbar-brand{background-color:unset}.ql-editor{border:outset 1em rgb(238,144,62);padding:1em;}.badge{margin:1em;}.badge img{height:2em;}.row img{max-width:100%;max-height:6em;}
.navbar-link,.navbar-nav.dropdown>a{background-color:rgba(0,0,0,.2);border-radius:2em;}.navbar-link:hover,.navbar-link:focus{background-color:rgba(0,0,0,.4);}.navbar-brand:focus{background-color:unset;}.ql-editor{border:outset 1em rgb(238,144,62);padding:1em;}.badge{margin:1em;}.badge img{height:2em;}.row img{max-width:100%;max-height:6em;}
main img{max-width:100%;max-height:100%;}.userinfo{display:block;padding:.8em;margin:.6em;background-repeat:no-repeat;background-attachment:local;background-size:contain;background-image:url('/images/lis.svg');overflow:auto;padding-left:2em;}.performer{border-radius:1.5em;background-color:#f1e4f1;padding:1em;}.performer ul{margin-left:2.5em;}.smalltofhol{align-self:left;padding:.1em;border-radius:50%;}.commentmeta{margin:.5em;padding:.5em;border-right:#444 dashed 1px;border-top:#444 solid 1px;}.price{font-weight:bold;font-size:large;padding:.2em;margin:.2em;}.total{font-weight:bold;font-size:xx-large;background-color:#f8f;border:solid black 3px;border-radius:1em;padding:.2em;margin:.2em;}.blog{padding:1em;}.blog a{font-weight:900;}.blog a:active,.blog a:hover{outline:0;}.discussion{color:black;}.notif{color:#555;}.pv{color:#540;font-style:bold;}.discussion{font-family:monospace;}.notif{color:#006;font-family:monospace;}.pv{color:#251;font-family:monospace;font-style:bold;}#targets{display:block;}
tr.visiblepost{max-height:3em;}
tr.visiblepost img{max-height:3em;}

@ -1 +0,0 @@
nav{background:url(/images/logo-lua.png) no-repeat local;background-size:contain}

@ -48,7 +48,7 @@
"Newtonsoft.Json": "9.0.1",
"NJsonSchema.CodeGeneration.CSharp": "9.10.65",
"Yavsc": {
"version": "1.0.6-rc04",
"version": "1.0.6-rc05",
"target": "package"
},
"Microsoft.Dnx.Host": "1.0.0-rc1-final",

@ -48,10 +48,12 @@
"Microsoft.Dnx.Runtime": "1.0.0-rc1-final",
"xunit.runner.dnx": "2.1.0-rc1-build204",
"Yavsc.Server": {
"target": "project"
"target": "project",
"type": "build"
},
"Yavsc": {
"target": "project"
"target": "project",
"type": "build"
}
},
"frameworks": {

@ -1 +1 @@
1.0.6-rc04
1.0.6-rc05

Loading…