Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat(api)!: track YouTube videos only

spacesdrive012507c89033
diff --git a/backend/container.ts b/backend/container.ts
index 918997b..18720c7 100644
--- a/backend/container.ts
+++ b/backend/container.ts
@@ -108,7 +108,7 @@ export function createServices(clients: Clients, config: AppConfig, context: Req
scheduledPosts: createScheduledPostService({ accounts, posts, publisher: scheduledPublisher }),
scheduledPublisher,
tokenRefresh: createTokenRefreshService({ accounts, context }),
- trackedContent: createTrackedContentService({ accounts, tracked, config, context }),
+ trackedContent: createTrackedContentService({ tracked, config, context }),
overview: createOverviewService({ accounts, tracked, cache, config }),
settings: createSettingsService({ settings, config }),
instagramConnect: createInstagramConnectService({ accounts, audit, config, context }),
diff --git a/backend/repositories/trackedPostRepository.ts b/backend/repositories/trackedPostRepository.ts
index 619f139..a67a527 100644
--- a/backend/repositories/trackedPostRepository.ts
+++ b/backend/repositories/trackedPostRepository.ts
@@ -5,7 +5,6 @@ import type { TrackedPost } from '../../shared/types/domain.ts';
interface TrackedPostRow {
id: string;
- account_id: string | null;
url: string;
label: string | null;
category: string | null;
@@ -17,38 +16,30 @@ interface TrackedPostRow {
export interface NewTrackedPost {
id: string;
- accountId?: string | null;
url: string;
label?: string;
category?: string;
- contentType?: string;
data?: Record<string, unknown>;
}
export interface TrackedPostUpdates {
label?: string;
category?: string;
- accountId?: string | null;
data?: Record<string, unknown>;
}
-interface TrackedPostColumnUpdates {
- label?: string;
- category?: string;
- account_id?: string | null;
- data?: Record<string, unknown>;
-}
+const COLUMNS = 'id, url, label, category, content_type, created_at, updated_at, data';
-const COLUMNS = 'id, account_id, url, label, category, content_type, created_at, updated_at, data';
+// rows of a platform Twiligent no longer tracks stay in the table until they are cleaned up, so reads leave them out
+const CONTENT_TYPE = 'youtube';
function toTrackedPost(row: TrackedPostRow): TrackedPost {
return {
id: row.id,
- accountId: row.account_id,
url: row.url,
label: row.label || '',
category: row.category || '',
- contentType: row.content_type || 'reddit',
+ contentType: row.content_type || CONTENT_TYPE,
createdAt: row.created_at,
updatedAt: row.updated_at,
...(row.data || {}),
@@ -72,6 +63,7 @@ export function createTrackedPostRepository(db: SupabaseClient): TrackedPostRepo
.from('tracked_posts')
.select(COLUMNS)
.eq('user_id', userId)
+ .eq('content_type', CONTENT_TYPE)
.order('created_at', { ascending: false }));
return found.map(toTrackedPost);
},
@@ -82,35 +74,34 @@ export function createTrackedPostRepository(db: SupabaseClient): TrackedPostRepo
.select(COLUMNS)
.eq('id', id)
.eq('user_id', userId)
+ .eq('content_type', CONTENT_TYPE)
.maybeSingle());
return row ? toTrackedPost(row) : null;
},
async create(post, userId) {
- const { id, accountId, url, label, category, contentType, data } = post;
+ const { id, url, label, category, data } = post;
await execute('trackedPosts.create', () => db.from('tracked_posts').insert({
id,
user_id: userId,
- account_id: accountId || null,
url,
label: label || '',
category: category || '',
- content_type: contentType || 'reddit',
+ content_type: CONTENT_TYPE,
data: data ?? null,
}));
},
// the database trigger keeps updated_at
async updateForUser(id, updates, userId) {
- const columns: TrackedPostColumnUpdates = {};
- if (updates.label !== undefined) columns.label = updates.label;
- if (updates.category !== undefined) columns.category = updates.category;
- if (updates.accountId !== undefined) columns.account_id = updates.accountId || null;
- if (updates.data !== undefined) columns.data = updates.data;
+ const columns: TrackedPostUpdates = {};
+ if (updates.label !== undefined) columns.label = updates.label;
+ if (updates.category !== undefined) columns.category = updates.category;
+ if (updates.data !== undefined) columns.data = updates.data;
await execute('trackedPosts.update', () => db.from('tracked_posts').update(columns).eq('id', id).eq('user_id', userId));
},
- // one atomic merge, so a manual view count and a refresh that lands at the same moment both survive
+ // one atomic merge in the database, so stored fields a refresh does not return are kept
async patchDataForUser(id, patch, userId) {
const { data } = await execute('trackedPosts.patchData', () => db.rpc('merge_tracked_post_data', { p_id: id, p_user_id: userId, p_patch: patch }));
if (!data) throw new NotFoundError('Tracked content not found');
diff --git a/backend/services/trackedContentRules.ts b/backend/services/trackedContentRules.ts
index 8a6df14..e2052d6 100644
--- a/backend/services/trackedContentRules.ts
+++ b/backend/services/trackedContentRules.ts
@@ -1,41 +1,9 @@
-export type TrackedContentType = 'reddit' | 'youtube';
+export type TrackedContentType = 'youtube';
-// either a validation error to send back or the fields to merge into the tracked post's data
-export type PatchResult<P> = { error: string; patch?: undefined } | { patch: P; error?: undefined };
+export const UNSUPPORTED_LINK_MESSAGE = 'Only YouTube video links can be tracked. Paste a youtube.com or youtu.be link.';
export function detectContentType(url: string | null | undefined): TrackedContentType | null {
const lower = (url || '').toLowerCase();
- if (lower.includes('reddit.com') || lower.includes('redd.it')) return 'reddit';
if (lower.includes('youtube.com') || lower.includes('youtu.be')) return 'youtube';
return null;
}
-
-// reddit dropped view_count in 2018 so views are typed in; youtube keeps its own
-export function manualViewsPatch(manualViews: unknown, isYouTube: boolean): PatchResult<{ manualViews: number | null }> {
- if (isYouTube) return { error: 'YouTube view counts are fetched automatically and cannot be set by hand' };
- if (manualViews === null || manualViews === '') return { patch: { manualViews: null } };
-
- const views = Number(manualViews);
- if (!Number.isInteger(views) || views < 0) return { error: 'Views must be a whole number of 0 or more' };
- return { patch: { manualViews: views } };
-}
-
-function parseUrl(value: unknown): URL | null {
- try {
- return new URL(String(value));
- } catch {
- // anything the URL parser rejects is not a usable image address
- return null;
- }
-}
-
-// reddit has no thumbnail, so the browser uploads one; youtube keeps its own
-export function imageUrlPatch(imageUrl: unknown, isYouTube: boolean): PatchResult<{ imageUrl: string | null }> {
- if (isYouTube) return { error: 'Images can only be attached to Reddit posts' };
- if (imageUrl === null || imageUrl === '') return { patch: { imageUrl: null } };
-
- const parsed = parseUrl(imageUrl);
- // https only: it lands in an img src, so javascript: and data: urls are refused
- if (!parsed || parsed.protocol !== 'https:') return { error: 'Image must be an https URL returned by the uploader' };
- return { patch: { imageUrl: parsed.toString() } };
-}
diff --git a/backend/services/trackedContentService.ts b/backend/services/trackedContentService.ts
index 9cdd76e..5fb6d4d 100644
--- a/backend/services/trackedContentService.ts
+++ b/backend/services/trackedContentService.ts
@@ -1,19 +1,13 @@
-import { fetchTrackedPostData } from './reddit/redditApi.ts';
import { fetchTrackedYouTubeData } from './youtube/youtubeTracked.ts';
-import { detectContentType, manualViewsPatch, imageUrlPatch } from './trackedContentRules.ts';
+import { detectContentType, UNSUPPORTED_LINK_MESSAGE } from './trackedContentRules.ts';
import { NotConfiguredError, NotFoundError, ValidationError } from '../lib/errors.ts';
import { newRowId } from '../lib/ids.ts';
-import type { PatchResult, TrackedContentType } from './trackedContentRules.ts';
-import type { AccountRepository } from '../repositories/accountRepository.ts';
import type { TrackedPostRepository, TrackedPostUpdates } from '../repositories/trackedPostRepository.ts';
import type { AppConfig } from '../lib/config.ts';
import type { RequestContext } from '../types/context.ts';
import type { TrackedPost } from '../../shared/types/domain.ts';
-import type { RedditTrackedPostData } from '../../shared/types/reddit.ts';
-import type { YouTubeTrackedVideoData } from '../../shared/types/youtube.ts';
export interface TrackedContentDeps {
- accounts: AccountRepository;
tracked: TrackedPostRepository;
config: AppConfig;
context: RequestContext;
@@ -21,18 +15,13 @@ export interface TrackedContentDeps {
export interface NewTrackedContent {
url: string;
- accountId?: string | null;
label?: string;
category?: string;
}
-// manualViews and imageUrl arrive as the client sent them; the rules decide what is valid
export interface TrackedContentChanges {
label?: string;
category?: string;
- accountId?: string | null;
- manualViews?: unknown;
- imageUrl?: unknown;
}
export interface TrackedContentService {
@@ -43,14 +32,7 @@ export interface TrackedContentService {
refresh(userId: string, id: string): Promise<TrackedPost | null>;
}
-type TrackedData = YouTubeTrackedVideoData | RedditTrackedPostData;
-
-function patchOrThrow<P>(result: PatchResult<P>): P {
- if (result.error !== undefined) throw new ValidationError(result.error);
- return result.patch;
-}
-
-export function createTrackedContentService({ accounts, tracked, config, context }: TrackedContentDeps): TrackedContentService {
+export function createTrackedContentService({ tracked, config, context }: TrackedContentDeps): TrackedContentService {
const { signal } = context;
function youtubeKey(): string {
@@ -64,54 +46,29 @@ export function createTrackedContentService({ accounts, tracked, config, context
return item;
}
- // a named account must be one of the user's Reddit accounts; no account means no cookie
- async function redditCookie(userId: string, accountId: string | null | undefined, strict: boolean): Promise<string | null> {
- if (!accountId) return null;
- const account = await accounts.findForUser(accountId, userId);
- if (strict && (!account || account.platform !== 'reddit')) throw new NotFoundError('Reddit account not found');
- return account?.cookie || null;
- }
-
- // only Reddit items read through an account, and it must be one of the user's own Reddit accounts
- async function checkedAccountId(userId: string, accountId: string | null, isYouTube: boolean): Promise<string | null> {
- if (!accountId) return null;
- if (isYouTube) throw new ValidationError('YouTube videos are read without an account; remove the account from this item.');
- await redditCookie(userId, accountId, true);
- return accountId;
- }
-
- async function fetchData(userId: string, contentType: TrackedContentType, url: string, accountId: string | null | undefined, strict: boolean): Promise<TrackedData> {
- if (contentType === 'youtube') return fetchTrackedYouTubeData(url, youtubeKey(), signal);
- return fetchTrackedPostData(url, await redditCookie(userId, accountId, strict), signal);
+ async function fetchVideoData(url: string): Promise<Record<string, unknown>> {
+ const data = await fetchTrackedYouTubeData(url, youtubeKey(), signal);
+ return data as unknown as Record<string, unknown>;
}
return {
list: userId => tracked.listForUser(userId),
- async add(userId, { url, accountId, label, category }) {
- const contentType = detectContentType(url);
- if (!contentType) throw new ValidationError('Only Reddit and YouTube URLs are supported');
- const data = await fetchData(userId, contentType, url, accountId, true);
+ async add(userId, { url, label, category }) {
+ if (!detectContentType(url)) throw new ValidationError(UNSUPPORTED_LINK_MESSAGE);
+ const data = await fetchVideoData(url);
const id = newRowId();
- const fetched = data as unknown as Record<string, unknown>;
- await tracked.create({ id, accountId: contentType === 'youtube' ? null : (accountId || null), url, label, category, contentType, data: fetched }, userId);
+ await tracked.create({ id, url, label, category, data }, userId);
return tracked.findForUser(id, userId);
},
- async update(userId, id, { label, category, accountId, manualViews, imageUrl }) {
- const existing = await findOwned(userId, id);
- const isYouTube = (existing.contentType || 'reddit') === 'youtube';
-
- if (manualViews !== undefined) await tracked.patchDataForUser(id, patchOrThrow(manualViewsPatch(manualViews, isYouTube)), userId);
- if (imageUrl !== undefined) await tracked.patchDataForUser(id, patchOrThrow(imageUrlPatch(imageUrl, isYouTube)), userId);
-
+ async update(userId, id, { label, category }) {
+ await findOwned(userId, id);
const updates: TrackedPostUpdates = {};
if (label !== undefined) updates.label = label;
if (category !== undefined) updates.category = category;
- if (accountId !== undefined) updates.accountId = await checkedAccountId(userId, accountId, isYouTube);
if (Object.keys(updates).length > 0) await tracked.updateForUser(id, updates, userId);
-
return tracked.findForUser(id, userId);
},
@@ -120,11 +77,9 @@ export function createTrackedContentService({ accounts, tracked, config, context
await tracked.deleteForUser(id, userId);
},
- // patched rather than replaced, so a manually entered view count survives the refresh
async refresh(userId, id) {
const existing = await findOwned(userId, id);
- const data = await fetchData(userId, existing.contentType === 'youtube' ? 'youtube' : 'reddit', existing.url, existing.accountId, false);
- await tracked.patchDataForUser(id, data as unknown as Record<string, unknown>, userId);
+ await tracked.patchDataForUser(id, await fetchVideoData(existing.url), userId);
return tracked.findForUser(id, userId);
},
};
diff --git a/backend/tests/fixtures/overviewRoutes.summary.golden.json b/backend/tests/fixtures/overviewRoutes.summary.golden.json
index d0d36af..f58a8b3 100644
--- a/backend/tests/fixtures/overviewRoutes.summary.golden.json
+++ b/backend/tests/fixtures/overviewRoutes.summary.golden.json
@@ -4,7 +4,7 @@
{
"call": "GET /overview",
"status": 200,
- "body": "{\"tracked\":[{\"id\":\"t1\",\"accountId\":null,\"url\":\"https://youtu.be/x\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Tracked\"}],\"analyticsCache\":{\"yt1\":{\"id\":\"yt1\",\"cacheWarmed\":true,\"totalLikes\":12,\"totalComments\":5,\"fetchedAt\":\"then\"},\"yt2\":{\"id\":\"yt2\",\"cacheWarmed\":true,\"totalLikes\":1,\"totalComments\":1,\"fetchedAt\":\"then\"},\"yt3\":{\"id\":\"yt3\",\"cacheWarmed\":false,\"syncing\":false},\"ig1\":{\"id\":\"ig1\",\"cacheWarmed\":true,\"totalLikes\":6,\"totalComments\":2,\"totalViews\":90,\"contentTypes\":{\"reel\":{\"count\":1,\"likes\":5,\"comments\":2,\"views\":90,\"viewsReported\":1},\"post\":{\"count\":1,\"likes\":1,\"comments\":0,\"views\":0,\"viewsReported\":0},\"video\":{\"count\":0,\"likes\":0,\"comments\":0,\"views\":0,\"viewsReported\":0}}},\"rd1\":{\"id\":\"rd1\",\"cacheWarmed\":true,\"fetchedPosts\":4,\"totalScore\":40,\"totalComments\":0},\"rd2\":{\"id\":\"rd2\",\"cacheWarmed\":false,\"syncing\":false}}}"
+ "body": "{\"tracked\":[{\"id\":\"t1\",\"url\":\"https://youtu.be/x\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Tracked\"}],\"analyticsCache\":{\"yt1\":{\"id\":\"yt1\",\"cacheWarmed\":true,\"totalLikes\":12,\"totalComments\":5,\"fetchedAt\":\"then\"},\"yt2\":{\"id\":\"yt2\",\"cacheWarmed\":true,\"totalLikes\":1,\"totalComments\":1,\"fetchedAt\":\"then\"},\"yt3\":{\"id\":\"yt3\",\"cacheWarmed\":false,\"syncing\":false},\"ig1\":{\"id\":\"ig1\",\"cacheWarmed\":true,\"totalLikes\":6,\"totalComments\":2,\"totalViews\":90,\"contentTypes\":{\"reel\":{\"count\":1,\"likes\":5,\"comments\":2,\"views\":90,\"viewsReported\":1},\"post\":{\"count\":1,\"likes\":1,\"comments\":0,\"views\":0,\"viewsReported\":0},\"video\":{\"count\":0,\"likes\":0,\"comments\":0,\"views\":0,\"viewsReported\":0}}},\"rd1\":{\"id\":\"rd1\",\"cacheWarmed\":true,\"fetchedPosts\":4,\"totalScore\":40,\"totalComments\":0},\"rd2\":{\"id\":\"rd2\",\"cacheWarmed\":false,\"syncing\":false}}}"
}
],
"queries": [
@@ -22,11 +22,15 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
}
@@ -40,7 +44,7 @@
{
"call": "GET /overview",
"status": 200,
- "body": "{\"tracked\":[{\"id\":\"t1\",\"accountId\":null,\"url\":\"https://youtu.be/x\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Tracked\"}],\"analyticsCache\":{\"yt1\":{\"id\":\"yt1\",\"cacheWarmed\":false,\"syncing\":false},\"yt2\":{\"id\":\"yt2\",\"cacheWarmed\":false,\"syncing\":false},\"yt3\":{\"id\":\"yt3\",\"cacheWarmed\":false,\"syncing\":false},\"ig1\":{\"id\":\"ig1\",\"cacheWarmed\":false,\"syncing\":false},\"rd1\":{\"id\":\"rd1\",\"cacheWarmed\":false,\"syncing\":false},\"rd2\":{\"id\":\"rd2\",\"cacheWarmed\":false,\"syncing\":false}}}"
+ "body": "{\"tracked\":[{\"id\":\"t1\",\"url\":\"https://youtu.be/x\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Tracked\"}],\"analyticsCache\":{\"yt1\":{\"id\":\"yt1\",\"cacheWarmed\":false,\"syncing\":false},\"yt2\":{\"id\":\"yt2\",\"cacheWarmed\":false,\"syncing\":false},\"yt3\":{\"id\":\"yt3\",\"cacheWarmed\":false,\"syncing\":false},\"ig1\":{\"id\":\"ig1\",\"cacheWarmed\":false,\"syncing\":false},\"rd1\":{\"id\":\"rd1\",\"cacheWarmed\":false,\"syncing\":false},\"rd2\":{\"id\":\"rd2\",\"cacheWarmed\":false,\"syncing\":false}}}"
}
],
"queries": [
@@ -58,11 +62,15 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
}
diff --git a/backend/tests/fixtures/overviewRoutes.warming.golden.json b/backend/tests/fixtures/overviewRoutes.warming.golden.json
index 7738525..99cb821 100644
--- a/backend/tests/fixtures/overviewRoutes.warming.golden.json
+++ b/backend/tests/fixtures/overviewRoutes.warming.golden.json
@@ -1,6 +1,6 @@
{
"status": 200,
- "body": "{\"tracked\":[{\"id\":\"t1\",\"accountId\":null,\"url\":\"https://youtu.be/x\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Tracked\"}],\"analyticsCache\":{\"yt1\":{\"id\":\"yt1\",\"cacheWarmed\":false,\"syncing\":true},\"yt2\":{\"id\":\"yt2\",\"cacheWarmed\":false,\"syncing\":true},\"yt3\":{\"id\":\"yt3\",\"cacheWarmed\":false,\"syncing\":false},\"ig1\":{\"id\":\"ig1\",\"cacheWarmed\":false,\"syncing\":true},\"rd1\":{\"id\":\"rd1\",\"cacheWarmed\":false,\"syncing\":true},\"rd2\":{\"id\":\"rd2\",\"cacheWarmed\":false,\"syncing\":false}}}",
+ "body": "{\"tracked\":[{\"id\":\"t1\",\"url\":\"https://youtu.be/x\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Tracked\"}],\"analyticsCache\":{\"yt1\":{\"id\":\"yt1\",\"cacheWarmed\":false,\"syncing\":true},\"yt2\":{\"id\":\"yt2\",\"cacheWarmed\":false,\"syncing\":true},\"yt3\":{\"id\":\"yt3\",\"cacheWarmed\":false,\"syncing\":false},\"ig1\":{\"id\":\"ig1\",\"cacheWarmed\":false,\"syncing\":true},\"rd1\":{\"id\":\"rd1\",\"cacheWarmed\":false,\"syncing\":true},\"rd2\":{\"id\":\"rd2\",\"cacheWarmed\":false,\"syncing\":false}}}",
"waitUntilCalls": 1,
"settled": [
[
diff --git a/backend/tests/fixtures/trackedContentRoutes.create.golden.json b/backend/tests/fixtures/trackedContentRoutes.create.golden.json
index 465dc60..ecda921 100644
--- a/backend/tests/fixtures/trackedContentRoutes.create.golden.json
+++ b/backend/tests/fixtures/trackedContentRoutes.create.golden.json
@@ -9,32 +9,22 @@
{
"call": "POST /tracked-content",
"status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Only Reddit and YouTube URLs are supported\",\"requestId\":\"req-test\"}"
+ "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Only YouTube video links can be tracked. Paste a youtube.com or youtu.be link.\",\"requestId\":\"req-test\"}"
},
{
"call": "POST /tracked-content",
- "status": 201,
- "body": "{\"id\":\"00000000-0000-4000-8000-000000000001\",\"accountId\":null,\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"Video\",\"category\":\"Music\",\"contentType\":\"youtube\",\"title\":\"Watch\",\"channelTitle\":\"Ribbon\",\"channelId\":\"UC1\",\"thumbnail\":\"m\",\"publishedAt\":\"2026-08-01T10:00:00Z\",\"viewCount\":1500,\"likeCount\":40,\"commentCount\":3,\"isShort\":false,\"permalink\":\"https://www.youtube.com/watch?v=abc\",\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
- },
- {
- "call": "POST /tracked-content",
- "status": 404,
- "body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Reddit account not found\",\"requestId\":\"req-test\"}"
- },
- {
- "call": "POST /tracked-content",
- "status": 404,
- "body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Reddit account not found\",\"requestId\":\"req-test\"}"
+ "status": 400,
+ "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Only YouTube video links can be tracked. Paste a youtube.com or youtu.be link.\",\"requestId\":\"req-test\"}"
},
{
"call": "POST /tracked-content",
"status": 201,
- "body": "{\"id\":\"00000000-0000-4000-8000-000000000002\",\"accountId\":\"rd1\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"Mine\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-07-25T17:20:00.000Z\",\"postId\":\"p1\",\"title\":\"Tracked\",\"subreddit\":\"webdev\",\"subredditPrefixed\":\"r/webdev\",\"author\":\"[deleted]\",\"score\":77,\"upvoteRatio\":0.93,\"numComments\":8,\"permalink\":\"https://reddit.com/r/webdev/comments/p1/tracked/\",\"isNsfw\":false,\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
+ "body": "{\"id\":\"00000000-0000-4000-8000-000000000001\",\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"Video\",\"category\":\"Music\",\"contentType\":\"youtube\",\"title\":\"Watch\",\"channelTitle\":\"Ribbon\",\"channelId\":\"UC1\",\"thumbnail\":\"m\",\"publishedAt\":\"2026-08-01T10:00:00Z\",\"viewCount\":1500,\"likeCount\":40,\"commentCount\":3,\"isShort\":false,\"permalink\":\"https://www.youtube.com/watch?v=abc\",\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
},
{
"call": "POST /tracked-content",
"status": 201,
- "body": "{\"id\":\"00000000-0000-4000-8000-000000000003\",\"accountId\":null,\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-07-25T17:20:00.000Z\",\"postId\":\"p1\",\"title\":\"Tracked\",\"subreddit\":\"webdev\",\"subredditPrefixed\":\"r/webdev\",\"author\":\"[deleted]\",\"score\":77,\"upvoteRatio\":0.93,\"numComments\":8,\"permalink\":\"https://reddit.com/r/webdev/comments/p1/tracked/\",\"isNsfw\":false,\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
+ "body": "{\"id\":\"00000000-0000-4000-8000-000000000002\",\"url\":\"https://youtu.be/abc\",\"label\":\"Mine\",\"category\":\"\",\"contentType\":\"youtube\",\"title\":\"Watch\",\"channelTitle\":\"Ribbon\",\"channelId\":\"UC1\",\"thumbnail\":\"m\",\"publishedAt\":\"2026-08-01T10:00:00Z\",\"viewCount\":1500,\"likeCount\":40,\"commentCount\":3,\"isShort\":false,\"permalink\":\"https://www.youtube.com/watch?v=abc\",\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
}
],
"queries": [
@@ -44,7 +34,6 @@
"values": {
"id": "00000000-0000-4000-8000-000000000001",
"user_id": "user-1",
- "account_id": null,
"url": "https://www.youtube.com/watch?v=abc",
"label": "Video",
"category": "Music",
@@ -69,7 +58,7 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -78,51 +67,10 @@
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
- "filters": [
- [
- "id",
- "yt1"
],
[
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
- "filters": [
- [
- "id",
- "missing"
- ],
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
- "filters": [
- [
- "id",
- "rd1"
- ],
- [
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
@@ -132,23 +80,22 @@
"values": {
"id": "00000000-0000-4000-8000-000000000002",
"user_id": "user-1",
- "account_id": "rd1",
- "url": "https://www.reddit.com/r/webdev/comments/p1/tracked/",
+ "url": "https://youtu.be/abc",
"label": "Mine",
"category": "",
- "content_type": "reddit",
+ "content_type": "youtube",
"data": {
- "postId": "p1",
- "title": "Tracked",
- "subreddit": "webdev",
- "subredditPrefixed": "r/webdev",
- "author": "[deleted]",
- "score": 77,
- "upvoteRatio": 0.93,
- "numComments": 8,
- "permalink": "https://reddit.com/r/webdev/comments/p1/tracked/",
- "isNsfw": false,
- "createdAt": "2026-07-25T17:20:00.000Z",
+ "contentType": "youtube",
+ "title": "Watch",
+ "channelTitle": "Ribbon",
+ "channelId": "UC1",
+ "thumbnail": "m",
+ "publishedAt": "2026-08-01T10:00:00Z",
+ "viewCount": 1500,
+ "likeCount": 40,
+ "commentCount": 3,
+ "isShort": false,
+ "permalink": "https://www.youtube.com/watch?v=abc",
"lastFetchedAt": "2026-09-01T12:00:00.000Z"
}
},
@@ -157,7 +104,7 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -166,49 +113,10 @@
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "insert",
- "table": "tracked_posts",
- "values": {
- "id": "00000000-0000-4000-8000-000000000003",
- "user_id": "user-1",
- "account_id": null,
- "url": "https://www.reddit.com/r/webdev/comments/p1/tracked/",
- "label": "",
- "category": "",
- "content_type": "reddit",
- "data": {
- "postId": "p1",
- "title": "Tracked",
- "subreddit": "webdev",
- "subredditPrefixed": "r/webdev",
- "author": "[deleted]",
- "score": 77,
- "upvoteRatio": 0.93,
- "numComments": 8,
- "permalink": "https://reddit.com/r/webdev/comments/p1/tracked/",
- "isNsfw": false,
- "createdAt": "2026-07-25T17:20:00.000Z",
- "lastFetchedAt": "2026-09-01T12:00:00.000Z"
- }
- },
- "filters": []
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "00000000-0000-4000-8000-000000000003"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
}
@@ -219,21 +127,8 @@
"method": "GET"
},
{
- "url": "https://www.reddit.com/r/webdev/comments/p1/tracked.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=COOKIE"
- }
- },
- {
- "url": "https://www.reddit.com/r/webdev/comments/p1/tracked.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json"
- }
+ "url": "https://www.googleapis.com/youtube/v3/videos?part=snippet%2Cstatistics&id=abc&key=YTKEY",
+ "method": "GET"
}
],
"logLines": []
diff --git a/backend/tests/fixtures/trackedContentRoutes.refresh.golden.json b/backend/tests/fixtures/trackedContentRoutes.refresh.golden.json
index ac94929..634603e 100644
--- a/backend/tests/fixtures/trackedContentRoutes.refresh.golden.json
+++ b/backend/tests/fixtures/trackedContentRoutes.refresh.golden.json
@@ -4,22 +4,17 @@
{
"call": "GET /tracked-content",
"status": 200,
- "body": "[{\"id\":\"t-reddit\",\"accountId\":\"rd1\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Old\",\"manualViews\":5},{\"id\":\"t-youtube\",\"accountId\":null,\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Video\"},{\"id\":\"t-orphan\",\"accountId\":\"gone\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\"}]"
+ "body": "[{\"id\":\"t-youtube\",\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Video\"},{\"id\":\"t-short\",\"url\":\"https://www.youtube.com/shorts/def\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-08-01T00:00:00Z\",\"title\":\"Short\",\"viewCount\":9}]"
},
{
- "call": "POST /tracked-content/t-reddit/refresh",
- "status": 200,
- "body": "{\"id\":\"t-reddit\",\"accountId\":\"rd1\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-07-25T17:20:00.000Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Tracked\",\"manualViews\":5,\"postId\":\"p1\",\"subreddit\":\"webdev\",\"subredditPrefixed\":\"r/webdev\",\"author\":\"[deleted]\",\"score\":77,\"upvoteRatio\":0.93,\"numComments\":8,\"permalink\":\"https://reddit.com/r/webdev/comments/p1/tracked/\",\"isNsfw\":false,\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
- },
- {
- "call": "POST /tracked-content/t-orphan/refresh",
- "status": 200,
- "body": "{\"id\":\"t-orphan\",\"accountId\":\"gone\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-07-25T17:20:00.000Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"postId\":\"p1\",\"title\":\"Tracked\",\"subreddit\":\"webdev\",\"subredditPrefixed\":\"r/webdev\",\"author\":\"[deleted]\",\"score\":77,\"upvoteRatio\":0.93,\"numComments\":8,\"permalink\":\"https://reddit.com/r/webdev/comments/p1/tracked/\",\"isNsfw\":false,\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
+ "call": "POST /tracked-content/t-retired/refresh",
+ "status": 404,
+ "body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Tracked content not found\",\"requestId\":\"req-test\"}"
},
{
"call": "POST /tracked-content/t-youtube/refresh",
"status": 200,
- "body": "{\"id\":\"t-youtube\",\"accountId\":null,\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Watch\",\"channelTitle\":\"Ribbon\",\"channelId\":\"UC1\",\"thumbnail\":\"m\",\"publishedAt\":\"2026-08-01T10:00:00Z\",\"viewCount\":1500,\"likeCount\":40,\"commentCount\":3,\"isShort\":false,\"permalink\":\"https://www.youtube.com/watch?v=abc\",\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
+ "body": "{\"id\":\"t-youtube\",\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Watch\",\"channelTitle\":\"Ribbon\",\"channelId\":\"UC1\",\"thumbnail\":\"m\",\"publishedAt\":\"2026-08-01T10:00:00Z\",\"viewCount\":1500,\"likeCount\":40,\"commentCount\":3,\"isShort\":false,\"permalink\":\"https://www.youtube.com/watch?v=abc\",\"lastFetchedAt\":\"2026-09-01T12:00:00.000Z\"}"
},
{
"call": "POST /tracked-content/nope/refresh",
@@ -35,168 +30,64 @@
"call": "DELETE /tracked-content/t-youtube",
"status": 404,
"body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Tracked content not found\",\"requestId\":\"req-test\"}"
+ },
+ {
+ "call": "DELETE /tracked-content/t-retired",
+ "status": 404,
+ "body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Tracked content not found\",\"requestId\":\"req-test\"}"
}
],
"queries": [
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
- ],
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
- [
- "id",
- "rd1"
- ],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "rpc",
- "table": "merge_tracked_post_data",
- "values": {
- "p_id": "t-reddit",
- "p_user_id": "user-1",
- "p_patch": {
- "postId": "p1",
- "title": "Tracked",
- "subreddit": "webdev",
- "subredditPrefixed": "r/webdev",
- "author": "[deleted]",
- "score": 77,
- "upvoteRatio": 0.93,
- "numComments": 8,
- "permalink": "https://reddit.com/r/webdev/comments/p1/tracked/",
- "isNsfw": false,
- "createdAt": "2026-07-25T17:20:00.000Z",
- "lastFetchedAt": "2026-09-01T12:00:00.000Z"
- }
- },
- "filters": []
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-orphan"
+ "t-retired"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "accounts",
- "columns": "id, platform, data",
- "filters": [
- [
- "id",
- "gone"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
- {
- "type": "rpc",
- "table": "merge_tracked_post_data",
- "values": {
- "p_id": "t-orphan",
- "p_user_id": "user-1",
- "p_patch": {
- "postId": "p1",
- "title": "Tracked",
- "subreddit": "webdev",
- "subredditPrefixed": "r/webdev",
- "author": "[deleted]",
- "score": 77,
- "upvoteRatio": 0.93,
- "numComments": 8,
- "permalink": "https://reddit.com/r/webdev/comments/p1/tracked/",
- "isNsfw": false,
- "createdAt": "2026-07-25T17:20:00.000Z",
- "lastFetchedAt": "2026-09-01T12:00:00.000Z"
- }
- },
- "filters": []
- },
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-orphan"
+ "t-youtube"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-youtube"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
@@ -226,7 +117,7 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -235,13 +126,17 @@
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
},
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -250,13 +145,17 @@
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
},
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -265,6 +164,10 @@
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
},
@@ -285,7 +188,7 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -294,28 +197,34 @@
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
+ ]
+ ]
+ },
+ {
+ "type": "select",
+ "table": "tracked_posts",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
+ "filters": [
+ [
+ "id",
+ "t-retired"
+ ],
+ [
+ "user_id",
+ "user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
}
],
"requests": [
- {
- "url": "https://www.reddit.com/r/webdev/comments/p1/tracked.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json",
- "Cookie": "reddit_session=COOKIE"
- }
- },
- {
- "url": "https://www.reddit.com/r/webdev/comments/p1/tracked.json",
- "method": "GET",
- "headers": {
- "User-Agent": "script:twiligent:v1.0 (by /u/spacesdrive)",
- "Accept": "application/json"
- }
- },
{
"url": "https://www.googleapis.com/youtube/v3/videos?part=snippet%2Cstatistics&id=abc&key=YTKEY",
"method": "GET"
@@ -335,7 +244,7 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -344,6 +253,10 @@
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
}
diff --git a/backend/tests/fixtures/trackedContentRoutes.update.golden.json b/backend/tests/fixtures/trackedContentRoutes.update.golden.json
index 454cec3..61452b0 100644
--- a/backend/tests/fixtures/trackedContentRoutes.update.golden.json
+++ b/backend/tests/fixtures/trackedContentRoutes.update.golden.json
@@ -6,71 +6,36 @@
"body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Tracked content not found\",\"requestId\":\"req-test\"}"
},
{
- "call": "PUT /tracked-content/t-youtube",
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"YouTube view counts are fetched automatically and cannot be set by hand\",\"requestId\":\"req-test\"}"
- },
- {
- "call": "PUT /tracked-content/t-youtube",
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Images can only be attached to Reddit posts\",\"requestId\":\"req-test\"}"
- },
- {
- "call": "PUT /tracked-content/t-reddit",
- "status": 200,
- "body": "{\"id\":\"t-reddit\",\"accountId\":\"rd1\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Old\",\"manualViews\":null}"
- },
- {
- "call": "PUT /tracked-content/t-reddit",
- "status": 200,
- "body": "{\"id\":\"t-reddit\",\"accountId\":\"rd1\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Old\",\"manualViews\":12}"
- },
- {
- "call": "PUT /tracked-content/t-reddit",
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Views must be a whole number of 0 or more\",\"requestId\":\"req-test\"}"
+ "call": "PUT /tracked-content/t-theirs",
+ "status": 404,
+ "body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Tracked content not found\",\"requestId\":\"req-test\"}"
},
{
- "call": "PUT /tracked-content/t-reddit",
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Views must be a whole number of 0 or more\",\"requestId\":\"req-test\"}"
+ "call": "PUT /tracked-content/t-retired",
+ "status": 404,
+ "body": "{\"success\":false,\"code\":\"NOT_FOUND\",\"message\":\"Tracked content not found\",\"requestId\":\"req-test\"}"
},
{
- "call": "PUT /tracked-content/t-reddit",
+ "call": "PUT /tracked-content/t-youtube",
"status": 200,
- "body": "{\"id\":\"t-reddit\",\"accountId\":\"rd1\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Old\",\"manualViews\":12,\"imageUrl\":\"https://img/a%20b.png\"}"
+ "body": "{\"id\":\"t-youtube\",\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"New\",\"category\":\"Cat\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Video\"}"
},
{
- "call": "PUT /tracked-content/t-reddit",
+ "call": "PUT /tracked-content/t-short",
"status": 200,
- "body": "{\"id\":\"t-reddit\",\"accountId\":\"rd1\",\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"\",\"category\":\"\",\"contentType\":\"reddit\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Old\",\"manualViews\":12,\"imageUrl\":null}"
+ "body": "{\"id\":\"t-short\",\"url\":\"https://www.youtube.com/shorts/def\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Short\",\"viewCount\":9}"
},
{
- "call": "PUT /tracked-content/t-reddit",
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Image must be an https URL returned by the uploader\",\"requestId\":\"req-test\"}"
- },
- {
- "call": "PUT /tracked-content/t-reddit",
- "status": 400,
- "body": "{\"success\":false,\"code\":\"VALIDATION_ERROR\",\"message\":\"Image must be an https URL returned by the uploader\",\"requestId\":\"req-test\"}"
- },
- {
- "call": "PUT /tracked-content/t-reddit",
+ "call": "PUT /tracked-content/t-short",
"status": 200,
- "body": "{\"id\":\"t-reddit\",\"accountId\":null,\"url\":\"https://www.reddit.com/r/webdev/comments/p1/tracked/\",\"label\":\"New\",\"category\":\"Cat\",\"contentType\":\"reddit\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Old\",\"manualViews\":7,\"imageUrl\":null}"
- },
- {
- "call": "PUT /tracked-content/t-youtube",
- "status": 200,
- "body": "{\"id\":\"t-youtube\",\"accountId\":null,\"url\":\"https://www.youtube.com/watch?v=abc\",\"label\":\"Only label\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Video\"}"
+ "body": "{\"id\":\"t-short\",\"url\":\"https://www.youtube.com/shorts/def\",\"label\":\"\",\"category\":\"\",\"contentType\":\"youtube\",\"createdAt\":\"2026-08-01T00:00:00Z\",\"updatedAt\":\"2026-09-01T12:00:00.000Z\",\"title\":\"Short\",\"viewCount\":9}"
}
],
"queries": [
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
@@ -79,203 +44,81 @@
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-youtube"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-youtube"
+ "t-theirs"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
- {
- "type": "rpc",
- "table": "merge_tracked_post_data",
- "values": {
- "p_id": "t-reddit",
- "p_user_id": "user-1",
- "p_patch": {
- "manualViews": null
- }
- },
- "filters": []
- },
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-reddit"
+ "t-retired"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
- {
- "type": "rpc",
- "table": "merge_tracked_post_data",
- "values": {
- "p_id": "t-reddit",
- "p_user_id": "user-1",
- "p_patch": {
- "manualViews": 12
- }
- },
- "filters": []
- },
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-reddit"
+ "t-youtube"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
{
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
- ],
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "select",
+ "type": "update",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
- ],
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "rpc",
- "table": "merge_tracked_post_data",
"values": {
- "p_id": "t-reddit",
- "p_user_id": "user-1",
- "p_patch": {
- "imageUrl": "https://img/a%20b.png"
- }
+ "label": "New",
+ "category": "Cat"
},
- "filters": []
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-reddit"
- ],
- [
- "user_id",
- "user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
+ "t-youtube"
],
[
"user_id",
@@ -283,87 +126,41 @@
]
]
},
- {
- "type": "rpc",
- "table": "merge_tracked_post_data",
- "values": {
- "p_id": "t-reddit",
- "p_user_id": "user-1",
- "p_patch": {
- "imageUrl": null
- }
- },
- "filters": []
- },
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-reddit"
+ "t-youtube"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-reddit"
+ "t-short"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "rpc",
- "table": "merge_tracked_post_data",
- "values": {
- "p_id": "t-reddit",
- "p_user_id": "user-1",
- "p_patch": {
- "manualViews": 7
- }
- },
- "filters": []
- },
- {
- "type": "select",
- "table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
- "filters": [
- [
- "id",
- "t-reddit"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
@@ -371,14 +168,12 @@
"type": "update",
"table": "tracked_posts",
"values": {
- "label": "New",
- "category": "Cat",
- "account_id": null
+ "category": ""
},
"filters": [
[
"id",
- "t-reddit"
+ "t-short"
],
[
"user_id",
@@ -389,62 +184,57 @@
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-reddit"
+ "t-short"
],
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
},
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-youtube"
+ "t-short"
],
[
"user_id",
"user-1"
- ]
- ]
- },
- {
- "type": "update",
- "table": "tracked_posts",
- "values": {
- "label": "Only label"
- },
- "filters": [
- [
- "id",
- "t-youtube"
],
[
- "user_id",
- "user-1"
+ "content_type",
+ "youtube"
]
]
},
{
"type": "select",
"table": "tracked_posts",
- "columns": "id, account_id, url, label, category, content_type, created_at, updated_at, data",
+ "columns": "id, url, label, category, content_type, created_at, updated_at, data",
"filters": [
[
"id",
- "t-youtube"
+ "t-short"
],
[
"user_id",
"user-1"
+ ],
+ [
+ "content_type",
+ "youtube"
]
]
}
diff --git a/backend/tests/routes/trackedContentRoutes.test.ts b/backend/tests/routes/trackedContentRoutes.test.ts
index 004e03d..bbd94a1 100644
--- a/backend/tests/routes/trackedContentRoutes.test.ts
+++ b/backend/tests/routes/trackedContentRoutes.test.ts
@@ -1,11 +1,10 @@
import { test, describe, before, after, afterEach, mock } from 'node:test';
-import assert from 'node:assert/strict';
import type { Mock } from 'node:test';
import trackedContentRouter from '../../routes/trackedContentRoutes.ts';
import { assertGolden } from '../fixtures/golden.ts';
import { installFetch, reply } from '../fixtures/fakeFetch.ts';
import type { FetchMock } from '../fixtures/fakeFetch.ts';
-import { fakeSupabase, accountRow, tableRow } from '../fixtures/fakeSupabase.ts';
+import { fakeSupabase, tableRow } from '../fixtures/fakeSupabase.ts';
import type { Row } from '../fixtures/fakeSupabase.ts';
import { mountWithContext, callRoute } from '../fixtures/routeHarness.ts';
import { mockRowIds } from '../fixtures/rowIds.ts';
@@ -15,21 +14,19 @@ import type { Env } from '../../types/env.ts';
const FIXED_NOW = Date.parse('2026-09-01T12:00:00Z');
const ENV = { YOUTUBE_API_KEY: 'YTKEY' };
-const REDDIT_POST = [{ data: { children: [{ data: { id: 'p1', title: 'Tracked', subreddit: 'webdev', score: 77, upvote_ratio: 0.93, num_comments: 8, permalink: '/r/webdev/comments/p1/tracked/', over_18: false, created_utc: 1785000000 } }] } }];
const YOUTUBE_VIDEO = { items: [{ snippet: { title: 'Watch', channelTitle: 'Ribbon', channelId: 'UC1', publishedAt: '2026-08-01T10:00:00Z', thumbnails: { medium: { url: 'm' } } }, statistics: { viewCount: '1500', likeCount: '40', commentCount: '3' } }] };
-function trackedRow(id: string, contentType: string, extra: { accountId?: string; url?: string; data?: Row } = {}) {
- return tableRow('tracked_posts', { id, user_id: 'user-1', account_id: extra.accountId ?? null, url: extra.url ?? `https://example/${id}`, label: '', category: '', content_type: contentType, created_at: '2026-08-01T00:00:00Z', updated_at: '2026-08-01T00:00:00Z', data: extra.data ?? {} });
+function trackedRow(id: string, contentType: string, extra: { userId?: string; url?: string; data?: Row } = {}) {
+ return tableRow('tracked_posts', { id, user_id: extra.userId ?? 'user-1', account_id: null, url: extra.url ?? `https://example/${id}`, label: '', category: '', content_type: contentType, created_at: '2026-08-01T00:00:00Z', updated_at: '2026-08-01T00:00:00Z', data: extra.data ?? {} });
}
function seedRows() {
return [
- tableRow('accounts', accountRow({ id: 'rd1', platform: 'reddit', username: 'ribbon', cookie: 'COOKIE' })),
- tableRow('accounts', accountRow({ id: 'yt1', platform: 'youtube', channelId: 'UC1' })),
- tableRow('accounts', accountRow({ id: 'rd-theirs', platform: 'reddit', username: 'other', cookie: 'THEIRS' }, 'user-2')),
- trackedRow('t-reddit', 'reddit', { accountId: 'rd1', url: 'https://www.reddit.com/r/webdev/comments/p1/tracked/', data: { title: 'Old', manualViews: 5 } }),
trackedRow('t-youtube', 'youtube', { url: 'https://www.youtube.com/watch?v=abc', data: { title: 'Video' } }),
- trackedRow('t-orphan', 'reddit', { accountId: 'gone', url: 'https://www.reddit.com/r/webdev/comments/p1/tracked/' }),
+ trackedRow('t-short', 'youtube', { url: 'https://www.youtube.com/shorts/def', data: { title: 'Short', viewCount: 9 } }),
+ trackedRow('t-theirs', 'youtube', { userId: 'user-2', url: 'https://youtu.be/ghi' }),
+ // a platform Twiligent no longer tracks; its rows stay in the table until they are cleaned up
+ trackedRow('t-retired', 'retired', { url: 'https://example.com/old-post', data: { title: 'Old' } }),
];
}
@@ -39,7 +36,7 @@ afterEach(() => fetchMock?.restore());
async function runCalls(calls: RouteStep[], env: Partial<Env> = ENV) {
const supabase = fakeSupabase(seedRows());
const app = mountWithContext(server => server.route('/', trackedContentRouter), { supabase, userId: 'user-1' });
- fetchMock = installFetch(request => (request.url.includes('googleapis') ? reply(YOUTUBE_VIDEO) : reply(REDDIT_POST)));
+ fetchMock = installFetch(() => reply(YOUTUBE_VIDEO));
const responses = [];
const logLines: unknown[][] = [];
mock.method(console, 'error', (...args: unknown[]) => logLines.push(['error', ...args]));
@@ -65,64 +62,39 @@ describe('tracked content routes golden output', () => {
mock.restoreAll();
});
- test('adding items validates the link and the reddit account', async () => {
+ test('adding a video validates the link and never links an account', async () => {
const result = await runCalls([
['POST', '/tracked-content', {}],
['POST', '/tracked-content', { url: 'https://example.com/post' }],
+ ['POST', '/tracked-content', { url: 'https://vimeo.com/123' }],
['POST', '/tracked-content', { url: ' https://www.youtube.com/watch?v=abc ', label: 'Video', category: 'Music' }],
- ['POST', '/tracked-content', { url: 'https://www.reddit.com/r/webdev/comments/p1/tracked/', accountId: 'yt1' }],
- ['POST', '/tracked-content', { url: 'https://www.reddit.com/r/webdev/comments/p1/tracked/', accountId: 'missing' }],
- ['POST', '/tracked-content', { url: 'https://www.reddit.com/r/webdev/comments/p1/tracked/', accountId: 'rd1', label: 'Mine' }],
- ['POST', '/tracked-content', { url: 'https://www.reddit.com/r/webdev/comments/p1/tracked/' }],
+ ['POST', '/tracked-content', { url: 'https://youtu.be/abc', accountId: 'acc-1', label: 'Mine' }],
]);
const withoutKey = await runCalls([['POST', '/tracked-content', { url: 'https://youtu.be/abc' }]], {});
assertGolden({ result, withoutKey }, 'trackedContentRoutes.create');
});
- test('updates check manual views and images before saving fields', async () => {
+ test('updates save the label and category and ignore fields that no longer exist', async () => {
const result = await runCalls([
['PUT', '/tracked-content/nope', { label: 'x' }],
- ['PUT', '/tracked-content/t-youtube', { manualViews: 10 }],
- ['PUT', '/tracked-content/t-youtube', { imageUrl: 'https://img/a.png' }],
- ['PUT', '/tracked-content/t-reddit', { manualViews: '' }],
- ['PUT', '/tracked-content/t-reddit', { manualViews: '12' }],
- ['PUT', '/tracked-content/t-reddit', { manualViews: -1 }],
- ['PUT', '/tracked-content/t-reddit', { manualViews: 1.5 }],
- ['PUT', '/tracked-content/t-reddit', { imageUrl: 'https://img/a b.png' }],
- ['PUT', '/tracked-content/t-reddit', { imageUrl: null }],
- ['PUT', '/tracked-content/t-reddit', { imageUrl: 'javascript:alert(1)' }],
- ['PUT', '/tracked-content/t-reddit', { manualViews: 7, imageUrl: 'http://img/a.png' }],
- ['PUT', '/tracked-content/t-reddit', { label: 'New', category: 'Cat', accountId: '' }],
- ['PUT', '/tracked-content/t-youtube', { label: 'Only label' }],
+ ['PUT', '/tracked-content/t-theirs', { label: 'x' }],
+ ['PUT', '/tracked-content/t-retired', { label: 'x' }],
+ ['PUT', '/tracked-content/t-youtube', { label: 'New', category: 'Cat' }],
+ ['PUT', '/tracked-content/t-short', { category: '' }],
+ ['PUT', '/tracked-content/t-short', { manualViews: 10, imageUrl: 'https://img/a.png', accountId: 'acc-1' }],
]);
assertGolden(result, 'trackedContentRoutes.update');
});
- test('an item can only move to a Reddit account the user owns, and a YouTube item to no account', async () => {
- const { responses } = await runCalls([
- ['PUT', '/tracked-content/t-reddit', { accountId: 'rd-theirs' }],
- ['PUT', '/tracked-content/t-reddit', { accountId: 'yt1' }],
- ['PUT', '/tracked-content/t-youtube', { accountId: 'rd1' }],
- ['PUT', '/tracked-content/t-reddit', { accountId: 'rd1' }],
- ]);
- const outcome = responses.map(response => [response.status, (JSON.parse(response.body) as { message?: string }).message ?? 'saved']);
- assert.deepEqual(outcome, [
- [404, 'Reddit account not found'],
- [404, 'Reddit account not found'],
- [400, 'YouTube videos are read without an account; remove the account from this item.'],
- [200, 'saved'],
- ]);
- });
-
test('list, refresh and delete', async () => {
const result = await runCalls([
['GET', '/tracked-content'],
- ['POST', '/tracked-content/t-reddit/refresh'],
- ['POST', '/tracked-content/t-orphan/refresh'],
+ ['POST', '/tracked-content/t-retired/refresh'],
['POST', '/tracked-content/t-youtube/refresh'],
['POST', '/tracked-content/nope/refresh'],
['DELETE', '/tracked-content/t-youtube'],
['DELETE', '/tracked-content/t-youtube'],
+ ['DELETE', '/tracked-content/t-retired'],
]);
const withoutKey = await runCalls([['POST', '/tracked-content/t-youtube/refresh']], {});
assertGolden({ result, withoutKey }, 'trackedContentRoutes.refresh');
diff --git a/backend/tests/services/trackedContentRules.test.ts b/backend/tests/services/trackedContentRules.test.ts
index b2d3d9f..f6da187 100644
--- a/backend/tests/services/trackedContentRules.test.ts
+++ b/backend/tests/services/trackedContentRules.test.ts
@@ -1,61 +1,18 @@
import { test, describe } from 'node:test';
import assert from 'node:assert/strict';
-import { detectContentType, manualViewsPatch, imageUrlPatch } from '../../services/trackedContentRules.ts';
+import { detectContentType } from '../../services/trackedContentRules.ts';
describe('detectContentType', () => {
- test('recognises reddit and youtube links in any case', () => {
- assert.equal(detectContentType('https://www.Reddit.com/r/x/comments/1'), 'reddit');
- assert.equal(detectContentType('https://redd.it/abc'), 'reddit');
+ test('recognises YouTube video and Shorts links in any case', () => {
assert.equal(detectContentType('https://youtu.be/xyz'), 'youtube');
- assert.equal(detectContentType('https://www.youtube.com/watch?v=1'), 'youtube');
+ assert.equal(detectContentType('https://www.YouTube.com/watch?v=1'), 'youtube');
+ assert.equal(detectContentType('https://www.youtube.com/shorts/abc'), 'youtube');
});
test('anything else is unsupported', () => {
+ assert.equal(detectContentType('https://vimeo.com/123'), null);
assert.equal(detectContentType('https://example.com'), null);
assert.equal(detectContentType(''), null);
assert.equal(detectContentType(undefined), null);
});
});
-
-describe('manualViewsPatch', () => {
- test('youtube items refuse manual views', () => {
- assert.deepEqual(manualViewsPatch(10, true), { error: 'YouTube view counts are fetched automatically and cannot be set by hand' });
- });
-
- test('empty values clear the count', () => {
- assert.deepEqual(manualViewsPatch(null, false), { patch: { manualViews: null } });
- assert.deepEqual(manualViewsPatch('', false), { patch: { manualViews: null } });
- });
-
- test('whole numbers of zero or more are stored as numbers', () => {
- assert.deepEqual(manualViewsPatch('42', false), { patch: { manualViews: 42 } });
- assert.deepEqual(manualViewsPatch(0, false), { patch: { manualViews: 0 } });
- });
-
- test('fractions, negatives and text are refused', () => {
- for (const value of ['1.5', -1, 'many']) {
- assert.deepEqual(manualViewsPatch(value, false), { error: 'Views must be a whole number of 0 or more' });
- }
- });
-});
-
-describe('imageUrlPatch', () => {
- test('youtube items refuse images', () => {
- assert.deepEqual(imageUrlPatch('https://x/y.png', true), { error: 'Images can only be attached to Reddit posts' });
- });
-
- test('empty values clear the image', () => {
- assert.deepEqual(imageUrlPatch(null, false), { patch: { imageUrl: null } });
- assert.deepEqual(imageUrlPatch('', false), { patch: { imageUrl: null } });
- });
-
- test('https urls are stored normalised', () => {
- assert.deepEqual(imageUrlPatch('https://res.cloudinary.com/a b.png', false), { patch: { imageUrl: 'https://res.cloudinary.com/a%20b.png' } });
- });
-
- test('other schemes and unparsable values are refused', () => {
- for (const value of ['http://x/y.png', 'javascript:alert(1)', 'data:image/png;base64,AA', 'not a url']) {
- assert.deepEqual(imageUrlPatch(value, false), { error: 'Image must be an https URL returned by the uploader' });
- }
- });
-});
diff --git a/backend/validators/trackedContentValidators.ts b/backend/validators/trackedContentValidators.ts
index 45d8f7e..52e5864 100644
--- a/backend/validators/trackedContentValidators.ts
+++ b/backend/validators/trackedContentValidators.ts
@@ -1,36 +1,19 @@
-import { ValidationError } from '../lib/errors.ts';
import { optionalString, presentField, requiredString } from './fields.ts';
import type { Fields } from './fields.ts';
import type { NewTrackedContent, TrackedContentChanges } from '../services/trackedContentService.ts';
-// an account id may be sent as null to unlink the account
-function optionalAccountId(body: Fields): string | null | undefined {
- if (body.accountId === null) return null;
- return optionalString(body, 'accountId');
-}
-
export function parseNewTrackedContent(body: Fields): NewTrackedContent {
return {
url: requiredString(body, 'url', 'url is required'),
- accountId: optionalAccountId(body),
label: optionalString(body, 'label'),
category: optionalString(body, 'category'),
};
}
-// manualViews and imageUrl keep their raw value: the tracked content rules explain what is wrong with it
+// only the label and category can change; the video's own numbers come from YouTube
export function parseTrackedContentChanges(body: Fields): TrackedContentChanges {
- for (const field of ['manualViews', 'imageUrl']) {
- const value = body[field];
- if (value !== undefined && value !== null && typeof value !== 'string' && typeof value !== 'number') {
- throw new ValidationError(`${field} must be text or a number`);
- }
- }
const changes: TrackedContentChanges = {};
if (presentField(body, 'label')) changes.label = optionalString(body, 'label') ?? '';
if (presentField(body, 'category')) changes.category = optionalString(body, 'category') ?? '';
- if (presentField(body, 'accountId')) changes.accountId = optionalAccountId(body) ?? null;
- if (presentField(body, 'manualViews')) changes.manualViews = body.manualViews;
- if (presentField(body, 'imageUrl')) changes.imageUrl = body.imageUrl;
return changes;
}
diff --git a/shared/types/domain.ts b/shared/types/domain.ts
index bb5d7d4..81c3c73 100644
--- a/shared/types/domain.ts
+++ b/shared/types/domain.ts
@@ -1,5 +1,4 @@
import type { InstagramContentTypeSummary } from './instagram.ts';
-import type { RedditTrackedPostData } from './reddit.ts';
import type { YouTubeTrackedVideoData } from './youtube.ts';
export type Platform = 'youtube' | 'instagram' | 'reddit';
@@ -139,11 +138,9 @@ export interface ScheduledPublishRun {
// one row of `tracked_posts`; fields refreshed from the platform live in the data jsonb
export interface TrackedPost {
id: string;
- accountId: string | null;
url: string;
label: string;
category: string;
- // 'reddit' unless the row says otherwise
contentType: string;
createdAt: string;
updatedAt: string;
@@ -346,29 +343,18 @@ export interface ScheduledPostRequest {
export type ScheduledPostUpdateRequest = Partial<Pick<ScheduledPost,
'caption' | 'scheduledAt' | 'shareToFeed' | 'collaborators' | 'audioName' | 'thumbOffset' | 'locationId' | 'userTags' | 'altText' | 'coverUrl'>>;
-// fields the user types in for a reddit post, kept in the data jsonb next to the fetched ones
-export interface TrackedPostManualFields {
- manualViews?: number | null;
- imageUrl?: string | null;
-}
-
-// a tracked post with the fetched fields of whichever platform it tracks
-export type TrackedContentItem = TrackedPost
- & Partial<RedditTrackedPostData>
- & Partial<Omit<YouTubeTrackedVideoData, 'contentType'>>
- & TrackedPostManualFields;
+// a tracked video with the fields fetched from YouTube
+export type TrackedContentItem = TrackedPost & Partial<Omit<YouTubeTrackedVideoData, 'contentType'>>;
// body of POST /api/tracked-content
export interface TrackedContentAddRequest {
url: string;
- accountId?: string | null;
label?: string;
category?: string;
}
-// body of PUT /api/tracked-content/:id; null clears manualViews or imageUrl
-export interface TrackedContentUpdateRequest extends TrackedPostManualFields {
+// body of PUT /api/tracked-content/:id
+export interface TrackedContentUpdateRequest {
label?: string;
category?: string;
- accountId?: string | null;
}