monographs: add slug field which regenerates on republish (#72)

* monographs: add slug field which regenerates on update

* monographs: don't regenerate slug on update

* common: fix monograph public url constant

* monographs: improve APIs && use .Project when fetching monographs
* create separate endpoint for fetching monographs by slug
* combine analytics and publish-url endpoint into a publish-info endpoint

* monographs: reinstate analytics endpoint

* common: add missing monograph constant

* monograph: refactoring

---------

Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
This commit is contained in:
01zulfi
2026-03-26 23:14:20 +05:00
committed by GitHub
parent da58262afb
commit 4bc1469dfe
6 changed files with 116 additions and 24 deletions

View File

@@ -32,6 +32,8 @@ using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
using Notesnook.API.Authorization;
using Notesnook.API.Extensions;
using Notesnook.API.Helpers;
using Notesnook.API.Interfaces;
using Notesnook.API.Models;
using Notesnook.API.Services;
@@ -275,15 +277,25 @@ namespace Notesnook.API.Hubs
Builders<Monograph>.Filter.In("_id", unsyncedMonographIds)
)
);
var userMonographs = await Repositories.Monographs.Collection.Find(filter).Project((m) => new MonographMetadata
var userMonographs = await Repositories.Monographs.Collection
.Find(filter)
.Project((m) => new MonographMetadata
{
DatePublished = m.DatePublished,
Deleted = m.Deleted,
Password = m.Password,
SelfDestruct = m.SelfDestruct,
Title = m.Title,
ItemId = m.ItemId ?? m.Id.ToString(),
PublishUrl = m.Slug // this will be converted to full url in the end, but we only need slug for now
})
.ToListAsync();
userMonographs = userMonographs.Select((p) =>
{
DatePublished = m.DatePublished,
Deleted = m.Deleted,
Password = m.Password,
SelfDestruct = m.SelfDestruct,
Title = m.Title,
ItemId = m.ItemId ?? m.Id.ToString()
}).ToListAsync();
p.PublishUrl = UrlHelper.ConstructPublishUrl(p);
return p;
}).ToList();
if (userMonographs.Count > 0 && !await Clients.Caller.SendMonographs(userMonographs).WaitAsync(TimeSpan.FromMinutes(10)))
throw new HubException("Client rejected monographs.");