#168 links to original sources for GanjoorLinks
This commit is contained in:
parent
f8ea77bd5c
commit
247ac7f0f6
@ -1,5 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using RMuseum.Models.Artifact;
|
||||
using RMuseum.Models.Bookmark;
|
||||
using RMuseum.Models.GanjoorAudio;
|
||||
@ -12,7 +11,6 @@ using RSecurityBackend.Models.Auth.Db;
|
||||
using System;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.MusicCatalogue;
|
||||
using System.IO;
|
||||
using RMuseum.Models.Accounting;
|
||||
|
||||
namespace RMuseum.DbContext
|
||||
|
||||
2636
RMuseum/Migrations/20210701101147_GanjoorLink-OriginalSourceUrl.Designer.cs
generated
Normal file
2636
RMuseum/Migrations/20210701101147_GanjoorLink-OriginalSourceUrl.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace RMuseum.Migrations
|
||||
{
|
||||
public partial class GanjoorLinkOriginalSourceUrl : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "LinkToOriginalSource",
|
||||
table: "GanjoorLinks",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "OriginalSourceUrl",
|
||||
table: "GanjoorLinks",
|
||||
type: "nvarchar(max)",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LinkToOriginalSource",
|
||||
table: "GanjoorLinks");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "OriginalSourceUrl",
|
||||
table: "GanjoorLinks");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1128,6 +1128,12 @@ namespace RMuseum.Migrations
|
||||
b.Property<Guid?>("ItemId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<bool>("LinkToOriginalSource")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("OriginalSourceUrl")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ReviewDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
|
||||
@ -93,5 +93,15 @@ namespace RMuseum.Models.GanjoorIntegration
|
||||
/// display this image on poem page
|
||||
/// </summary>
|
||||
public bool DisplayOnPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// original source url
|
||||
/// </summary>
|
||||
public string OriginalSourceUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// link to original source
|
||||
/// </summary>
|
||||
public bool LinkToOriginalSource { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -3751,6 +3751,16 @@
|
||||
display this image on poem page
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorIntegration.GanjoorLink.OriginalSourceUrl">
|
||||
<summary>
|
||||
original source url
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.GanjoorIntegration.GanjoorLink.LinkToOriginalSource">
|
||||
<summary>
|
||||
link to original source
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.GanjoorIntegration.LinkType">
|
||||
<summary>
|
||||
Link Type
|
||||
@ -7668,6 +7678,15 @@
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
</summary>
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartFillingGanjoorLinkOriginalSources">
|
||||
<summary>
|
||||
start updating stats page
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.ArtifactService.StartImportingFromHarvardDirectly(System.String,System.String,System.String)">
|
||||
<summary>
|
||||
|
||||
@ -0,0 +1,90 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RMuseum.DbContext;
|
||||
using RMuseum.Models.Artifact;
|
||||
using RMuseum.Models.ImportJob;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RMuseum.Services.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// IArtifactService implementation
|
||||
/// </summary>
|
||||
public partial class ArtifactService : IArtifactService
|
||||
{
|
||||
/// <summary>
|
||||
/// start updating stats page
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> StartFillingGanjoorLinkOriginalSources()
|
||||
{
|
||||
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("UpdateStatsPage", "Total Poets Stats")).Result;
|
||||
|
||||
try
|
||||
{
|
||||
var links = await context.GanjoorLinks.ToListAsync();
|
||||
|
||||
for (int i = 0; i < links.Count; i++)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, i);
|
||||
|
||||
var link = links[i];
|
||||
|
||||
var itemInfo = await context.Items
|
||||
.Include(i => i.Tags)
|
||||
.ThenInclude(t => t.RTag)
|
||||
.Where(i => i.Id == link.ItemId).SingleAsync();
|
||||
|
||||
var sourceTag = itemInfo.Tags.Where(t => t.RTag.FriendlyUrl == "source").FirstOrDefault();
|
||||
|
||||
if(sourceTag != null)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(sourceTag.ValueSupplement) && (sourceTag.ValueSupplement.IndexOf("http") == 0))
|
||||
{
|
||||
link.OriginalSourceUrl = sourceTag.ValueSupplement;
|
||||
link.LinkToOriginalSource = true;
|
||||
context.GanjoorLinks.Update(link);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1141,7 +1141,7 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
PoemRelatedImageType = PoemRelatedImageType.MuseumLink,
|
||||
ThumbnailImageUrl = $"https://ganjgah.ir/api/images/thumb/{link.Item.Images.First().Id}.jpg",
|
||||
TargetPageUrl = $"https://museum.ganjoor.net/items/{link.Artifact.FriendlyUrl}/{link.Item.FriendlyUrl}",
|
||||
TargetPageUrl = link.LinkToOriginalSource ? link.OriginalSourceUrl : $"https://museum.ganjoor.net/items/{link.Artifact.FriendlyUrl}/{link.Item.FriendlyUrl}",
|
||||
AltText = $"{link.Artifact.Name} » {link.Item.Name}",
|
||||
};
|
||||
List<PoemRelatedImage> museumImages = await museumSrc.ToListAsync();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user