Skip to content

Commit

Permalink
Unlink museum ganjoor and naskban links
Browse files Browse the repository at this point in the history
  • Loading branch information
hrmoh committed Jan 10, 2025
1 parent c87b1e9 commit 88bcc61
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 13 deletions.
36 changes: 36 additions & 0 deletions RMuseum/Controllers/ArtifactController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,24 @@ public async Task<IActionResult> SynchronizeGanjoorLink(Guid linkId, bool displa
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>
Expand Down Expand Up @@ -2082,6 +2100,24 @@ public async Task<IActionResult> SynchronizeSuggestedPinterestLink(Guid linkId)
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>
Expand Down
42 changes: 42 additions & 0 deletions RMuseum/RMuseum.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions RMuseum/Services/IArtifactService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,13 @@ Task<RServiceResult<RArtifactMasterRecord>> Add
/// <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>
Expand Down Expand Up @@ -528,6 +535,13 @@ Task<RServiceResult<RArtifactMasterRecord>> Add
/// <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>
Expand Down
71 changes: 58 additions & 13 deletions RMuseum/Services/Implementation/ArtifactService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using RMuseum.Models.PDFLibrary;
using Microsoft.Identity.Client;
using Org.BouncyCastle.Utilities.Collections;
using static System.Windows.Forms.LinkLabel;

namespace RMuseum.Services.Implementation
{
Expand Down Expand Up @@ -155,7 +156,7 @@ await _context.Items.AsNoTracking()
{
return new RServiceResult<RArtifactMasterRecordViewModel>(null, exp.ToString());
}

}

/// <summary>
Expand Down Expand Up @@ -185,7 +186,7 @@ await _context.Items.AsNoTracking()
{
return new RServiceResult<RArtifactItemRecord[]>(null, exp.ToString());
}

}

/// <summary>
Expand Down Expand Up @@ -1133,7 +1134,7 @@ await _context.Artifacts
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();

Expand Down Expand Up @@ -1298,11 +1299,11 @@ public RServiceResult<bool> StartUploadingArtifactToExternalServer(Guid artifact
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");
}
Expand Down Expand Up @@ -1347,15 +1348,15 @@ private async Task<RServiceResult<bool>> _UploadArtifactToExternalServer(RArtifa
Configuration.GetSection("ExternalFTPServer")["Password"]
);



if (!skipUpload)
{
ftpClient.ValidateCertificate += FtpClient_ValidateCertificate;
await ftpClient.AutoConnect();
ftpClient.Config.RetryAttempts = 3;
}


foreach (var imageSizeString in new string[] { "orig", "norm", "thumb" })
{
Expand All @@ -1365,14 +1366,14 @@ private async Task<RServiceResult<bool>> _UploadArtifactToExternalServer(RArtifa
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);
}

}


Expand All @@ -1388,18 +1389,18 @@ private async Task<RServiceResult<bool>> _UploadArtifactToExternalServer(RArtifa
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();
}
Expand Down Expand Up @@ -3054,6 +3055,28 @@ await _context.GanjoorLinks
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>
Expand Down Expand Up @@ -3440,6 +3463,28 @@ await _context.PinterestLinks
}
}

/// <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;
Expand Down Expand Up @@ -3648,7 +3693,7 @@ public async Task<RServiceResult<RArtifactItemRecord>> AddItemToArtifactAsync(st
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
}
Expand Down

0 comments on commit 88bcc61

Please sign in to comment.