diff --git a/RMuseum/Controllers/ArtifactController.cs b/RMuseum/Controllers/ArtifactController.cs index dcf48e19..a43a8b6f 100644 --- a/RMuseum/Controllers/ArtifactController.cs +++ b/RMuseum/Controllers/ArtifactController.cs @@ -1985,6 +1985,24 @@ public async Task SynchronizeGanjoorLink(Guid linkId, bool displa return Ok(); } + /// + /// remove ganjoor link + /// + /// + /// + [HttpDelete] + [Route("ganjoor")] + [Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task RemoveGanjoorLinkAsync(Guid linkId) + { + RServiceResult suggestion = await _artifactService.RemoveGanjoorLinkAsync(linkId); + if (!string.IsNullOrEmpty(suggestion.ExceptionString)) + return BadRequest(suggestion.ExceptionString); + return Ok(); + } + /// ///toc / temporary one time api / to be removed /// @@ -2082,6 +2100,24 @@ public async Task SynchronizeSuggestedPinterestLink(Guid linkId) return Ok(); } + /// + /// remove pinterest link + /// + /// + /// + [HttpDelete] + [Route("pinterest")] + [Authorize(Policy = RMuseumSecurableItem.ArtifactEntityShortName + ":" + RMuseumSecurableItem.ReviewGanjoorLinksOperationShortName)] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task RemovePinterestLinkAsync(Guid linkId) + { + RServiceResult suggestion = await _artifactService.RemovePinterestLinkAsync(linkId); + if (!string.IsNullOrEmpty(suggestion.ExceptionString)) + return BadRequest(suggestion.ExceptionString); + return Ok(); + } + /// /// start filling GanjoorLink table OriginalSource values /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 318304d6..1134abad 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -578,6 +578,13 @@ display ogn page + + + remove ganjoor link + + + + toc / temporary one time api / to be removed @@ -617,6 +624,13 @@ + + + remove pinterest link + + + + start filling GanjoorLink table OriginalSource values @@ -15204,6 +15218,13 @@ + + + remove ganjoor link + + + + Temporary api @@ -15246,6 +15267,13 @@ + + + remove pinterest link + + + + Synchronize suggested pinterest link @@ -17973,6 +18001,13 @@ + + + remove ganjoor link + + + + Temporary api @@ -18015,6 +18050,13 @@ + + + remove pinterest link + + + + Synchronize suggested pinterest link diff --git a/RMuseum/Services/IArtifactService.cs b/RMuseum/Services/IArtifactService.cs index 21f2da1c..b503b8ea 100644 --- a/RMuseum/Services/IArtifactService.cs +++ b/RMuseum/Services/IArtifactService.cs @@ -486,6 +486,13 @@ Task> Add /// Task> ReviewSuggestedLink(Guid linkId, Guid userId, ReviewResult result); + /// + /// remove ganjoor link + /// + /// + /// + Task> RemoveGanjoorLinkAsync(Guid id); + /// /// Temporary api /// @@ -528,6 +535,13 @@ Task> Add /// Task> ReviewSuggestedPinterestLink(Guid linkId, Guid userId, string altText, ReviewResult result, string reviewDesc, string imageUrl); + /// + /// remove pinterest link + /// + /// + /// + Task> RemovePinterestLinkAsync(Guid id); + /// /// Synchronize suggested pinterest link /// diff --git a/RMuseum/Services/Implementation/ArtifactService.cs b/RMuseum/Services/Implementation/ArtifactService.cs index 933e2969..10b26cb1 100644 --- a/RMuseum/Services/Implementation/ArtifactService.cs +++ b/RMuseum/Services/Implementation/ArtifactService.cs @@ -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 { @@ -155,7 +156,7 @@ await _context.Items.AsNoTracking() { return new RServiceResult(null, exp.ToString()); } - + } /// @@ -185,7 +186,7 @@ await _context.Items.AsNoTracking() { return new RServiceResult(null, exp.ToString()); } - + } /// @@ -1133,7 +1134,7 @@ await _context.Artifacts return new RServiceResult(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 @@ public RServiceResult 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"); } @@ -1347,7 +1348,7 @@ private async Task> _UploadArtifactToExternalServer(RArtifa Configuration.GetSection("ExternalFTPServer")["Password"] ); - + if (!skipUpload) { @@ -1355,7 +1356,7 @@ private async Task> _UploadArtifactToExternalServer(RArtifa await ftpClient.AutoConnect(); ftpClient.Config.RetryAttempts = 3; } - + foreach (var imageSizeString in new string[] { "orig", "norm", "thumb" }) { @@ -1365,14 +1366,14 @@ private async Task> _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); } - + } @@ -1388,18 +1389,18 @@ private async Task> _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(); } @@ -3054,6 +3055,28 @@ await _context.GanjoorLinks return new RServiceResult(true); } + /// + /// remove ganjoor link + /// + /// + /// + public async Task> RemoveGanjoorLinkAsync(Guid id) + { + try + { + GanjoorLink link = + await _context.GanjoorLinks + .Where(l => l.Id == id) + .SingleAsync(); + _context.Remove(link); + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + /// /// Temporary api /// @@ -3440,6 +3463,28 @@ await _context.PinterestLinks } } + /// + /// remove pinterest link + /// + /// + /// + public async Task> RemovePinterestLinkAsync(Guid id) + { + try + { + PinterestLink link = + await _context.PinterestLinks + .Where(l => l.Id == id) + .SingleAsync(); + _context.Remove(link); + return new RServiceResult(true); + } + catch (Exception exp) + { + return new RServiceResult(false, exp.ToString()); + } + } + private void FtpClient_ValidateCertificate(FluentFTP.Client.BaseClient.BaseFtpClient control, FtpSslValidationEventArgs e) { e.Accept = true; @@ -3648,7 +3693,7 @@ public async Task> 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 }