Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const progressResponseSchema = z.object({
completed: z.number().int(),
last_watched_at: z.string().datetime().nullish(),
reset_at: z.null(),
next_episode: episodeResponseSchema,
next_episode: episodeResponseSchema.or(z.null()),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to get null next_episode in case of intent "completed" for example.

last_episode: episodeResponseSchema.or(z.null()),
/***
* Available if requesting include_stats `true`.
Expand Down
88 changes: 25 additions & 63 deletions projects/api/src/contracts/scrobble/index.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,36 @@
import { authMetadata, builder } from '../_internal/builder.ts';
import { extendedQuerySchemaFactory } from '../_internal/request/extendedQuerySchemaFactory.ts';
import type { z } from '../_internal/z.ts';
import { z } from '../_internal/z.ts';
import { episodeScrobbleRequestSchema } from './schema/request/episodeScrobbleRequestSchema.ts';
import { movieScrobbleRequestSchema } from './schema/request/movieScrobbleRequestSchema.ts';
import { episodeScrobbleResponseSchema } from './schema/response/episodeScrobbleResponseSchema.ts';
import { movieScrobbleResponseSchema } from './schema/response/movieScrobbleResponseSchema.ts';

export const scrobble = builder.router({
movie: builder.router({
start: {
path: '/start',
method: 'POST',
body: movieScrobbleRequestSchema,
query: extendedQuerySchemaFactory<['full', 'images']>(),
responses: {
201: movieScrobbleResponseSchema,
},
start: {
path: '/start',
method: 'POST',
body: z.union([movieScrobbleRequestSchema, episodeScrobbleRequestSchema]),
responses: {
201: z.union([movieScrobbleResponseSchema, episodeScrobbleResponseSchema]),
},
pause: {
path: '/pause',
method: 'POST',
body: movieScrobbleRequestSchema,
query: extendedQuerySchemaFactory<['full', 'images']>(),
responses: {
201: movieScrobbleResponseSchema,
},
},
pause: {
path: '/pause',
method: 'POST',
body: z.union([movieScrobbleRequestSchema, episodeScrobbleRequestSchema]),
responses: {
201: z.union([movieScrobbleResponseSchema, episodeScrobbleResponseSchema]),
},
stop: {
path: '/stop',
method: 'POST',
body: movieScrobbleRequestSchema,
query: extendedQuerySchemaFactory<['full', 'images']>(),
responses: {
201: movieScrobbleResponseSchema,
},
},
stop: {
path: '/stop',
method: 'POST',
body: z.union([movieScrobbleRequestSchema, episodeScrobbleRequestSchema]),
responses: {
201: z.union([movieScrobbleResponseSchema, episodeScrobbleResponseSchema]),
},
}),
episode: builder.router({
start: {
path: '/start',
method: 'POST',
body: episodeScrobbleRequestSchema,
query: extendedQuerySchemaFactory<['full', 'images']>(),
responses: {
201: episodeScrobbleResponseSchema,
},
},
pause: {
path: '/pause',
method: 'POST',
body: episodeScrobbleRequestSchema,
query: extendedQuerySchemaFactory<['full', 'images']>(),
responses: {
201: episodeScrobbleResponseSchema,
},
},
stop: {
path: '/stop',
method: 'POST',
body: episodeScrobbleRequestSchema,
query: extendedQuerySchemaFactory<['full', 'images']>(),
responses: {
201: episodeScrobbleResponseSchema,
},
},
}),
},
}, {
pathPrefix: '/scrobble',
metadata: authMetadata('required'),
Expand All @@ -78,10 +44,6 @@ export {
};

export type MovieScrobbleRequest = z.infer<typeof movieScrobbleRequestSchema>;
export type MovieScrobbleResponse = z.infer<typeof movieScrobbleRequestSchema>;
export type EpisodeScrobbleRequest = z.infer<
typeof episodeScrobbleRequestSchema
>;
export type EpisodeScrobbleResponse = z.infer<
typeof episodeScrobbleRequestSchema
>;
export type MovieScrobbleResponse = z.infer<typeof movieScrobbleResponseSchema>;
export type EpisodeScrobbleRequest = z.infer<typeof episodeScrobbleRequestSchema>;
export type EpisodeScrobbleResponse = z.infer<typeof episodeScrobbleResponseSchema>;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
episodeIdsRequestSchema,
} from '../../../_internal/request/idsRequestSchema.ts';
import { z } from '../../../_internal/z.ts';
import {float, z} from '../../../_internal/z.ts';

export const episodeScrobbleRequestSchema = z.object({
progress: z.number().int(),
progress: float(z.number()),
episode: z.object({
ids: episodeIdsRequestSchema,
}),
}).nullish(),
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {
movieIdsRequestSchema,
} from '../../../_internal/request/idsRequestSchema.ts';
import { z } from '../../../_internal/z.ts';
import {float, z} from '../../../_internal/z.ts';

/*
FIXME: verify data structure of the standard media
schemas and reuse where applicable.
*/

export const movieScrobbleRequestSchema = z.object({
progress: z.number().int(),
progress: float(z.number()),
movie: z.object({
title: z.string(),
year: z.number().int(),
ids: movieIdsRequestSchema,
}),
}).nullish(),
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { episodeResponseSchema } from '../../../_internal/response/episodeResponseSchema.ts';
import { showResponseSchema } from '../../../_internal/response/showResponseSchema.ts';
import { asString, z } from '../../../_internal/z.ts';
import { asString, float, int64, z } from '../../../_internal/z.ts';

export const episodeScrobbleResponseSchema = z.object({
id: z.number().int(),
id: int64(z.number().int()),
progress: float(z.number()),
action: asString(z.enum(['start', 'pause', 'stop'])),
episode: episodeResponseSchema,
show: showResponseSchema,
episode: episodeResponseSchema.nullish(),
show: showResponseSchema.nullish(),
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { movieResponseSchema } from '../../../_internal/response/movieResponseSchema.ts';
import { asString, z } from '../../../_internal/z.ts';
import { asString, float, int64, z } from '../../../_internal/z.ts';

export const movieScrobbleResponseSchema = z.object({
id: z.number().int(),
id: int64(z.number().int()),
progress: float(z.number()),
action: asString(z.enum(['start', 'pause', 'stop'])),
movie: movieResponseSchema,
movie: movieResponseSchema.nullish(),
});
1 change: 1 addition & 0 deletions projects/api/src/contracts/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const progress = builder.router({
method: 'GET',
path: '/progress/up_next_nitro',
query: pageQuerySchema
.merge(sortQuerySchema)
.merge(upNextIntentQuerySchema),
responses: {
200: upNextResponseSchema.array(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { z } from '../../../_internal/z.ts';

export const playbackIdParamsSchema = z.object({
id: z.number().int().or(z.string()).describe(
'ID of the playback entry',
),
id: z.number().int().describe('ID of the playback entry'),
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { z } from '../../../_internal/z.ts';

export const coverRequestSchema = z.object({
cover_type: z.enum(['movie', 'show', 'episode']),
cover_id: z.number(),
cover_id: z.number().int(),
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { z } from '../../../_internal/z.ts';

export const filterIdParamsSchema = z.object({
id: z.number().int().or(z.string()).describe(
'ID of the saved filter',
),
id: z.number().int().describe('ID of the saved filter'),
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { z } from '../../../_internal/z.ts';
import { episodeResponseSchema } from '../../../_internal/response/episodeResponseSchema.ts';
import { movieResponseSchema } from '../../../_internal/response/movieResponseSchema.ts';
import { showResponseSchema } from '../../../_internal/response/showResponseSchema.ts';
import { int64, z } from '../../../_internal/z.ts';
import { historyActionSchema } from './historyActionSchema.ts';

import { episodeActivityHistoryResponseSchema } from './episodeActivityHistoryResponseSchema.ts';
import { movieActivityHistoryResponseSchema } from './movieActivityHistoryResponseSchema.ts';
const historyBaseSchema = z.object({
id: int64(z.number().int()),
watched_at: z.string().datetime(),
action: historyActionSchema,
});

export const activityHistoryResponseSchema = z.discriminatedUnion('type', [
movieActivityHistoryResponseSchema,
episodeActivityHistoryResponseSchema,
const historyEpisodeSchema = z.object({
type: z.literal('episode'),
episode: episodeResponseSchema.nullish(),
show: showResponseSchema.nullish(),
});

const historyMovieSchema = z.object({
type: z.literal('movie'),
movie: movieResponseSchema.nullish(),
});

export const activityHistoryResponseSchema = z.union([
historyBaseSchema.merge(historyEpisodeSchema),
historyBaseSchema.merge(historyMovieSchema),
]);
15 changes: 9 additions & 6 deletions projects/api/src/contracts/users/subroutes/watched.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { builder } from '../../_internal/builder.ts';
import { extendedQuerySchemaFactory } from '../../_internal/request/extendedQuerySchemaFactory.ts';
import { pageQuerySchema } from '../../_internal/request/pageQuerySchema.ts';
import { z } from '../../_internal/z.ts';
import { showQueryParamsSchema } from '../../shows/schema/request/showQueryParamsSchema.ts';
import { minimalParamSchema } from '../../sync/schema/request/minimalParamSchema.ts';
Expand Down Expand Up @@ -33,7 +34,7 @@ export const watched = builder.router({
path: '/movies',
method: 'GET',
pathParams: profileParamsSchema,
query: minimalParamSchema,
query: minimalParamSchema.merge(pageQuerySchema),
responses: {
200: watchedMoviesMinimalResponseSchema,
},
Expand All @@ -42,11 +43,13 @@ export const watched = builder.router({
path: '/shows',
method: 'GET',
pathParams: profileParamsSchema,
query: minimalParamSchema.merge(
showQueryParamsSchema.pick({ specials: true }),
).extend({
season_numbers: z.boolean().nullish(),
}),
query: minimalParamSchema
.merge(pageQuerySchema)
.merge(
showQueryParamsSchema.pick({ specials: true }),
).extend({
season_numbers: z.boolean().nullish(),
}),
responses: {
200: watchedShowsMinimalResponseSchema,
},
Expand Down
Loading