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 - beta
sudo: false sudo: false
install: 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 - DNX_USER_HOME=`pwd -P`/dnx . ./dnx/dnvm/dnvm.sh
- cd src/OAuth.AspNet.Token && dnu restore - cd src/OAuth.AspNet.Token && dnu restore
- cd ../OAuth.AspNet.AuthServer && dnu restore - cd ../OAuth.AspNet.AuthServer && dnu restore

@ -1,14 +1,17 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using Yavsc.ViewModels.UserFiles; 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 class AbstractFileSystemHelpers
{ {
public static string UserBillsDirName { set; get; } public static string UserBillsDirName { set; get; }
public static string UserFilesDirName { set; get; } public static string UserFilesDirName { set; get; }
@ -20,12 +23,12 @@ namespace Yavsc.Abstract.FileSystem
if (!IsValidDirectoryName(name) || name.Equals("..") || name.Equals(".")) if (!IsValidDirectoryName(name) || name.Equals("..") || name.Equals("."))
return false; return false;
} }
if (path[path.Length-1]==FileSystemConstants.RemoteDirectorySeparator) return false; if (path[path.Length-1]==RemoteDirectorySeparator) return false;
return true; return true;
} }
public static bool IsValidDirectoryName(this string name) 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, // Ensure this path is canonical,
// No "dirto/./this", neither "dirt/to/that/" // No "dirto/./this", neither "dirt/to/that/"
@ -37,24 +40,27 @@ namespace Yavsc.Abstract.FileSystem
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach (var c in fileName) foreach (var c in fileName)
{ {
if (FileSystemConstants.ValidFileNameChars.Contains(c)) if (ValidFileNameChars.Contains(c))
sb.Append(c); sb.Append(c);
else sb.Append('_'); else sb.Append('_');
} }
return sb.ToString(); 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; return di;
} }
}
public static class FileSystemConstants
{
public const char RemoteDirectorySeparator = '/'; public const char RemoteDirectorySeparator = '/';
public static char[] ValidFileNameChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=_~. ".ToCharArray(); 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.IO;
using System.Linq; using System.Linq;
using Yavsc.Abstract.FileSystem; using Yavsc.Abstract.FileSystem;
using Yavsc.Helpers;
namespace Yavsc.ViewModels.UserFiles 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 System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Yavsc.Abstract.FileSystem; using Yavsc.Helpers;
using Yavsc.Exceptions; using Yavsc.Exceptions;
using Yavsc.Models.FileSystem; using Yavsc.Models.FileSystem;
@ -48,7 +48,7 @@ namespace Yavsc.ApiControllers
if (subdir !=null) if (subdir !=null)
if (!subdir.IsValidYavscPath()) if (!subdir.IsValidYavscPath())
return new BadRequestResult(); return new BadRequestResult();
var files = User.GetUserFiles(subdir); var files = AbstractFileSystemHelpers.GetUserFiles(User.Identity.Name, subdir);
return Ok(files); return Ok(files);
} }
@ -89,7 +89,7 @@ namespace Yavsc.ApiControllers
return Ok(received); return Ok(received);
} }
[Route("/api/addquota/{len}")] [Route("/api/fs/addquota/{len}")]
[Authorize("AdministratorOnly")] [Authorize("AdministratorOnly")]
public IActionResult AddQuota(int len) public IActionResult AddQuota(int len)
{ {
@ -102,6 +102,19 @@ namespace Yavsc.ApiControllers
return Ok(len); 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] [HttpDelete]
public async Task <IActionResult> Delete (string id) public async Task <IActionResult> Delete (string id)
{ {

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

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

@ -99,7 +99,7 @@ namespace Yavsc.Controllers
public IActionResult EstimatePdf(long id) public IActionResult EstimatePdf(long id)
{ {
ViewBag.TempDir = Startup.SiteSetup.TempDir; ViewBag.TempDir = Startup.SiteSetup.TempDir;
ViewBag.BillsDir = AbstractFileSystemHelpers.UserBillsDirName; ViewBag.BillsDir = AbstractFileSystemHelpers.UserBillsDirName;
var estimate = _context.Estimates.Include(x => x.Query) var estimate = _context.Estimates.Include(x => x.Query)
.Include(x => x.Query.Client) .Include(x => x.Query.Client)
.Include(x => x.Query.PerformerProfile) .Include(x => x.Query.PerformerProfile)

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

@ -2094,5 +2094,11 @@ namespace Yavsc {
return ResourceManager.GetString("LiveFlow", resourceCulture); 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.Http;
using Microsoft.AspNet.StaticFiles; using Microsoft.AspNet.StaticFiles;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Yavsc.Abstract.FileSystem; using Yavsc.Helpers;
using Yavsc.Services; using Yavsc.Services;
using Yavsc.ViewModels.Auth; using Yavsc.ViewModels.Auth;

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

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

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

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

@ -132,9 +132,11 @@
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final", "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
"System.Json": "4.0.20126.16343", "System.Json": "4.0.20126.16343",
"OAuth.AspNet.Token": { "OAuth.AspNet.Token": {
"target": "project",
"type": "build" "type": "build"
}, },
"OAuth.AspNet.AuthServer": { "OAuth.AspNet.AuthServer": {
"target": "project",
"type": "build" "type": "build"
}, },
"PayPalMerchant-net451": { "PayPalMerchant-net451": {
@ -142,9 +144,11 @@
}, },
"Gapi.net45": "1.0.1", "Gapi.net45": "1.0.1",
"Yavsc.Abstract": { "Yavsc.Abstract": {
"target": "project",
"type": "build" "type": "build"
}, },
"Yavsc.Server": { "Yavsc.Server": {
"target": "project",
"type": "build" "type": "build"
}, },
"GoogleTranslate": "1.0.5" "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;} 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{max-height:3em;}
tr.visiblepost img{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", "Newtonsoft.Json": "9.0.1",
"NJsonSchema.CodeGeneration.CSharp": "9.10.65", "NJsonSchema.CodeGeneration.CSharp": "9.10.65",
"Yavsc": { "Yavsc": {
"version": "1.0.6-rc04", "version": "1.0.6-rc05",
"target": "package" "target": "package"
}, },
"Microsoft.Dnx.Host": "1.0.0-rc1-final", "Microsoft.Dnx.Host": "1.0.0-rc1-final",

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

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

Loading…