Unlink museum ganjoor and naskban links

#458
This commit is contained in:
Hamid Reza Mohammadi 2025-01-10 15:47:04 +03:30
parent c87b1e91c9
commit 88bcc61536
4 changed files with 150 additions and 13 deletions

View File

@ -1985,6 +1985,24 @@ namespace RMuseum.Controllers
return Ok();
}
/// <summary>
/// remove ganjoor link
/// </summary>
/// <param name="linkId"></param>
/// <returns></returns>
[HttpDelete]
[Route("ganjoor")]
[Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> RemoveGanjoorLinkAsync(Guid linkId)
{
RServiceResult<bool> suggestion = await _artifactService.RemoveGanjoorLinkAsync(linkId);
if (!string.IsNullOrEmpty(suggestion.ExceptionString))
return BadRequest(suggestion.ExceptionString);
return Ok();
}
/// <summary>
///toc / temporary one time api / to be removed
/// </summary>
@ -2082,6 +2100,24 @@ namespace RMuseum.Controllers
return Ok();
}
/// <summary>
/// remove pinterest link
/// </summary>
/// <param name="linkId"></param>
/// <returns></returns>
[HttpDelete]
[Route("pinterest")]
[Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> RemovePinterestLinkAsync(Guid linkId)
{
RServiceResult<bool> suggestion = await _artifactService.RemovePinterestLinkAsync(linkId);
if (!string.IsNullOrEmpty(suggestion.ExceptionString))
return BadRequest(suggestion.ExceptionString);
return Ok();
}
/// <summary>
/// start filling GanjoorLink table OriginalSource values
/// </summary>

View File

@ -578,6 +578,13 @@
<param name="displayOnPage">display ogn page</param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.ArtifactController.RemoveGanjoorLinkAsync(System.Guid)">
<summary>
remove ganjoor link
</summary>
<param name="linkId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.ArtifactController.AddTOCForSuggestedLinks">
<summary>
toc / temporary one time api / to be removed
@ -617,6 +624,13 @@
<param name="linkId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.ArtifactController.RemovePinterestLinkAsync(System.Guid)">
<summary>
remove pinterest link
</summary>
<param name="linkId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.ArtifactController.StartFillingGanjoorLinkOriginalSources">
<summary>
start filling GanjoorLink table OriginalSource values
@ -15204,6 +15218,13 @@
<param name="result"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IArtifactService.RemoveGanjoorLinkAsync(System.Guid)">
<summary>
remove ganjoor link
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IArtifactService.AddTOCForSuggestedLinks">
<summary>
Temporary api
@ -15246,6 +15267,13 @@
<param name="imageUrl"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IArtifactService.RemovePinterestLinkAsync(System.Guid)">
<summary>
remove pinterest link
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IArtifactService.SynchronizeSuggestedPinterestLink(System.Guid)">
<summary>
Synchronize suggested pinterest link
@ -17973,6 +18001,13 @@
<param name="result"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.ArtifactService.RemoveGanjoorLinkAsync(System.Guid)">
<summary>
remove ganjoor link
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.ArtifactService.AddTOCForSuggestedLinks">
<summary>
Temporary api
@ -18015,6 +18050,13 @@
<param name="imageUrl"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.ArtifactService.RemovePinterestLinkAsync(System.Guid)">
<summary>
remove pinterest link
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.ArtifactService.SynchronizeSuggestedPinterestLink(System.Guid)">
<summary>
Synchronize suggested pinterest link

View File

@ -486,6 +486,13 @@ namespace RMuseum.Services
/// <returns></returns>
Task<RServiceResult<bool>> ReviewSuggestedLink(Guid linkId, Guid userId, ReviewResult result);
/// <summary>
/// remove ganjoor link
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<RServiceResult<bool>> RemoveGanjoorLinkAsync(Guid id);
/// <summary>
/// Temporary api
/// </summary>
@ -528,6 +535,13 @@ namespace RMuseum.Services
/// <returns></returns>
Task<RServiceResult<bool>> ReviewSuggestedPinterestLink(Guid linkId, Guid userId, string altText, ReviewResult result, string reviewDesc, string imageUrl);
/// <summary>
/// remove pinterest link
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<RServiceResult<bool>> RemovePinterestLinkAsync(Guid id);
/// <summary>
/// Synchronize suggested pinterest link
/// </summary>

View File

@ -31,6 +31,7 @@ using RSecurityBackend.Models.Notification;
using RMuseum.Models.PDFLibrary;
using Microsoft.Identity.Client;
using Org.BouncyCastle.Utilities.Collections;
using static System.Windows.Forms.LinkLabel;
namespace RMuseum.Services.Implementation
{
@ -155,7 +156,7 @@ namespace RMuseum.Services.Implementation
{
return new RServiceResult<RArtifactMasterRecordViewModel>(null, exp.ToString());
}
}
/// <summary>
@ -185,7 +186,7 @@ namespace RMuseum.Services.Implementation
{
return new RServiceResult<RArtifactItemRecord[]>(null, exp.ToString());
}
}
/// <summary>
@ -1133,7 +1134,7 @@ namespace RMuseum.Services.Implementation
return new RServiceResult<RArtifactItemRecordViewModel>(null);
RArtifactItemRecord item =
RArtifactItemRecord item =
await _context.Items.AsNoTracking().Include(i => i.Images).Include(i => i.Tags).ThenInclude(t => t.RTag).
Where(i => i.RArtifactMasterRecordId == parent.Id && i.FriendlyUrl == itemUrl).SingleAsync();
@ -1298,11 +1299,11 @@ namespace RMuseum.Services.Implementation
var book = await context.Artifacts.Include(a => a.Items).ThenInclude(i => i.Images).Include(a => a.CoverImage).SingleAsync();
await jobProgressServiceEF.UpdateJob(job.Id, 2, $"بارگذاری {book.Name}");
var resUpload = await _UploadArtifactToExternalServer(book, context, skipUpload);
if(!string.IsNullOrEmpty(resUpload.ExceptionString))
if (!string.IsNullOrEmpty(resUpload.ExceptionString))
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, resUpload.ExceptionString);
}
if(!resUpload.Result)
if (!resUpload.Result)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, "_UploadArtifactToExternalServer returned false");
}
@ -1347,7 +1348,7 @@ namespace RMuseum.Services.Implementation
Configuration.GetSection("ExternalFTPServer")["Password"]
);
if (!skipUpload)
{
@ -1355,7 +1356,7 @@ namespace RMuseum.Services.Implementation
await ftpClient.AutoConnect();
ftpClient.Config.RetryAttempts = 3;
}
foreach (var imageSizeString in new string[] { "orig", "norm", "thumb" })
{
@ -1365,14 +1366,14 @@ namespace RMuseum.Services.Implementation
book.CoverImage.ExternalNormalSizeImageUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/{book.CoverImage.FolderName}/orig/{Path.GetFileName(localFilePath)}";
context.Update(book.CoverImage);
}
if(!skipUpload)
if (!skipUpload)
{
await jobProgressServiceEF.UpdateJob(job.Id, 0, localFilePath);
var remoteFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/images/{book.CoverImage.FolderName}/{imageSizeString}/{Path.GetFileName(localFilePath)}";
await ftpClient.UploadFile(localFilePath, remoteFilePath, createRemoteDir: true);
}
}
@ -1388,18 +1389,18 @@ namespace RMuseum.Services.Implementation
image.ExternalNormalSizeImageUrl = $"{Configuration.GetSection("ExternalFTPServer")["RootUrl"]}/{image.FolderName}/orig/{Path.GetFileName(localFilePath)}";
context.Update(image);
}
if(!skipUpload)
if (!skipUpload)
{
await jobProgressServiceEF.UpdateJob(job.Id, 0, localFilePath);
var remoteFilePath = $"{Configuration.GetSection("ExternalFTPServer")["RootPath"]}/images/{book.CoverImage.FolderName}/{imageSizeString}/{Path.GetFileName(localFilePath)}";
await ftpClient.UploadFile(localFilePath, remoteFilePath, createRemoteDir: true);
}
}
}
}
if(!skipUpload)
if (!skipUpload)
{
await ftpClient.Disconnect();
}
@ -3054,6 +3055,28 @@ namespace RMuseum.Services.Implementation
return new RServiceResult<bool>(true);
}
/// <summary>
/// remove ganjoor link
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> RemoveGanjoorLinkAsync(Guid id)
{
try
{
GanjoorLink link =
await _context.GanjoorLinks
.Where(l => l.Id == id)
.SingleAsync();
_context.Remove(link);
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// Temporary api
/// </summary>
@ -3440,6 +3463,28 @@ namespace RMuseum.Services.Implementation
}
}
/// <summary>
/// remove pinterest link
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<RServiceResult<bool>> RemovePinterestLinkAsync(Guid id)
{
try
{
PinterestLink link =
await _context.PinterestLinks
.Where(l => l.Id == id)
.SingleAsync();
_context.Remove(link);
return new RServiceResult<bool>(true);
}
catch (Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
private void FtpClient_ValidateCertificate(FluentFTP.Client.BaseClient.BaseFtpClient control, FtpSslValidationEventArgs e)
{
e.Accept = true;
@ -3648,7 +3693,7 @@ namespace RMuseum.Services.Implementation
RArtifactMasterRecord book = await _context.Artifacts.Where(b => b.FriendlyUrl == artifactFriendlyUrl).SingleAsync();
RArtifactItemRecord firstItem = await _context.Items.AsNoTracking().Where(i => i.RArtifactMasterRecordId == book.Id).FirstOrDefaultAsync();
int zeroPads = 4;
if(firstItem != null)
if (firstItem != null)
{
zeroPads = firstItem.FriendlyUrl.Length - 1; //removing p at the start
}