Skip to content

Commit 02527d1

Browse files
lixiyuan1030-stackvladjerca
authored andcommitted
feat(sync): add last_activities contract
1 parent f62703f commit 02527d1

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

projects/api/src/contracts/sync/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { favoritesRemoveResponseSchema } from './schema/response/favoritesRemove
3232
import { favoritesResponseSchema } from './schema/response/favoritesResponseSchema.ts';
3333
import { historyRemoveResponseSchema } from './schema/response/historyRemoveResponseSchema.ts';
3434
import { historyResponseSchema } from './schema/response/historyResponseSchema.ts';
35+
import { lastActivitiesResponseSchema } from './schema/response/lastActivitiesResponseSchema.ts';
3536
import { movieProgressResponseSchema } from './schema/response/movieProgressResponseSchema.ts';
3637
import { ratingsSyncResponseSchema } from './schema/response/ratingsResponseSchema.ts';
3738
import { removeRatingsResponseSchema } from './schema/response/removeRatingsResponseSchema.ts';
@@ -420,6 +421,16 @@ Returns the authenticated user episode collection in a minimal format optimized
420421
});
421422

422423
export const sync = builder.router({
424+
lastActivities: {
425+
summary: 'Get last activity',
426+
description: `#### 🔒 OAuth Required
427+
Returns the latest activity timestamps for the authenticated user. Cache these dates locally and compare them before syncing to avoid fetching data that has not changed.`,
428+
method: 'GET',
429+
path: '/last_activities',
430+
responses: {
431+
200: lastActivitiesResponseSchema,
432+
},
433+
},
423434
history,
424435
progress,
425436
watchlist,
@@ -441,6 +452,7 @@ export {
441452
favoritesResponseSchema,
442453
historyRemoveRequestSchema,
443454
historyResponseSchema,
455+
lastActivitiesResponseSchema,
444456
minimalParamSchema,
445457
movieProgressResponseSchema,
446458
ratingsParamSchema,
@@ -458,6 +470,9 @@ export type HistoryAddRequest = z.infer<typeof bulkMediaRequestSchema>;
458470
export type HistoryRemoveRequest = z.infer<typeof historyRemoveRequestSchema>;
459471
export type HistoryResponse = z.infer<typeof historyResponseSchema>;
460472
export type HistoryRemoveResponse = z.infer<typeof historyRemoveResponseSchema>;
473+
export type LastActivitiesResponse = z.infer<
474+
typeof lastActivitiesResponseSchema
475+
>;
461476

462477
export type WatchlistRequest = z.infer<typeof listRequestSchema>;
463478

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { z } from '../../../_internal/z.ts';
2+
3+
const timestampSchema = z.string().datetime();
4+
5+
const movieActivitiesSchema = z.object({
6+
watched_at: timestampSchema,
7+
collected_at: timestampSchema,
8+
rated_at: timestampSchema,
9+
watchlisted_at: timestampSchema,
10+
favorited_at: timestampSchema,
11+
commented_at: timestampSchema,
12+
paused_at: timestampSchema,
13+
hidden_at: timestampSchema,
14+
});
15+
16+
const episodeActivitiesSchema = z.object({
17+
watched_at: timestampSchema,
18+
collected_at: timestampSchema,
19+
rated_at: timestampSchema,
20+
watchlisted_at: timestampSchema,
21+
commented_at: timestampSchema,
22+
paused_at: timestampSchema,
23+
});
24+
25+
const showActivitiesSchema = z.object({
26+
rated_at: timestampSchema,
27+
watchlisted_at: timestampSchema,
28+
favorited_at: timestampSchema,
29+
commented_at: timestampSchema,
30+
hidden_at: timestampSchema,
31+
dropped_at: timestampSchema,
32+
});
33+
34+
const seasonActivitiesSchema = z.object({
35+
rated_at: timestampSchema,
36+
watchlisted_at: timestampSchema,
37+
commented_at: timestampSchema,
38+
hidden_at: timestampSchema,
39+
});
40+
41+
const commentActivitiesSchema = z.object({
42+
liked_at: timestampSchema,
43+
reacted_at: timestampSchema,
44+
blocked_at: timestampSchema,
45+
});
46+
47+
const listActivitiesSchema = z.object({
48+
liked_at: timestampSchema,
49+
reacted_at: timestampSchema,
50+
updated_at: timestampSchema,
51+
commented_at: timestampSchema,
52+
});
53+
54+
const updatedActivitiesSchema = z.object({
55+
updated_at: timestampSchema,
56+
});
57+
58+
const accountActivitiesSchema = z.object({
59+
settings_at: timestampSchema,
60+
followed_at: timestampSchema,
61+
following_at: timestampSchema,
62+
pending_at: timestampSchema,
63+
requested_at: timestampSchema,
64+
});
65+
66+
export const lastActivitiesResponseSchema = z.object({
67+
all: timestampSchema,
68+
movies: movieActivitiesSchema,
69+
episodes: episodeActivitiesSchema,
70+
shows: showActivitiesSchema,
71+
seasons: seasonActivitiesSchema,
72+
comments: commentActivitiesSchema,
73+
lists: listActivitiesSchema,
74+
watchlist: updatedActivitiesSchema,
75+
favorites: updatedActivitiesSchema,
76+
collaborations: updatedActivitiesSchema,
77+
account: accountActivitiesSchema,
78+
saved_filters: updatedActivitiesSchema,
79+
notes: updatedActivitiesSchema,
80+
});

0 commit comments

Comments
 (0)