docs: #263 Remove museum original images to free up space and replace them with the urls to their original sources
This commit is contained in:
parent
f0210db076
commit
863c9ede70
@ -1974,6 +1974,32 @@ namespace RMuseum.Controllers
|
||||
return BadRequest(exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// start removing original images
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpDelete("originalimages/remove")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ImportOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.Unauthorized)]
|
||||
public IActionResult StartRemovingOriginalImages()
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = _artifactService.StartRemovingOriginalImages();
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return BadRequest(exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// readonly mode
|
||||
/// </summary>
|
||||
|
||||
@ -596,6 +596,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.ArtifactController.StartRemovingOriginalImages">
|
||||
<summary>
|
||||
start removing original images
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RMuseum.Controllers.ArtifactController.ReadOnlyMode">
|
||||
<summary>
|
||||
readonly mode
|
||||
@ -9377,6 +9383,12 @@
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IArtifactService.StartRemovingOriginalImages">
|
||||
<summary>
|
||||
start removing original images
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IDonationService">
|
||||
<summary>
|
||||
donation service
|
||||
@ -10404,6 +10416,9 @@
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
</summary>
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartFillingGanjoorLinkOriginalSources">
|
||||
<summary>
|
||||
@ -10511,6 +10526,12 @@
|
||||
<param name="friendlyUrl">golestan-walters-01</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartRemovingOriginalImages">
|
||||
<summary>
|
||||
start removing original images
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartImportingFromPrinceton(System.String,System.String)">
|
||||
<summary>
|
||||
from http://pudl.princeton.edu/
|
||||
|
||||
@ -557,5 +557,11 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> AcceptPublicNoteReport(Guid id);
|
||||
|
||||
/// <summary>
|
||||
/// start removing original images
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> StartRemovingOriginalImages();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.DbContext;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
namespace RMuseum.Services.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// IArtifactService implementation
|
||||
/// </summary>
|
||||
public partial class ArtifactService : IArtifactService
|
||||
{
|
||||
/// <summary>
|
||||
/// start removing original images
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> StartRemovingOriginalImages()
|
||||
{
|
||||
try
|
||||
{
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
|
||||
{
|
||||
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
|
||||
var job = (await jobProgressServiceEF.NewJob("RemovingOriginalImages", "Removing")).Result;
|
||||
|
||||
try
|
||||
{
|
||||
var srcPath = Configuration.GetSection("PictureFileService")["StoragePath"];
|
||||
var trashPath = Configuration.GetSection("PictureFileService")["TrashStoragePath"];
|
||||
|
||||
var images = await context.PictureFiles.Where(p => p.StoredFileName != null && p.SrcUrl != null).ToListAsync();
|
||||
|
||||
int progress = 0;
|
||||
|
||||
for (int i = 0; i < images.Count; i++)
|
||||
{
|
||||
var image = images[i];
|
||||
string targetDir = Path.Combine(trashPath, image.FolderName);
|
||||
if (!Directory.Exists(targetDir))
|
||||
{
|
||||
Directory.CreateDirectory(targetDir);
|
||||
Directory.CreateDirectory(Path.Combine(targetDir, "orig"));
|
||||
}
|
||||
string srcFileName = Path.Combine(Path.Combine(srcPath, image.FolderName), image.StoredFileName);
|
||||
if(File.Exists(srcFileName))
|
||||
{
|
||||
string targetFileName = Path.Combine(Path.Combine(trashPath, image.FolderName), image.StoredFileName);
|
||||
File.Move(srcFileName, targetFileName, true);
|
||||
image.StoredFileName = null;
|
||||
context.Update(image);
|
||||
|
||||
if( (i * 100 / images.Count) > progress)
|
||||
{
|
||||
progress = i * 100 / images.Count;
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,8 @@
|
||||
"NormalImageMaxHeight": "1350",
|
||||
"ThumbnailImageWidth": "300",
|
||||
"ThumbnailMaxHeight": "500",
|
||||
"ImageInfoCacheEnabled": "False"
|
||||
"ImageInfoCacheEnabled": "False",
|
||||
"TrashStoragePath": "C:\\museum-trash"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user