mirror of
https://github.com/svemagie/indiekit-endpoint-microsub.git
synced 2026-04-02 15:35:00 +02:00
fix: add markAllRead function and route
Restore the "Mark all as read" button functionality in channel view. The button form posts to /api/mark-read but the route and controller function were missing from the standalone repo. - Add markAllRead function to reader controller - Add /api/mark-read route to index.js - Import markItemsRead from storage/items.js Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1
index.js
1
index.js
@@ -96,6 +96,7 @@ export default class MicrosubEndpoint {
|
||||
readerRouter.get("/search", readerController.searchPage);
|
||||
readerRouter.post("/search", readerController.searchFeeds);
|
||||
readerRouter.post("/subscribe", readerController.subscribe);
|
||||
readerRouter.post("/api/mark-read", readerController.markAllRead);
|
||||
router.use("/reader", readerRouter);
|
||||
|
||||
return router;
|
||||
|
||||
@@ -17,7 +17,11 @@ import {
|
||||
createFeed,
|
||||
deleteFeed,
|
||||
} from "../storage/feeds.js";
|
||||
import { getTimelineItems, getItemById } from "../storage/items.js";
|
||||
import {
|
||||
getTimelineItems,
|
||||
getItemById,
|
||||
markItemsRead,
|
||||
} from "../storage/items.js";
|
||||
import { getUserId } from "../utils/auth.js";
|
||||
import {
|
||||
validateChannelName,
|
||||
@@ -622,6 +626,33 @@ export async function subscribe(request, response) {
|
||||
response.redirect(`${request.baseUrl}/channels/${channelUid}/feeds`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark all items in channel as read
|
||||
* @param {object} request - Express request
|
||||
* @param {object} response - Express response
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function markAllRead(request, response) {
|
||||
const { application } = request.app.locals;
|
||||
const userId = getUserId(request);
|
||||
const { channel: channelUid } = request.body;
|
||||
|
||||
const channelDocument = await getChannel(application, channelUid, userId);
|
||||
if (!channelDocument) {
|
||||
return response.status(404).render("404");
|
||||
}
|
||||
|
||||
// Mark all items as read using the special "last-read-entry" value
|
||||
await markItemsRead(
|
||||
application,
|
||||
channelDocument._id,
|
||||
["last-read-entry"],
|
||||
userId,
|
||||
);
|
||||
|
||||
response.redirect(`${request.baseUrl}/channels/${channelUid}`);
|
||||
}
|
||||
|
||||
export const readerController = {
|
||||
index,
|
||||
channels,
|
||||
@@ -630,6 +661,7 @@ export const readerController = {
|
||||
channel,
|
||||
settings,
|
||||
updateSettings,
|
||||
markAllRead,
|
||||
deleteChannel: deleteChannelAction,
|
||||
feeds,
|
||||
addFeed,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rmdes/indiekit-endpoint-microsub",
|
||||
"version": "1.0.15",
|
||||
"version": "1.0.16",
|
||||
"description": "Microsub endpoint for Indiekit. Enables subscribing to feeds and reading content using the Microsub protocol.",
|
||||
"keywords": [
|
||||
"indiekit",
|
||||
|
||||
Reference in New Issue
Block a user