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
47 changes: 40 additions & 7 deletions projects/api/src/contracts/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { listRemoveResponseSchema } from '../_internal/response/listRemoveRespon
import { z } from '../_internal/z.ts';
import { reorderRequestSchema } from '../users/schema/request/reorderRequestSchema.ts';
import { reorderListResponseSchema } from '../users/schema/response/reorderListResponseSchema.ts';
import { collectionAddRequestSchema } from './schema/request/collectionAddRequestSchema.ts';
import { collectionParamSchema } from './schema/request/collectionParamSchema.ts';
import { favoriteParamSchema } from './schema/request/favoritesParamSchema.ts';
import { historyRemoveRequestSchema } from './schema/request/historyRemoveRequestSchema.ts';
Expand All @@ -22,10 +23,12 @@ import { progressParamsSchema } from './schema/request/progressParamsSchema.ts';
import { ratingsParamSchema } from './schema/request/ratingsParamSchema.ts';
import { removeRatingsParamSchema } from './schema/request/removeRatingsParamSchema.ts';
import { upNextIntentQuerySchema } from './schema/request/upNextIntentQuerySchema.ts';
import { collectionAddResponseSchema } from './schema/response/collectionAddResponseSchema.ts';
import {
collectionMinimalResponseSchema,
collectionMinimalShowResponseSchema,
} from './schema/response/collectionMinimalResponseSchema.ts';
import { collectionRemoveResponseSchema } from './schema/response/collectionRemoveResponseSchema.ts';
import {
collectedEpisodeSchema,
collectedMovieSchema,
Expand Down Expand Up @@ -619,24 +622,46 @@ Returns movies, shows, and episodes in the authenticated user collection. Use \`
},
add: {
summary: 'Add items to collection',
description:
'Add items to a user collection. Accepts shows, seasons, episodes, and movies.',
description: `#### 🔒 OAuth Required
Add items to a user collection. Accepts shows, seasons, episodes and movies. A show adds its aired episodes, specials excluded; a season adds its aired episodes. A movie or episode without a release date is returned in \`not_found\`.

Sending an item that is already collected with different metadata updates it, \`collected_at\` included; a new \`collected_at\` alone is ignored. Metadata left out of the request is cleared.

#### JSON POST Data
| Key | Type | Value |
|---|---|---|
| \`movies\` | array | Array of \`movie\` objects. (see examples ->) |
| \`shows\` | array | Array of \`show\` objects. |
| \`seasons\` | array | Array of \`season\` objects. |
| \`episodes\` | array | Array of \`episode\` objects. |

#### Media Object POST Data
| Key | Type | Value |
|---|---|---|
| item * | object | \`movie\`, \`show\`, \`season\`, or \`episode\` object. |
| \`collected_at\` | datetime | UTC datetime when the item was collected. Set to \`released\` for the release date, \`unknown\` for no specific date, or \`now\`. |
| \`media_type\` | string | Physical or digital format, e.g. \`bluray\`. |
| \`resolution\` | string | e.g. \`uhd_4k\`. |
| \`hdr\` | string | e.g. \`dolby_vision\`. |
| \`audio\` | string | e.g. \`dolby_atmos\`. |
| \`audio_channels\` | string | e.g. \`7.1\`. |
| \`3d\` | boolean | Set to \`true\` for 3D media. |`,
method: 'POST',
path: '',
body: mediaItemsRequestSchema,
body: collectionAddRequestSchema,
responses: {
201: listAddResponseSchema,
201: collectionAddResponseSchema,
},
},
remove: {
summary: 'Remove items from collection',
description:
'Remove items from a user collection. Accepts shows, seasons, episodes, and movies.',
description: `#### 🔒 OAuth Required
Remove items from a user collection. Accepts shows, seasons, episodes and movies. A show or season removes every collected episode it holds.`,
method: 'POST',
path: '/remove',
body: mediaItemsRequestSchema,
responses: {
200: listRemoveResponseSchema,
200: collectionRemoveResponseSchema,
},
},
minimal: builder.router(
Expand Down Expand Up @@ -788,6 +813,14 @@ export type FavoritesRemoveResponse = z.infer<

/** The collection request payload. */
export type CollectionRequest = z.infer<typeof collectionParamSchema>;
/** The collection add request payload. */
export type CollectionAddRequest = z.infer<typeof collectionAddRequestSchema>;
/** The collection add response payload. */
export type CollectionAddResponse = z.infer<typeof collectionAddResponseSchema>;
/** The collection remove response payload. */
export type CollectionRemoveResponse = z.infer<
typeof collectionRemoveResponseSchema
>;
/** The collection response payload. */
export type CollectionResponse = z.infer<typeof collectionResponseSchema>;
/** The collection movie response payload. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { mediaItemsRequestSchemaFactory } from '../../../_internal/request/mediaItemsRequestSchemaFactory.ts';
import { z } from '../../../_internal/z.ts';

/** Zod schema for the collection add request. */
export const collectionAddRequestSchema = mediaItemsRequestSchemaFactory({
collected_at: z
.union([z.string().datetime(), z.enum(['released', 'unknown', 'now'])])
.nullish()
.openapi({
description:
'When the item was collected: a UTC datetime, `released` for its release date, `unknown` for no specific date, or `now` for the current time. Defaults to the stored date, else now.',
}),
media_type: z
.enum([
'digital',
'bluray',
'hddvd',
'dvd',
'vcd',
'vhs',
'betamax',
'laserdisc',
])
.nullish(),
resolution: z
.enum([
'uhd_4k',
'hd_1080p',
'hd_1080i',
'hd_720p',
'sd_480p',
'sd_480i',
'sd_576p',
'sd_576i',
])
.nullish(),
hdr: z.enum(['dolby_vision', 'hdr10', 'hdr10_plus', 'hlg']).nullish(),
audio: z
.enum([
'lpcm',
'mp3',
'mp2',
'aac',
'ogg',
'ogg_opus',
'wma',
'flac',
'dts',
'dts_ma',
'dts_hr',
'dts_x',
'auro_3d',
'dolby_digital',
'dolby_digital_plus',
'dolby_digital_plus_atmos',
'dolby_atmos',
'dolby_truehd',
'dolby_prologic',
])
.nullish(),
audio_channels: z
.enum([
'1.0',
'2.0',
'2.1',
'3.0',
'3.1',
'4.0',
'4.1',
'5.0',
'5.1',
'5.1.2',
'5.1.4',
'6.1',
'7.1',
'7.1.2',
'7.1.4',
'9.1',
'10.1',
])
.nullish(),
'3d': z.boolean().nullish(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { z } from '../../../_internal/z.ts';
import { collectionAddRequestSchema } from '../request/collectionAddRequestSchema.ts';

const collectedCountsSchema = z.object({
movies: z.number().int(),
episodes: z.number().int(),
});

/** Zod schema for the collection add response. */
export const collectionAddResponseSchema = z.object({
added: collectedCountsSchema,
/** Already collected; the date or metadata changed. Metadata left out of the request is cleared. */
updated: collectedCountsSchema,
/** Already collected with the same date and metadata. */
existing: collectedCountsSchema,
/** Items echoed as sent. A movie or episode without a release date is echoed as `{ ids: { trakt } }`. */
not_found: collectionAddRequestSchema,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { mediaItemsRequestSchema } from '../../../_internal/request/mediaItemsRequestSchema.ts';
import { z } from '../../../_internal/z.ts';

/** Zod schema for the collection remove response. */
export const collectionRemoveResponseSchema = z.object({
deleted: z.object({ movies: z.number().int(), episodes: z.number().int() }),
not_found: mediaItemsRequestSchema,
});
Loading