mirror of
https://github.com/p-stream/backend.git
synced 2026-04-21 07:52:18 +00:00
Fix for Watch-history PUT masks 400
This commit is contained in:
parent
8e8fd83164
commit
cd6704eafb
1 changed files with 10 additions and 9 deletions
|
|
@ -52,16 +52,17 @@ export default defineEventHandler(async event => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'PUT') {
|
if (method === 'PUT') {
|
||||||
try {
|
const body = await readBody(event);
|
||||||
const body = await readBody(event);
|
|
||||||
|
|
||||||
// Accept single object (normal playback) or array (e.g. user import)
|
// Accept single object (normal playback) or array (e.g. user import)
|
||||||
const bodySchema = z.union([
|
const bodySchema = z.union([
|
||||||
watchHistoryItemSchema,
|
watchHistoryItemSchema,
|
||||||
z.array(watchHistoryItemSchema).max(1000),
|
z.array(watchHistoryItemSchema).max(1000),
|
||||||
]);
|
]);
|
||||||
const parsed = bodySchema.parse(body);
|
const parsed = bodySchema.parse(body);
|
||||||
const items = Array.isArray(parsed) ? parsed : [parsed];
|
const items = Array.isArray(parsed) ? parsed : [parsed];
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
const upsertPromises = items.map(validatedBody => {
|
const upsertPromises = items.map(validatedBody => {
|
||||||
const itemTmdbId = items.length === 1 ? tmdbId : (validatedBody.tmdbId ?? tmdbId);
|
const itemTmdbId = items.length === 1 ? tmdbId : (validatedBody.tmdbId ?? tmdbId);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue