feedkeeper 0.44.3 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/dist/api/feeds.js +37 -2
- package/server/dist/api/items.js +25 -1
- package/server/dist/api/v1/resources.js +53 -7
- package/server/dist/api/v1/serialize.js +3 -1
- package/server/dist/cli.js +4 -0
- package/server/dist/db/migrations/0049_media_positions_and_feed_moves.sql +13 -0
- package/server/dist/doctor-cli.js +247 -0
- package/server/dist/feedkeeper.js +8 -0
- package/server/dist/feeds/fetcher.js +26 -3
- package/server/dist/feeds/mediaPosition.js +56 -0
- package/server/dist/feeds/poller.js +60 -11
- package/server/dist/feeds/repository.js +20 -9
- package/server/dist/feeds/searchQuery.js +101 -0
- package/server/package.json +1 -1
- package/web/dist/assets/{index-BcKdqdmb.js → index-C-Cqi_Uh.js} +13 -13
- package/web/dist/assets/index-CAofPYDH.css +2 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-DKnVXchH.css +0 -2
package/package.json
CHANGED
package/server/dist/api/feeds.js
CHANGED
|
@@ -2,8 +2,8 @@ import { Router } from "express";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { requireSession } from "../auth/middleware.js";
|
|
4
4
|
import { requireCapability } from "../auth/capabilities.js";
|
|
5
|
-
import { listSubscriptionsForUser, findFeedById, isUserSubscribed, reorderSubscriptions } from "../feeds/repository.js";
|
|
6
|
-
import { subscribeToFeed, unsubscribeFromFeed, updateFeedSettings, FeedError, MultipleFeedsFoundError } from "../feeds/service.js";
|
|
5
|
+
import { listSubscriptionsForUser, findFeedById, findSubscriptionForUser, isUserSubscribed, reorderSubscriptions } from "../feeds/repository.js";
|
|
6
|
+
import { changeFeedUrl, subscribeToFeed, unsubscribeFromFeed, updateFeedSettings, FeedError, MultipleFeedsFoundError } from "../feeds/service.js";
|
|
7
7
|
import { SsrfBlockedError, normalizeUrlCandidate } from "../feeds/ssrfGuard.js";
|
|
8
8
|
import { blockedUrlBody } from "../feeds/blockedHosts.js";
|
|
9
9
|
import { generateOpml, importOpmlFeeds } from "../feeds/opml.js";
|
|
@@ -195,6 +195,41 @@ feedsRouter.post("/:feedId/refresh", requireSync, async (req, res) => {
|
|
|
195
195
|
retryAt: pollResult.retryAt,
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
|
+
feedsRouter.post("/:feedId/accept-move", requireSync, async (req, res) => {
|
|
199
|
+
const feedId = Number(req.params.feedId);
|
|
200
|
+
if (!Number.isInteger(feedId) || feedId <= 0) {
|
|
201
|
+
res.status(400).json({ error: "invalid_feed_id" });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const existing = findSubscriptionForUser(req.user.id, feedId);
|
|
205
|
+
if (!existing) {
|
|
206
|
+
res.status(404).json({ error: "feed_not_found" });
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!existing.suggested_url) {
|
|
210
|
+
res.status(404).json({ error: "no_suggested_url" });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const moved = await changeFeedUrl(req.user.id, feedId, existing.suggested_url);
|
|
215
|
+
res.json({ feed: moved.subscription });
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (error instanceof MultipleFeedsFoundError) {
|
|
219
|
+
res.status(409).json({ error: "multiple_feeds_found", feeds: error.feeds });
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (error instanceof SsrfBlockedError) {
|
|
223
|
+
res.status(400).json(blockedUrlBody(error));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (error instanceof FeedError) {
|
|
227
|
+
res.status(error.message === "not_subscribed" ? 404 : 400).json({ error: error.message });
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
res.status(400).json({ error: "invalid_feed", message: error instanceof Error ? error.message : String(error) });
|
|
231
|
+
}
|
|
232
|
+
});
|
|
198
233
|
feedsRouter.post("/refresh-all", requireSync, async (req, res) => {
|
|
199
234
|
const subs = listSubscriptionsForUser(req.user.id);
|
|
200
235
|
const { newItems: totalNewItems, errors: errorCount, deferred } = await pollFeeds(subs);
|
package/server/dist/api/items.js
CHANGED
|
@@ -3,9 +3,11 @@ import { Router } from "express";
|
|
|
3
3
|
import rateLimit from "express-rate-limit";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { requireSession } from "../auth/middleware.js";
|
|
6
|
-
import {
|
|
6
|
+
import { requireCapability } from "../auth/capabilities.js";
|
|
7
|
+
import { canAccessItem, listItemsForUser, markAllRead, markItemRead, markItemUnread, bookmarkItem, unbookmarkItem, findItemById, } from "../feeds/repository.js";
|
|
7
8
|
import { loadFullText } from "../feeds/fullText.js";
|
|
8
9
|
import { loadItemChapters } from "../feeds/chapters.js";
|
|
10
|
+
import { mediaPositions, upsertMediaPosition } from "../feeds/mediaPosition.js";
|
|
9
11
|
import { readerHtml } from "../feeds/articleContent.js";
|
|
10
12
|
import { cleanSnippet } from "../feeds/contentNoise.js";
|
|
11
13
|
import { fetchItemImage, pruneArchive, scheduleArchive, withArchivedImages, withProxiedImages } from "../feeds/archive.js";
|
|
@@ -47,6 +49,7 @@ itemsRouter.get("/", (req, res) => {
|
|
|
47
49
|
const archived = withArchivedImages(listItemsForUser(req.user.id, parsed.data), origin);
|
|
48
50
|
// Offline copies also get the images of articles that are not archived, through this server.
|
|
49
51
|
const items = parsed.data.offline ? withProxiedImages(archived, origin) : archived;
|
|
52
|
+
const positions = mediaPositions(req.user.id, items.map((item) => item.id));
|
|
50
53
|
res.json(items.map(({ content_lead: _lead, lead_version: _leadVersion, ...item }) => ({
|
|
51
54
|
...item,
|
|
52
55
|
content_snippet: cleanSnippet(item.content_snippet, item.title),
|
|
@@ -54,6 +57,7 @@ itemsRouter.get("/", (req, res) => {
|
|
|
54
57
|
full_content_html: readerHtml(item.full_content_html, item.title, item.author, item.link),
|
|
55
58
|
read: Boolean(item.read),
|
|
56
59
|
bookmarked: Boolean(item.bookmarked),
|
|
60
|
+
media_position: positions.get(item.id) ?? null,
|
|
57
61
|
})));
|
|
58
62
|
});
|
|
59
63
|
const imageLimiter = rateLimit({ windowMs: 60 * 1000, limit: 600, standardHeaders: true, legacyHeaders: false });
|
|
@@ -150,4 +154,24 @@ itemsRouter.get("/:itemId/chapters", async (req, res) => {
|
|
|
150
154
|
}
|
|
151
155
|
res.json({ chapters: result.chapters });
|
|
152
156
|
});
|
|
157
|
+
const mediaPositionSchema = z.object({
|
|
158
|
+
positionSeconds: z.number().min(0).max(864_000),
|
|
159
|
+
durationSeconds: z.number().min(0).max(864_000).nullable().optional(),
|
|
160
|
+
completed: z.boolean().optional(),
|
|
161
|
+
updatedAt: z.string().datetime().optional(),
|
|
162
|
+
});
|
|
163
|
+
itemsRouter.put("/:itemId/media-position", requireCapability("sync"), (req, res) => {
|
|
164
|
+
const itemId = Number(req.params.itemId);
|
|
165
|
+
if (!Number.isInteger(itemId) || itemId <= 0 || !canAccessItem(req.user.id, itemId)) {
|
|
166
|
+
res.status(404).json({ error: "item_not_found" });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const parsed = mediaPositionSchema.safeParse(req.body ?? {});
|
|
170
|
+
if (!parsed.success) {
|
|
171
|
+
res.status(400).json({ error: "invalid_input", details: parsed.error.flatten() });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const saved = upsertMediaPosition(req.user.id, itemId, parsed.data);
|
|
175
|
+
res.json({ itemId, ...saved });
|
|
176
|
+
});
|
|
153
177
|
//# sourceMappingURL=items.js.map
|
|
@@ -22,6 +22,7 @@ import { MAX_SUBSCRIPTION_BATCH, fetchStatusFor, subscribeBatch } from "../../fe
|
|
|
22
22
|
import { buildOverview } from "../../mcp/digest.js";
|
|
23
23
|
import { decodeCursor, encodeCursor } from "../../mcp/items.js";
|
|
24
24
|
import { readingPositions, serializeItem, serializeSubscriptionDetail } from "./serialize.js";
|
|
25
|
+
import { mediaPositions, upsertMediaPosition } from "../../feeds/mediaPosition.js";
|
|
25
26
|
import { dismissEdition, editionCandidates, ensureEditionSchema, getEdition, getEditionState } from "../../native/editions.js";
|
|
26
27
|
import { getEditionFeedback, resetEditionFeedback, setEditionFeedback } from "../../native/editionFeedback.js";
|
|
27
28
|
import { getNativePreferences, patchNativePreferences } from "../../native/preferences.js";
|
|
@@ -169,6 +170,27 @@ resourcesRouter.post("/subscriptions/:id/refresh", requireCapability("sync"), as
|
|
|
169
170
|
return void res.status(404).json({ error: "not_found" });
|
|
170
171
|
res.json(result);
|
|
171
172
|
});
|
|
173
|
+
resourcesRouter.post("/subscriptions/:id/accept-move", requireCapability("sync"), async (req, res) => {
|
|
174
|
+
const id = Number(req.params.id);
|
|
175
|
+
const existing = findSubscriptionForUser(req.user.id, id);
|
|
176
|
+
if (!existing)
|
|
177
|
+
return void res.status(404).json({ error: "not_found" });
|
|
178
|
+
if (!existing.suggested_url)
|
|
179
|
+
return void res.status(404).json({ error: "no_suggested_url" });
|
|
180
|
+
try {
|
|
181
|
+
const moved = await changeFeedUrl(req.user.id, id, existing.suggested_url);
|
|
182
|
+
res.json({ subscription: subscriptionOf(req.user.id, moved.subscription.id) });
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof MultipleFeedsFoundError)
|
|
186
|
+
return void res.status(409).json({ error: "multiple_feeds_found", feeds: error.feeds });
|
|
187
|
+
if (error instanceof SsrfBlockedError)
|
|
188
|
+
return void res.status(400).json(blockedUrlBody(error));
|
|
189
|
+
if (error instanceof FeedError)
|
|
190
|
+
return void res.status(error.message === "not_subscribed" ? 404 : 400).json({ error: error.message });
|
|
191
|
+
res.status(400).json({ error: "invalid_feed", message: error instanceof Error ? error.message : String(error) });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
172
194
|
resourcesRouter.post("/refresh", requireCapability("sync"), async (req, res) => {
|
|
173
195
|
const subscriptions = listSubscriptionsForUser(req.user.id);
|
|
174
196
|
const { newItems, errors, deferred } = await pollFeeds(subscriptions);
|
|
@@ -367,11 +389,12 @@ resourcesRouter.get("/search", requireCapability("search.fts"), (req, res) => {
|
|
|
367
389
|
offset: query.offset,
|
|
368
390
|
});
|
|
369
391
|
const progress = readingPositions(req.user.id, rows.map((row) => row.id));
|
|
392
|
+
const mediaProgress = mediaPositions(req.user.id, rows.map((row) => row.id));
|
|
370
393
|
const hasNotes = itemsWithNotes(req.user.id, rows.map((row) => row.id));
|
|
371
394
|
res.json({
|
|
372
395
|
query: query.q,
|
|
373
396
|
total,
|
|
374
|
-
items: prepare(rows, req, query.images, withContent).map((row) => serializeItem(row, progress, withContent, hasNotes.has(row.id))),
|
|
397
|
+
items: prepare(rows, req, query.images, withContent).map((row) => serializeItem(row, progress, withContent, hasNotes.has(row.id), mediaProgress)),
|
|
375
398
|
});
|
|
376
399
|
});
|
|
377
400
|
resourcesRouter.get("/items", (req, res) => {
|
|
@@ -403,9 +426,10 @@ resourcesRouter.get("/items", (req, res) => {
|
|
|
403
426
|
const hasMore = rows.length > limit;
|
|
404
427
|
const page = rows.slice(0, limit);
|
|
405
428
|
const progress = readingPositions(req.user.id, page.map((row) => row.id));
|
|
429
|
+
const mediaProgress = mediaPositions(req.user.id, page.map((row) => row.id));
|
|
406
430
|
const hasNotes = itemsWithNotes(req.user.id, page.map((row) => row.id));
|
|
407
431
|
res.json({
|
|
408
|
-
items: prepare(page, req, query.images, withContent).map((row) => serializeItem(row, progress, withContent, hasNotes.has(row.id))),
|
|
432
|
+
items: prepare(page, req, query.images, withContent).map((row) => serializeItem(row, progress, withContent, hasNotes.has(row.id), mediaProgress)),
|
|
409
433
|
newestCursor: page[0] ? encodeCursor(page[0]) : null,
|
|
410
434
|
nextCursor: hasMore && page.length ? encodeCursor(page[page.length - 1]) : null,
|
|
411
435
|
});
|
|
@@ -419,8 +443,9 @@ resourcesRouter.get("/items/bundle", (req, res) => {
|
|
|
419
443
|
const byId = new Map(findItemsForUser(req.user.id, ids).map((row) => [row.id, row]));
|
|
420
444
|
const rows = ids.map((id) => byId.get(id)).filter((row) => Boolean(row));
|
|
421
445
|
const progress = readingPositions(req.user.id, rows.map((row) => row.id));
|
|
446
|
+
const mediaProgress = mediaPositions(req.user.id, rows.map((row) => row.id));
|
|
422
447
|
const hasNotes = itemsWithNotes(req.user.id, rows.map((row) => row.id));
|
|
423
|
-
res.json({ items: prepare(rows, req, parsed.data.images, true).map((row) => serializeItem(row, progress, true, hasNotes.has(row.id))) });
|
|
448
|
+
res.json({ items: prepare(rows, req, parsed.data.images, true).map((row) => serializeItem(row, progress, true, hasNotes.has(row.id), mediaProgress)) });
|
|
424
449
|
});
|
|
425
450
|
// Explicit extraction side effect; read-only devices continue to consume the shared cache.
|
|
426
451
|
resourcesRouter.post("/items/prepare", requireCapability("fulltext"), async (req, res) => {
|
|
@@ -444,8 +469,9 @@ resourcesRouter.get("/items/:id", (req, res) => {
|
|
|
444
469
|
if (!row)
|
|
445
470
|
return void res.status(404).json({ error: "item_not_found" });
|
|
446
471
|
const progress = readingPositions(req.user.id, [row.id]);
|
|
472
|
+
const mediaProgress = mediaPositions(req.user.id, [row.id]);
|
|
447
473
|
const hasNotes = itemsWithNotes(req.user.id, [row.id]);
|
|
448
|
-
res.json(serializeItem(prepare([row], req, parsed.data.images)[0], progress, true, hasNotes.has(row.id)));
|
|
474
|
+
res.json(serializeItem(prepare([row], req, parsed.data.images)[0], progress, true, hasNotes.has(row.id), mediaProgress));
|
|
449
475
|
});
|
|
450
476
|
resourcesRouter.get("/items/:id/chapters", async (req, res) => {
|
|
451
477
|
const id = Number(req.params.id);
|
|
@@ -458,6 +484,23 @@ resourcesRouter.get("/items/:id/chapters", async (req, res) => {
|
|
|
458
484
|
return void res.status(502).json({ error: "chapters_unavailable" });
|
|
459
485
|
res.json({ chapters: result.chapters });
|
|
460
486
|
});
|
|
487
|
+
const mediaPositionSchema = z.object({
|
|
488
|
+
positionSeconds: z.number().min(0).max(864_000),
|
|
489
|
+
durationSeconds: z.number().min(0).max(864_000).nullable().optional(),
|
|
490
|
+
completed: z.boolean().optional(),
|
|
491
|
+
updatedAt: z.string().datetime().optional(),
|
|
492
|
+
});
|
|
493
|
+
resourcesRouter.put("/items/:id/media-position", requireCapability("sync"), (req, res) => {
|
|
494
|
+
const id = Number(req.params.id);
|
|
495
|
+
if (!Number.isInteger(id) || id <= 0 || !canAccessItem(req.user.id, id)) {
|
|
496
|
+
return void res.status(404).json({ error: "item_not_found" });
|
|
497
|
+
}
|
|
498
|
+
const parsed = mediaPositionSchema.safeParse(req.body ?? {});
|
|
499
|
+
if (!parsed.success)
|
|
500
|
+
return invalid(res, parsed.error.flatten());
|
|
501
|
+
const saved = upsertMediaPosition(req.user.id, id, parsed.data);
|
|
502
|
+
res.json({ itemId: id, ...saved });
|
|
503
|
+
});
|
|
461
504
|
resourcesRouter.post("/items/:id/full-text", requireCapability("fulltext"), async (req, res) => {
|
|
462
505
|
const id = Number(req.params.id);
|
|
463
506
|
const result = await loadFullText(req.user.id, id, { force: req.query.force === "true" });
|
|
@@ -465,8 +508,9 @@ resourcesRouter.post("/items/:id/full-text", requireCapability("fulltext"), asyn
|
|
|
465
508
|
return void res.status(FULL_TEXT_STATUS[result.error]).json({ error: result.error, ...(result.error === "capability_not_available" ? { capability: "fulltext" } : {}), ...(result.message ? { message: result.message } : {}) });
|
|
466
509
|
}
|
|
467
510
|
const row = findItemForUser(req.user.id, id);
|
|
511
|
+
const mediaProgress = mediaPositions(req.user.id, [id]);
|
|
468
512
|
const hasNotes = itemsWithNotes(req.user.id, [id]);
|
|
469
|
-
res.json(serializeItem(prepare([row], req, req.query.images === "proxy" ? "proxy" : "original")[0], readingPositions(req.user.id, [id]), true, hasNotes.has(id)));
|
|
513
|
+
res.json(serializeItem(prepare([row], req, req.query.images === "proxy" ? "proxy" : "original")[0], readingPositions(req.user.id, [id]), true, hasNotes.has(id), mediaProgress));
|
|
470
514
|
});
|
|
471
515
|
const readAllSchema = z.object({ subscriptionId: z.number().int().positive().optional(), folderId: z.number().int().positive().optional() });
|
|
472
516
|
resourcesRouter.post("/items/read-all", requireCapability("sync"), (req, res) => {
|
|
@@ -563,11 +607,12 @@ function editionResponse(req, edition) {
|
|
|
563
607
|
.map((id) => byId.get(id))
|
|
564
608
|
.filter((row) => Boolean(row));
|
|
565
609
|
const progress = readingPositions(req.user.id, rows.map((r) => r.id));
|
|
610
|
+
const mediaProgress = mediaPositions(req.user.id, rows.map((r) => r.id));
|
|
566
611
|
const hasNotes = itemsWithNotes(req.user.id, rows.map((r) => r.id));
|
|
567
612
|
const prepared = prepare(rows, req, req.query.images === "proxy" ? "proxy" : "original", false);
|
|
568
613
|
return {
|
|
569
614
|
...edition,
|
|
570
|
-
items: prepared.map((row) => serializeItem(row, progress, false, hasNotes.has(row.id))),
|
|
615
|
+
items: prepared.map((row) => serializeItem(row, progress, false, hasNotes.has(row.id), mediaProgress)),
|
|
571
616
|
};
|
|
572
617
|
}
|
|
573
618
|
function nativeAction(res, action) {
|
|
@@ -676,8 +721,9 @@ resourcesRouter.post("/inbox", requireCapability("inbox"), async (req, res) => {
|
|
|
676
721
|
try {
|
|
677
722
|
const result = await saveToInbox(req.user.id, parsed.data);
|
|
678
723
|
const progress = readingPositions(req.user.id, [result.itemId]);
|
|
724
|
+
const mediaProgress = mediaPositions(req.user.id, [result.itemId]);
|
|
679
725
|
const prepared = prepare([result.item], req, "original");
|
|
680
|
-
res.status(201).json(serializeItem(prepared[0], progress, true, result.hasNote));
|
|
726
|
+
res.status(201).json(serializeItem(prepared[0], progress, true, result.hasNote, mediaProgress));
|
|
681
727
|
}
|
|
682
728
|
catch (error) {
|
|
683
729
|
if (error instanceof SsrfBlockedError) {
|
|
@@ -13,6 +13,7 @@ export function serializeSubscriptionDetail(subscription) {
|
|
|
13
13
|
lastSuccessAt: subscription.last_success_at,
|
|
14
14
|
lastError: subscription.last_error,
|
|
15
15
|
consecutiveErrors: subscription.consecutive_errors,
|
|
16
|
+
suggestedUrl: subscription.suggested_url ?? null,
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
export function readingPositions(userId, itemIds) {
|
|
@@ -23,7 +24,7 @@ export function readingPositions(userId, itemIds) {
|
|
|
23
24
|
.all(userId, ...itemIds);
|
|
24
25
|
return new Map(rows.map((row) => [row.item_id, row.position]));
|
|
25
26
|
}
|
|
26
|
-
export function serializeItem(row, progress, withContent, hasNote = false) {
|
|
27
|
+
export function serializeItem(row, progress, withContent, hasNote = false, mediaProgress) {
|
|
27
28
|
return {
|
|
28
29
|
id: row.id,
|
|
29
30
|
subscriptionId: row.feed_id,
|
|
@@ -51,6 +52,7 @@ export function serializeItem(row, progress, withContent, hasNote = false) {
|
|
|
51
52
|
savedAt: row.bookmarked_at ?? null,
|
|
52
53
|
archivedAt: row.archived_at ?? null,
|
|
53
54
|
progress: progress.get(row.id) ?? null,
|
|
55
|
+
mediaPosition: mediaProgress?.get(row.id) ?? null,
|
|
54
56
|
hasNote,
|
|
55
57
|
},
|
|
56
58
|
};
|
package/server/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ export const HELP = `FeedKeeper: a self-hosted RSS reader and remote MCP server
|
|
|
7
7
|
Usage:
|
|
8
8
|
feedkeeper [options] Start the server
|
|
9
9
|
feedkeeper mcp [options] Start in stdio MCP mode
|
|
10
|
+
feedkeeper doctor [options] Check configuration, paths, and SQLite health
|
|
10
11
|
feedkeeper backup <file> Back up the database (see docs for restore)
|
|
11
12
|
feedkeeper restore <file> --force Restore the database from a backup
|
|
12
13
|
|
|
@@ -73,6 +74,9 @@ export function parseArgs(argv) {
|
|
|
73
74
|
else if (options.action === "start" && argument === "mcp") {
|
|
74
75
|
options.action = "mcp";
|
|
75
76
|
}
|
|
77
|
+
else if (options.action === "start" && argument === "doctor") {
|
|
78
|
+
options.action = "doctor";
|
|
79
|
+
}
|
|
76
80
|
else if (options.action === "start" && (argument === "backup" || argument === "restore")) {
|
|
77
81
|
options.action = argument;
|
|
78
82
|
options.forwarded.push(argument);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS item_media_positions (
|
|
2
|
+
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
3
|
+
item_id INTEGER NOT NULL REFERENCES items(id) ON DELETE CASCADE,
|
|
4
|
+
position_seconds INTEGER NOT NULL DEFAULT 0,
|
|
5
|
+
duration_seconds INTEGER,
|
|
6
|
+
completed INTEGER NOT NULL DEFAULT 0,
|
|
7
|
+
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
8
|
+
PRIMARY KEY (user_id, item_id)
|
|
9
|
+
);
|
|
10
|
+
CREATE INDEX IF NOT EXISTS idx_item_media_positions_user_updated ON item_media_positions(user_id, updated_at);
|
|
11
|
+
|
|
12
|
+
ALTER TABLE feeds ADD COLUMN suggested_url TEXT;
|
|
13
|
+
ALTER TABLE feeds ADD COLUMN suggested_url_checked_at TEXT;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import Database from "better-sqlite3";
|
|
2
|
+
import { constants, accessSync, existsSync, readFileSync, readdirSync, statfsSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { APP_VERSION } from "./version.js";
|
|
7
|
+
const MIN_DISK_BYTES = 100 * 1024 * 1024; // 100 MiB
|
|
8
|
+
function parseSemver(version) {
|
|
9
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
|
|
10
|
+
if (!match)
|
|
11
|
+
return null;
|
|
12
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
13
|
+
}
|
|
14
|
+
export function isSupportedNodeVersion(version) {
|
|
15
|
+
const parsed = parseSemver(version);
|
|
16
|
+
if (!parsed)
|
|
17
|
+
return false;
|
|
18
|
+
const [major, minor, patch] = parsed;
|
|
19
|
+
if (major === 22)
|
|
20
|
+
return minor > 22 || (minor === 22 && patch >= 2);
|
|
21
|
+
if (major === 24)
|
|
22
|
+
return minor > 15 || (minor === 15 && patch >= 0);
|
|
23
|
+
return major >= 26;
|
|
24
|
+
}
|
|
25
|
+
function nearestExistingDir(target) {
|
|
26
|
+
let current = resolve(target);
|
|
27
|
+
while (!existsSync(current)) {
|
|
28
|
+
const parent = dirname(current);
|
|
29
|
+
if (parent === current)
|
|
30
|
+
return null;
|
|
31
|
+
current = parent;
|
|
32
|
+
}
|
|
33
|
+
return current;
|
|
34
|
+
}
|
|
35
|
+
function isWritable(target) {
|
|
36
|
+
const existing = nearestExistingDir(target);
|
|
37
|
+
if (!existing)
|
|
38
|
+
return { writable: false, existing: null };
|
|
39
|
+
try {
|
|
40
|
+
accessSync(existing, constants.R_OK | constants.W_OK);
|
|
41
|
+
return { writable: true, existing };
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return { writable: false, existing };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function formatMiB(bytes) {
|
|
48
|
+
return `${Math.round(bytes / (1024 * 1024))} MiB`;
|
|
49
|
+
}
|
|
50
|
+
/** Runs read-only diagnostics on the runtime, configuration, storage paths, and SQLite database. */
|
|
51
|
+
export function runDoctor(options = {}) {
|
|
52
|
+
const env = options.env ?? process.env;
|
|
53
|
+
const cwd = options.cwd ?? process.cwd();
|
|
54
|
+
const home = options.home ?? homedir();
|
|
55
|
+
const nodeVersion = options.nodeVersion ?? process.versions.node;
|
|
56
|
+
const checks = [];
|
|
57
|
+
if (isSupportedNodeVersion(nodeVersion)) {
|
|
58
|
+
checks.push({ name: "Node.js", status: "pass", detail: `v${nodeVersion} (supported)` });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
checks.push({
|
|
62
|
+
name: "Node.js",
|
|
63
|
+
status: "fail",
|
|
64
|
+
detail: `v${nodeVersion} is unsupported (requires ^22.22.2 || ^24.15.0 || >=26.0.0)`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const configuredDb = env.DATABASE_PATH?.trim();
|
|
68
|
+
const dataDir = resolve(options.dataDir ?? (env.FEEDKEEPER_DATA_DIR?.trim() || (configuredDb ? dirname(resolve(configuredDb)) : join(home, ".feedkeeper"))));
|
|
69
|
+
const databasePath = options.dataDir !== undefined || !configuredDb ? join(dataDir, "feedkeeper.sqlite") : resolve(configuredDb);
|
|
70
|
+
const archivePath = env.ARCHIVE_PATH?.trim() ? resolve(env.ARCHIVE_PATH.trim()) : join(dirname(databasePath), "archive");
|
|
71
|
+
const imageCachePath = env.IMAGE_CACHE_PATH?.trim() ? resolve(env.IMAGE_CACHE_PATH.trim()) : join(dirname(databasePath), "image-cache");
|
|
72
|
+
const envSecret = env.SESSION_SECRET?.trim() ?? "";
|
|
73
|
+
const secretFilePath = join(dataDir, "session-secret");
|
|
74
|
+
let fileSecret = "";
|
|
75
|
+
if (!envSecret && existsSync(secretFilePath)) {
|
|
76
|
+
try {
|
|
77
|
+
fileSecret = readFileSync(secretFilePath, "utf8").trim();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
checks.push({
|
|
81
|
+
name: "SESSION_SECRET",
|
|
82
|
+
status: "fail",
|
|
83
|
+
detail: `Could not read ${secretFilePath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const effectiveSecret = envSecret || fileSecret;
|
|
88
|
+
if (effectiveSecret) {
|
|
89
|
+
const source = envSecret ? "environment" : secretFilePath;
|
|
90
|
+
if (effectiveSecret.length < 32) {
|
|
91
|
+
checks.push({
|
|
92
|
+
name: "SESSION_SECRET",
|
|
93
|
+
status: "warn",
|
|
94
|
+
detail: `Set via ${source}, but shorter than 32 characters`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
checks.push({ name: "SESSION_SECRET", status: "pass", detail: `Configured via ${source}` });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (!checks.some(check => check.name === "SESSION_SECRET")) {
|
|
102
|
+
const envFile = resolve(cwd, ".env");
|
|
103
|
+
checks.push({
|
|
104
|
+
name: "SESSION_SECRET",
|
|
105
|
+
status: "warn",
|
|
106
|
+
detail: existsSync(envFile)
|
|
107
|
+
? `Not set in ${envFile} or ${secretFilePath} (generated on first start in CLI mode)`
|
|
108
|
+
: "Not set (generated on first start in CLI mode; set explicitly for Docker/production)",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const publicUrl = (options.publicUrl ?? env.PUBLIC_URL?.trim()) || `http://localhost:${env.PORT?.trim() || 3000}`;
|
|
112
|
+
try {
|
|
113
|
+
const parsed = new URL(publicUrl);
|
|
114
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
115
|
+
checks.push({ name: "PUBLIC_URL", status: "fail", detail: `Invalid protocol "${parsed.protocol}" in ${publicUrl}` });
|
|
116
|
+
}
|
|
117
|
+
else if ((env.NODE_ENV ?? "production") === "production" && parsed.hostname === "localhost" && !env.PUBLIC_URL?.trim()) {
|
|
118
|
+
checks.push({ name: "PUBLIC_URL", status: "warn", detail: `Defaults to ${publicUrl} (set PUBLIC_URL for remote access or OAuth)` });
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
checks.push({ name: "PUBLIC_URL", status: "pass", detail: publicUrl });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
checks.push({ name: "PUBLIC_URL", status: "fail", detail: `Invalid URL "${publicUrl}"` });
|
|
126
|
+
}
|
|
127
|
+
for (const [label, target] of [
|
|
128
|
+
["Data directory", dataDir],
|
|
129
|
+
["Archive directory", archivePath],
|
|
130
|
+
["Image cache directory", imageCachePath],
|
|
131
|
+
]) {
|
|
132
|
+
const access = isWritable(target);
|
|
133
|
+
if (access.writable) {
|
|
134
|
+
const suffix = existsSync(target) ? "" : ` (will be created under ${access.existing})`;
|
|
135
|
+
checks.push({ name: label, status: "pass", detail: `${target} is writable${suffix}` });
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
checks.push({
|
|
139
|
+
name: label,
|
|
140
|
+
status: "fail",
|
|
141
|
+
detail: `${target} is not writable${access.existing ? ` (checked ${access.existing})` : ""}`,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const diskTarget = nearestExistingDir(dataDir);
|
|
146
|
+
if (diskTarget) {
|
|
147
|
+
try {
|
|
148
|
+
const stats = statfsSync(diskTarget);
|
|
149
|
+
const freeBytes = Number(stats.bavail) * Number(stats.bsize);
|
|
150
|
+
if (freeBytes < MIN_DISK_BYTES) {
|
|
151
|
+
checks.push({ name: "Disk space", status: "warn", detail: `Only ${formatMiB(freeBytes)} free on ${diskTarget}` });
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
checks.push({ name: "Disk space", status: "pass", detail: `${formatMiB(freeBytes)} free on ${diskTarget}` });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
checks.push({
|
|
159
|
+
name: "Disk space",
|
|
160
|
+
status: "warn",
|
|
161
|
+
detail: `Could not inspect free space on ${diskTarget}: ${error instanceof Error ? error.message : String(error)}`,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (!existsSync(databasePath)) {
|
|
166
|
+
checks.push({
|
|
167
|
+
name: "SQLite database",
|
|
168
|
+
status: "warn",
|
|
169
|
+
detail: `${databasePath} does not exist yet (will be initialized on first start)`,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
let db = null;
|
|
174
|
+
try {
|
|
175
|
+
db = new Database(databasePath, { readonly: true, fileMustExist: true });
|
|
176
|
+
const integrity = db.pragma("quick_check", { simple: true });
|
|
177
|
+
if (integrity !== "ok") {
|
|
178
|
+
checks.push({ name: "SQLite database", status: "fail", detail: `${databasePath} failed quick_check: ${String(integrity)}` });
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const hasMigrations = db
|
|
182
|
+
.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = '_migrations'")
|
|
183
|
+
.get();
|
|
184
|
+
if (!hasMigrations) {
|
|
185
|
+
checks.push({
|
|
186
|
+
name: "SQLite database",
|
|
187
|
+
status: "warn",
|
|
188
|
+
detail: `${databasePath} passed quick_check, but has no _migrations table yet`,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const applied = db.prepare("SELECT COUNT(*) AS count FROM _migrations").get()?.count ?? 0;
|
|
193
|
+
const migrationsDir = join(dirname(fileURLToPath(import.meta.url)), "db", "migrations");
|
|
194
|
+
const available = existsSync(migrationsDir)
|
|
195
|
+
? readdirSync(migrationsDir).filter(file => file.endsWith(".sql")).length
|
|
196
|
+
: applied;
|
|
197
|
+
const migrationInfo = applied < available ? `${applied}/${available} migrations applied` : `${applied} migrations applied`;
|
|
198
|
+
checks.push({ name: "SQLite database", status: "pass", detail: `${databasePath} ok (${migrationInfo})` });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
checks.push({
|
|
204
|
+
name: "SQLite database",
|
|
205
|
+
status: "fail",
|
|
206
|
+
detail: `Could not open ${databasePath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
db?.close();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
version: APP_VERSION,
|
|
215
|
+
ok: checks.every(check => check.status !== "fail"),
|
|
216
|
+
checks,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export function formatDoctorReport(report) {
|
|
220
|
+
const tags = {
|
|
221
|
+
pass: "PASS",
|
|
222
|
+
warn: "WARN",
|
|
223
|
+
fail: "FAIL",
|
|
224
|
+
};
|
|
225
|
+
const lines = [`FeedKeeper doctor v${report.version}`, ""];
|
|
226
|
+
for (const check of report.checks) {
|
|
227
|
+
lines.push(`[${tags[check.status]}] ${check.name}: ${check.detail}`);
|
|
228
|
+
}
|
|
229
|
+
const fails = report.checks.filter(check => check.status === "fail").length;
|
|
230
|
+
const warns = report.checks.filter(check => check.status === "warn").length;
|
|
231
|
+
lines.push("");
|
|
232
|
+
lines.push(report.ok ? `Summary: ok (${warns} warning${warns === 1 ? "" : "s"})` : `Summary: ${fails} failed, ${warns} warning${warns === 1 ? "" : "s"}`);
|
|
233
|
+
return lines.join("\n");
|
|
234
|
+
}
|
|
235
|
+
export function runDoctorCli(options = {}) {
|
|
236
|
+
const envFile = resolve(options.cwd ?? process.cwd(), ".env");
|
|
237
|
+
if (existsSync(envFile) && !options.env) {
|
|
238
|
+
process.loadEnvFile(envFile);
|
|
239
|
+
}
|
|
240
|
+
const report = runDoctor(options);
|
|
241
|
+
console.log(formatDoctorReport(report));
|
|
242
|
+
return report.ok ? 0 : 1;
|
|
243
|
+
}
|
|
244
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
245
|
+
process.exitCode = runDoctorCli();
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=doctor-cli.js.map
|
|
@@ -14,6 +14,14 @@ async function main() {
|
|
|
14
14
|
const envFile = resolve(process.cwd(), ".env");
|
|
15
15
|
if (existsSync(envFile))
|
|
16
16
|
process.loadEnvFile(envFile);
|
|
17
|
+
if (options.action === "doctor") {
|
|
18
|
+
const { runDoctorCli } = await import("./doctor-cli.js");
|
|
19
|
+
process.exitCode = runDoctorCli({
|
|
20
|
+
dataDir: options.dataDir,
|
|
21
|
+
publicUrl: options.publicUrl,
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
17
25
|
const prepared = prepareEnvironment(options, process.env);
|
|
18
26
|
if (options.action === "backup" || options.action === "restore") {
|
|
19
27
|
process.argv.splice(2, process.argv.length, ...options.forwarded);
|
|
@@ -100,6 +100,8 @@ async function validateUrl(url, signal) {
|
|
|
100
100
|
// its first slot in the shared gate, so a busy gate cannot use it up; waiting for a slot has its own limit (the poll attempt deadline).
|
|
101
101
|
async function downloadPublic(url, opts) {
|
|
102
102
|
let currentUrl = url;
|
|
103
|
+
let permanentChain = true;
|
|
104
|
+
let permanentRedirectUrl;
|
|
103
105
|
const controller = new AbortController();
|
|
104
106
|
const settings = readPollSettings();
|
|
105
107
|
let timeout;
|
|
@@ -133,14 +135,27 @@ async function downloadPublic(url, opts) {
|
|
|
133
135
|
feedRequests.defer(host, rateLimitUntil);
|
|
134
136
|
if (response.status === 304) {
|
|
135
137
|
await response.body?.cancel();
|
|
136
|
-
return {
|
|
138
|
+
return {
|
|
139
|
+
notModified: true,
|
|
140
|
+
buffer: Buffer.alloc(0),
|
|
141
|
+
finalUrl: currentUrl,
|
|
142
|
+
contentType: response.headers.get("content-type") ?? undefined,
|
|
143
|
+
...(permanentRedirectUrl && permanentRedirectUrl !== url ? { permanentRedirectUrl } : {}),
|
|
144
|
+
};
|
|
137
145
|
}
|
|
138
146
|
if (response.status >= 300 && response.status < 400) {
|
|
139
147
|
const location = response.headers.get("location");
|
|
140
148
|
await response.body?.cancel();
|
|
141
149
|
if (!location)
|
|
142
150
|
throw new Error("Redirect without a Location header");
|
|
143
|
-
|
|
151
|
+
const nextUrl = new URL(location, validated).toString();
|
|
152
|
+
if (permanentChain && (response.status === 301 || response.status === 308)) {
|
|
153
|
+
permanentRedirectUrl = nextUrl;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
permanentChain = false;
|
|
157
|
+
}
|
|
158
|
+
currentUrl = nextUrl;
|
|
144
159
|
continue;
|
|
145
160
|
}
|
|
146
161
|
if (!response.ok) {
|
|
@@ -179,6 +194,7 @@ async function downloadPublic(url, opts) {
|
|
|
179
194
|
contentType: response.headers.get("content-type") ?? undefined,
|
|
180
195
|
etag: response.headers.get("etag") ?? undefined,
|
|
181
196
|
lastModified: response.headers.get("last-modified") ?? undefined, finalUrl: currentUrl,
|
|
197
|
+
...(permanentRedirectUrl && permanentRedirectUrl !== url ? { permanentRedirectUrl } : {}),
|
|
182
198
|
};
|
|
183
199
|
}
|
|
184
200
|
finally {
|
|
@@ -204,7 +220,13 @@ export async function fetchFeed(url, opts = {}) {
|
|
|
204
220
|
priority: opts.priority,
|
|
205
221
|
});
|
|
206
222
|
if (download.notModified) {
|
|
207
|
-
return {
|
|
223
|
+
return {
|
|
224
|
+
notModified: true,
|
|
225
|
+
body: "",
|
|
226
|
+
finalUrl: download.finalUrl,
|
|
227
|
+
contentType: download.contentType,
|
|
228
|
+
...(download.permanentRedirectUrl ? { permanentRedirectUrl: download.permanentRedirectUrl } : {}),
|
|
229
|
+
};
|
|
208
230
|
}
|
|
209
231
|
return {
|
|
210
232
|
body: decodeFeedBuffer(download.buffer, download.contentType),
|
|
@@ -213,6 +235,7 @@ export async function fetchFeed(url, opts = {}) {
|
|
|
213
235
|
lastModified: download.lastModified,
|
|
214
236
|
contentType: download.contentType,
|
|
215
237
|
finalUrl: download.finalUrl,
|
|
238
|
+
...(download.permanentRedirectUrl ? { permanentRedirectUrl: download.permanentRedirectUrl } : {}),
|
|
216
239
|
};
|
|
217
240
|
}
|
|
218
241
|
/** Downloads an image for the archive; the caller checks the file signature. */
|