fixe l'upload
This commit is contained in:
@ -82,6 +82,18 @@ editorcontenu.on('text-change',function(delta,source){
|
||||
$('#titletoolbar').addClass('hidden');
|
||||
})
|
||||
|
||||
Dropzone.options.postfiles= {
|
||||
maxFilesize: 2, // MB
|
||||
autoProcessQueue: true,
|
||||
accept: function(file, done) {
|
||||
if (file.name == "justinbieber.jpg") {
|
||||
done("Naha, you don't.");
|
||||
}
|
||||
else { done(); }
|
||||
},
|
||||
url: "/UserFiles/Create?PostId=@Model.Id"
|
||||
};
|
||||
|
||||
});
|
||||
</script>
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
@ -120,8 +132,7 @@ editorcontenu.on('text-change',function(delta,source){
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div markdown="@Model.bcontent" base="~/@Model.Author.UserName/@Model.Id"
|
||||
site="SiteSettings.Value" id="contentcnt" ></div>
|
||||
<div markdown="@Model.bcontent" base="~/@Model.Id" site="SiteSettings.Value" id="contentcnt" ></div>
|
||||
|
||||
<hr>
|
||||
|
||||
@ -174,20 +185,19 @@ editorcontenu.on('text-change',function(delta,source){
|
||||
|
||||
|
||||
<div >
|
||||
<form asp-action="Create" asp-controller="UserFiles" method="post" class="dropzone" enctype="multipart/form-data">
|
||||
<form id="postfiles" class="dropzone" method="post" enctype="multipart/form-data">
|
||||
<div class="fallback">
|
||||
<input name="file" type="file" multiple />
|
||||
<input name="File[]" type="file"/>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="postId" value="@Model.Id" />
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<input type="submit" value="Upload" class="btn btn-default" />
|
||||
<input type="button" value="Upload" class="btn btn-default" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@Html.AntiForgeryToken()
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a asp-action="Index">Back to List</a>
|
||||
</div>
|
||||
|
6
Yavsc/Views/Shared/_FileListPartial.cshtml
Normal file
6
Yavsc/Views/Shared/_FileListPartial.cshtml
Normal file
@ -0,0 +1,6 @@
|
||||
@model IList<string>
|
||||
|
||||
@foreach (var file in Model) {
|
||||
<li>@file</li>
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
"Address": "contact@company.com"
|
||||
},
|
||||
"UserFiles": {
|
||||
"RootDir": "UserFiles",
|
||||
"DirName": "UserFiles",
|
||||
"Quota": "200M"
|
||||
},
|
||||
"DirNames": {
|
||||
|
@ -27,7 +27,6 @@ namespace Yavsc
|
||||
public const string UserBlogFilesDir= "Blog";
|
||||
public const string UserBillsFilesDir= "Bills";
|
||||
|
||||
public const string UserFilesRequestPath = "/UserFiles";
|
||||
public const string GCMNotificationUrl = "https://gcm-http.googleapis.com/gcm/send";
|
||||
private static readonly string[] GoogleScopes = { "openid", "profile", "email" };
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace Yavsc.Controllers
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
ViewBag.Files = estimate.GetFileContent(_site.UserFiles.RootDir);
|
||||
ViewBag.Files = estimate.GetFileContent(_site.UserFiles.DirName);
|
||||
return View(estimate);
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ namespace Yavsc.Controllers
|
||||
);
|
||||
|
||||
var userdir = Path.Combine(
|
||||
_site.UserFiles.RootDir,
|
||||
_site.UserFiles.DirName,
|
||||
perfomerProfile.Performer.UserName
|
||||
);
|
||||
|
||||
@ -119,7 +119,7 @@ namespace Yavsc.Controllers
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
ViewBag.Files = estimate.GetFileContent(_site.UserFiles.RootDir);
|
||||
ViewBag.Files = estimate.GetFileContent(_site.UserFiles.DirName);
|
||||
return View(estimate);
|
||||
}
|
||||
|
||||
|
@ -342,14 +342,16 @@ namespace Yavsc.Controllers
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
var userdirinfo = new DirectoryInfo(
|
||||
Path.Combine(_siteSettings.UserFiles.RootDir,
|
||||
oldUserName));
|
||||
var newdir = Path.Combine(_siteSettings.UserFiles.RootDir,
|
||||
model.NewUserName);
|
||||
/* Obsolete : files are no more prefixed using the user name.
|
||||
|
||||
var userdirinfo = new DirectoryInfo(
|
||||
Path.Combine(_siteSettings.UserFiles.DirName,
|
||||
oldUserName));
|
||||
var newdir = Path.Combine(_siteSettings.UserFiles.DirName,
|
||||
model.NewUserName);
|
||||
if (userdirinfo.Exists)
|
||||
userdirinfo.MoveTo(newdir);
|
||||
*/
|
||||
|
||||
await _signInManager.SignInAsync(user, isPersistent: false);
|
||||
_logger.LogInformation(3, "User changed his user name successfully.");
|
||||
|
@ -1,11 +1,72 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Authorize, ServiceFilter(typeof(LanguageActionFilter))]
|
||||
public class UserFilesController : Controller
|
||||
{
|
||||
private SiteSettings _siteSettings;
|
||||
IHostingEnvironment _environment;
|
||||
private IAuthorizationService _authorizationService;
|
||||
ApplicationDbContext _context;
|
||||
ILogger _logger;
|
||||
public UserFilesController(
|
||||
ApplicationDbContext context,
|
||||
IHostingEnvironment environment, IOptions<SiteSettings> siteSettings,
|
||||
IAuthorizationService authorizationService, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_context = context;
|
||||
_siteSettings = siteSettings.Value;
|
||||
_environment = environment;
|
||||
_authorizationService = authorizationService;
|
||||
_logger = loggerFactory.CreateLogger<UserFilesController>();
|
||||
}
|
||||
|
||||
[HttpPost, Produces("application/json")]
|
||||
public async Task<IActionResult> Create(BlogFilesPost model)
|
||||
{
|
||||
var blogEntry = _context.Blogspot.FirstOrDefault(
|
||||
be => be.Id == model.PostId);
|
||||
if (blogEntry == null)
|
||||
return new HttpNotFoundResult();
|
||||
if (!ModelState.IsValid)
|
||||
return new BadRequestObjectResult(ModelState);
|
||||
var results = new List<string>();
|
||||
var uploads = Path.Combine(_environment.WebRootPath, _siteSettings.UserFiles.DirName);
|
||||
uploads = Path.Combine(uploads, model.PostId.ToString());
|
||||
var spot = new FileSpotInfo(uploads, blogEntry);
|
||||
if (!await _authorizationService.AuthorizeAsync(User, spot, new EditRequirement()))
|
||||
{
|
||||
return new HttpStatusCodeResult(403);
|
||||
}
|
||||
if (!spot.PathInfo.Exists) spot.PathInfo.Create();
|
||||
foreach (var file in model.File)
|
||||
{
|
||||
var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
|
||||
var permUrl = $"~/{_siteSettings.UserFiles.DirName}/{model.PostId}/{fileName}";
|
||||
results.Add(permUrl);
|
||||
_logger.LogWarning($"Create: {model.PostId} {file.ContentDisposition}");
|
||||
/* if (file.Length > 0)
|
||||
{
|
||||
var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
|
||||
var fullName = Path.Combine(spot.PathInfo.FullName, fileName);
|
||||
results.Add(permUrl);
|
||||
await file.SaveAsAsync(fullName);
|
||||
} */
|
||||
}
|
||||
return Ok(results);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -107,7 +107,8 @@ namespace Yavsc.Helpers
|
||||
|
||||
var content = await GetContent(output);
|
||||
var markdown = content;
|
||||
var basePath = Base?.StartsWith("~") ?? false ? Constants.UserFilesRequestPath+
|
||||
var basePath = Base?.StartsWith("~") ?? false ?
|
||||
"/"+Startup.UserFilesDirName +
|
||||
Base.Substring(1) : Base;
|
||||
var html = Markdown(markdown, basePath);
|
||||
output.Content.SetHtmlContent(html ?? "");
|
||||
|
@ -2,7 +2,7 @@ namespace Yavsc
|
||||
{
|
||||
|
||||
public class ThirdPartyFiles {
|
||||
public string RootDir { get; set; }
|
||||
public string DirName { get; set; }
|
||||
public string Quota { get; set; }
|
||||
}
|
||||
}
|
@ -72,6 +72,7 @@ namespace Yavsc
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public static string UserFilesDirName { get; private set; }
|
||||
private RsaSecurityKey key;
|
||||
|
||||
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
|
||||
@ -244,6 +245,7 @@ namespace Yavsc
|
||||
services.AddSingleton<IAuthorizationHandler, BlogViewHandler>();
|
||||
services.AddSingleton<IAuthorizationHandler, CommandEditHandler>();
|
||||
services.AddSingleton<IAuthorizationHandler, CommandViewHandler>();
|
||||
services.AddSingleton<IAuthorizationHandler, PostUserFileHandler>();
|
||||
services.AddMvc(config =>
|
||||
{
|
||||
var policy = new AuthorizationPolicyBuilder()
|
||||
@ -291,6 +293,7 @@ namespace Yavsc
|
||||
IOptions<OAuth2AppSettings> oauth2SettingsContainer,
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
Startup.UserFilesDirName = siteSettings.Value.UserFiles.DirName;
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
@ -338,11 +341,6 @@ namespace Yavsc
|
||||
}
|
||||
}
|
||||
|
||||
var udirinfo = new DirectoryInfo(Configuration["Site:UserFiles:RootDir"]);
|
||||
if (!udirinfo.Exists)
|
||||
throw new Exception($"Configuration value for Site:UserFiles:RootDir : {udirinfo.FullName}");
|
||||
|
||||
|
||||
var googleOptions = new GoogleOptions
|
||||
{
|
||||
ClientId = Configuration["Authentication:Google:ClientId"],
|
||||
@ -450,8 +448,11 @@ namespace Yavsc
|
||||
app.UseFileServer(new FileServerOptions()
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(
|
||||
udirinfo.FullName),
|
||||
RequestPath = new PathString(Constants.UserFilesRequestPath),
|
||||
Path.Combine(
|
||||
env.WebRootPath,
|
||||
siteSettings.Value.UserFiles.DirName
|
||||
)),
|
||||
RequestPath = new PathString("/"+siteSettings.Value.UserFiles.DirName),
|
||||
EnableDirectoryBrowsing = false
|
||||
});
|
||||
|
||||
|
11
Yavsc/src/ViewModels/UserFiles/BlogFilesPost.cs
Normal file
11
Yavsc/src/ViewModels/UserFiles/BlogFilesPost.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
public class BlogFilesPost {
|
||||
[Required]
|
||||
public long PostId {get; set; }
|
||||
[Required]
|
||||
public IList<IFormFile> File { get; set; }
|
||||
}
|
19
Yavsc/src/ViewModels/UserFiles/FileInfo.cs
Normal file
19
Yavsc/src/ViewModels/UserFiles/FileInfo.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace Yavsc.ViewModels
|
||||
{
|
||||
public class FileInfo
|
||||
{
|
||||
|
||||
public string PermanentUri { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public int Size { get; set; }
|
||||
|
||||
public DateTime Creation { get; set; }
|
||||
|
||||
public string MimeType { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -134,7 +134,7 @@
|
||||
acceptedMimeTypes: null,
|
||||
autoProcessQueue: true,
|
||||
autoQueue: true,
|
||||
addRemoveLinks: false,
|
||||
addRemoveLinks: true,
|
||||
previewsContainer: null,
|
||||
hiddenInputContainer: "body",
|
||||
capture: null,
|
||||
|
2
Yavsc/wwwroot/js/site.min.js
vendored
2
Yavsc/wwwroot/js/site.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user