use the ID for the document filenames

This commit is contained in:
Lynne Megido 2020-09-20 14:05:18 +10:00
parent 9a25bc406f
commit e5748ec8d5
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
2 changed files with 6 additions and 5 deletions

View file

@ -5,6 +5,7 @@
ViewData["Title"] = $"Viewing \"{Model.Document.Title}\"";
ViewData["SlimNavbar"] = true;
ViewData["NoMainPadding"] = true;
string path = $"/Content/{Model.Document.ID}.pdf";
}
<iframe id="document-viewer" src="/Content/@Model.Document.Filename"></iframe>
<iframe id="document-viewer" src="@path"></iframe>

View file

@ -32,10 +32,10 @@ namespace Snootalogue.Pages {
return Page();
}
var filename = WebUtility.HtmlEncode(ud.UploadedFile.FileName);
var id = Document.NewID(_context);
// var uploadDirectory = Path.Combine(filename);
var uploadDirectory = "wwwroot/Content";
var destination = Path.Combine(uploadDirectory, filename);
var destination = Path.Combine(uploadDirectory, $"{id}.pdf");
using (var fs = new FileStream(destination, FileMode.Create)) {
await ud.UploadedFile.CopyToAsync(fs);
@ -43,14 +43,14 @@ namespace Snootalogue.Pages {
// Document d = _context.Document.
Document d = new Document {
ID = Document.NewID(_context),
ID = id,
Title = ud.Title,
Authors = ud.Authors.Split(",").ToList<string>(),
Category = ud.Category,
Tags = string.IsNullOrWhiteSpace(ud.Tags) ? null : ud.Tags.Split(",").ToList<string>(),
Notes = ud.Notes,
Read = ud.Read,
Filename = filename
Filename = WebUtility.HtmlEncode(ud.UploadedFile.FileName)
};
_context.Document.Add(d);