feedkeeper 0.42.5 → 0.42.6
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/system.js +1 -0
- package/server/dist/api/v1/index.js +1 -0
- package/server/dist/config.js +1 -0
- package/server/dist/db/migrations/0047_retention_min_items.sql +4 -0
- package/server/dist/feeds/cleanup.js +25 -4
- package/server/dist/feeds/feedParser.js +20 -3
- package/server/package.json +1 -1
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ const updateRetentionSchema = z.object({
|
|
|
14
14
|
retentionReadDays: z.number().int().min(0).max(3650).optional(),
|
|
15
15
|
retentionMaxDays: z.number().int().min(0).max(3650).optional(),
|
|
16
16
|
retentionMaxItemsPerFeed: z.number().int().min(0).max(100000).optional(),
|
|
17
|
+
retentionMinItemsPerFeed: z.number().int().min(0).max(10000).optional(),
|
|
17
18
|
autoCleanupEnabled: z.boolean().optional(),
|
|
18
19
|
});
|
|
19
20
|
systemRouter.patch("/retention", (req, res) => {
|
|
@@ -72,6 +72,7 @@ v1Router.get("/meta", (_req, res) => {
|
|
|
72
72
|
readDays: retention.retentionReadDays,
|
|
73
73
|
maxDays: retention.retentionMaxDays,
|
|
74
74
|
maxItemsPerFeed: retention.retentionMaxItemsPerFeed,
|
|
75
|
+
minItemsPerFeed: retention.retentionMinItemsPerFeed,
|
|
75
76
|
protectActiveEdition: true,
|
|
76
77
|
},
|
|
77
78
|
},
|
package/server/dist/config.js
CHANGED
|
@@ -33,6 +33,7 @@ export const config = {
|
|
|
33
33
|
retentionReadDays: Number(process.env.RETENTION_READ_DAYS ?? 30),
|
|
34
34
|
retentionMaxDays: Number(process.env.RETENTION_MAX_DAYS ?? 90),
|
|
35
35
|
retentionMaxItemsPerFeed: Number(process.env.RETENTION_MAX_ITEMS_PER_FEED ?? 1000),
|
|
36
|
+
retentionMinItemsPerFeed: Number(process.env.RETENTION_MIN_ITEMS_PER_FEED ?? 30),
|
|
36
37
|
autoCleanupEnabled: process.env.AUTO_CLEANUP_ENABLED !== "false",
|
|
37
38
|
// Optional: only these hosts may register OAuth redirect URIs (comma-separated). Loopback addresses are always allowed.
|
|
38
39
|
oauthAllowedRedirectHosts: (process.env.OAUTH_ALLOWED_REDIRECT_HOSTS ?? "")
|
|
@@ -40,6 +40,7 @@ export function getRetentionSettings() {
|
|
|
40
40
|
retentionReadDays: Number(map.get("retention_read_days") ?? config.retentionReadDays),
|
|
41
41
|
retentionMaxDays: Number(map.get("retention_max_days") ?? config.retentionMaxDays),
|
|
42
42
|
retentionMaxItemsPerFeed: Number(map.get("retention_max_items_per_feed") ?? config.retentionMaxItemsPerFeed),
|
|
43
|
+
retentionMinItemsPerFeed: Number(map.get("retention_min_items_per_feed") ?? config.retentionMinItemsPerFeed),
|
|
43
44
|
autoCleanupEnabled: (map.get("auto_cleanup_enabled") ?? String(config.autoCleanupEnabled)) === "true",
|
|
44
45
|
};
|
|
45
46
|
}
|
|
@@ -48,6 +49,7 @@ export function getRetentionSettings() {
|
|
|
48
49
|
retentionReadDays: config.retentionReadDays,
|
|
49
50
|
retentionMaxDays: config.retentionMaxDays,
|
|
50
51
|
retentionMaxItemsPerFeed: config.retentionMaxItemsPerFeed,
|
|
52
|
+
retentionMinItemsPerFeed: config.retentionMinItemsPerFeed,
|
|
51
53
|
autoCleanupEnabled: config.autoCleanupEnabled,
|
|
52
54
|
};
|
|
53
55
|
}
|
|
@@ -66,6 +68,9 @@ export function updateRetentionSettings(settings) {
|
|
|
66
68
|
if (settings.retentionMaxItemsPerFeed !== undefined) {
|
|
67
69
|
updateStmt.run("retention_max_items_per_feed", String(Math.max(0, settings.retentionMaxItemsPerFeed)));
|
|
68
70
|
}
|
|
71
|
+
if (settings.retentionMinItemsPerFeed !== undefined) {
|
|
72
|
+
updateStmt.run("retention_min_items_per_feed", String(Math.max(0, settings.retentionMinItemsPerFeed)));
|
|
73
|
+
}
|
|
69
74
|
if (settings.autoCleanupEnabled !== undefined) {
|
|
70
75
|
updateStmt.run("auto_cleanup_enabled", String(settings.autoCleanupEnabled));
|
|
71
76
|
}
|
|
@@ -100,7 +105,21 @@ export function runCleanup(custom) {
|
|
|
100
105
|
let deletedReadItems = 0;
|
|
101
106
|
let deletedOldItems = 0;
|
|
102
107
|
let deletedPerFeedExcess = 0;
|
|
103
|
-
|
|
108
|
+
const minKeep = settings.retentionMinItemsPerFeed > 0 ? settings.retentionMinItemsPerFeed : null;
|
|
109
|
+
const minKeepClause = (idCol) => minKeep !== null
|
|
110
|
+
? `AND ${idCol} NOT IN (
|
|
111
|
+
SELECT id FROM (
|
|
112
|
+
SELECT id, ROW_NUMBER() OVER (
|
|
113
|
+
PARTITION BY feed_id
|
|
114
|
+
ORDER BY COALESCE(julianday(published_at), julianday(created_at)) DESC, id DESC
|
|
115
|
+
) AS rn
|
|
116
|
+
FROM items
|
|
117
|
+
)
|
|
118
|
+
WHERE rn <= ?
|
|
119
|
+
)`
|
|
120
|
+
: "";
|
|
121
|
+
const minKeepParams = minKeep !== null ? [minKeep] : [];
|
|
122
|
+
// 1. Delete read items older than retentionReadDays (excluding bookmarked items, notes, and the newest minKeep per feed)
|
|
104
123
|
if (settings.retentionReadDays > 0) {
|
|
105
124
|
deletedReadItems = retireItems(`id IN (
|
|
106
125
|
SELECT i.id
|
|
@@ -117,16 +136,18 @@ export function runCleanup(custom) {
|
|
|
117
136
|
AND NOT EXISTS (SELECT 1 FROM item_reads r WHERE r.item_id = i.id AND r.user_id = s.user_id)
|
|
118
137
|
)
|
|
119
138
|
AND COALESCE(julianday(i.published_at), julianday(i.created_at)) <= julianday('now', '-' || ? || ' days')
|
|
120
|
-
|
|
139
|
+
${minKeepClause("i.id")}
|
|
140
|
+
)`, settings.retentionReadDays, ...minKeepParams);
|
|
121
141
|
}
|
|
122
|
-
// 2. Delete all items older than retentionMaxDays (excluding bookmarked items and
|
|
142
|
+
// 2. Delete all items older than retentionMaxDays (excluding bookmarked items, notes, and the newest minKeep per feed)
|
|
123
143
|
if (settings.retentionMaxDays > 0) {
|
|
124
144
|
deletedOldItems = retireItems(`id NOT IN (SELECT item_id FROM item_bookmarks)
|
|
125
145
|
AND id NOT IN (SELECT item_id FROM item_notes)
|
|
126
146
|
AND feed_id NOT IN (SELECT id FROM feeds WHERE is_system_inbox = 1)
|
|
127
147
|
AND id NOT IN (SELECT CAST(selected.value AS INTEGER) FROM editions e, json_each(e.item_ids) selected
|
|
128
148
|
WHERE e.source = 'curated' AND e.status <> 'dismissed')
|
|
129
|
-
AND COALESCE(julianday(published_at), julianday(created_at)) <= julianday('now', '-' || ? || ' days')
|
|
149
|
+
AND COALESCE(julianday(published_at), julianday(created_at)) <= julianday('now', '-' || ? || ' days')
|
|
150
|
+
${minKeepClause("id")}`, settings.retentionMaxDays, ...minKeepParams);
|
|
130
151
|
}
|
|
131
152
|
// 3. Delete items exceeding retentionMaxItemsPerFeed (excluding bookmarked items and items with notes)
|
|
132
153
|
if (settings.retentionMaxItemsPerFeed > 0) {
|
|
@@ -9,6 +9,7 @@ const xmlParser = new Parser({
|
|
|
9
9
|
item: [
|
|
10
10
|
["media:content", "mediaContent", { keepArray: false }],
|
|
11
11
|
["media:thumbnail", "mediaThumbnail", { keepArray: false }],
|
|
12
|
+
["media:group", "mediaGroup", { keepArray: false }],
|
|
12
13
|
["content:encoded", "contentEncoded", { keepArray: false }],
|
|
13
14
|
],
|
|
14
15
|
},
|
|
@@ -104,9 +105,9 @@ function firstHtmlImageUrl(html) {
|
|
|
104
105
|
}
|
|
105
106
|
return null;
|
|
106
107
|
}
|
|
107
|
-
function
|
|
108
|
+
function extractMediaImageUrl(source) {
|
|
108
109
|
// 1. media:content (Media RSS)
|
|
109
|
-
const mediaContent =
|
|
110
|
+
const mediaContent = source.mediaContent ?? source["media:content"];
|
|
110
111
|
if (mediaContent) {
|
|
111
112
|
for (const entry of asMediaEntries(mediaContent)) {
|
|
112
113
|
if (isValidImageUrl(entry))
|
|
@@ -122,7 +123,7 @@ function extractXmlImageUrl(item) {
|
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
// 2. media:thumbnail
|
|
125
|
-
const mediaThumbnail =
|
|
126
|
+
const mediaThumbnail = source.mediaThumbnail ?? source["media:thumbnail"];
|
|
126
127
|
if (mediaThumbnail) {
|
|
127
128
|
for (const entry of asMediaEntries(mediaThumbnail)) {
|
|
128
129
|
if (isValidImageUrl(entry))
|
|
@@ -134,6 +135,22 @@ function extractXmlImageUrl(item) {
|
|
|
134
135
|
return cleanImageUrl(url);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function extractXmlImageUrl(item) {
|
|
141
|
+
const direct = extractMediaImageUrl(item);
|
|
142
|
+
if (direct)
|
|
143
|
+
return direct;
|
|
144
|
+
const mediaGroup = item.mediaGroup ?? item["media:group"];
|
|
145
|
+
if (mediaGroup) {
|
|
146
|
+
for (const group of asMediaEntries(mediaGroup)) {
|
|
147
|
+
if (!isRecord(group))
|
|
148
|
+
continue;
|
|
149
|
+
const grouped = extractMediaImageUrl(group);
|
|
150
|
+
if (grouped)
|
|
151
|
+
return grouped;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
137
154
|
// 3. enclosure
|
|
138
155
|
if (item.enclosure?.url) {
|
|
139
156
|
const url = item.enclosure.url;
|