fix: correctly merge edit data with non-form play data

This commit is contained in:
FoxxMD 2026-10-09 20:00:35 +00:00
parent 39e7af3fdf
commit 591888e97a
2 changed files with 20 additions and 6 deletions

View file

@ -1116,15 +1116,27 @@ export default abstract class AbstractComponent extends AbstractInitializable {
abstract processPlay(playEntity: PlaySelectWithQueueStates, signal?: AbortSignal): Promise<PlayProcessingResult>
public async updatePlay(uid: string, data: Partial<TrackData>): Promise<PlayApiCommonDetailed> {
public async updatePlay(uid: string, data: Partial<PlayData>): Promise<PlayApiCommonDetailed> {
const playRow = await this.playRepo.findByUidWith<'events'>(uid, ['events']);
if(playRow === undefined) {
throw new SimpleError(`No play exists with uid ${uid}`);
}
const original = JSON.parse(JSON.stringify(playRow.play));
playRow.play.data = {
...data
const merged: PlayData = {
...playRow.play.data,
...data,
repeat: playRow.play.data.repeat
};
const samePlayDate = data.playDate?.isSame(playRow.play.data.playDate);
if(playRow.play.data.listenRanges !== undefined && samePlayDate) {
merged.listenRanges = playRow.play.data.listenRanges
merged.playDateCompleted = playRow.play.data.playDateCompleted;
} else if(data.listenedFor !== undefined) {
merged.playDateCompleted = data.playDate?.add(data.listenedFor, 's')
}
playRow.play.data = merged;
const modified = JSON.parse(JSON.stringify(playRow.play));
const patch = diffObjects(original, modified);
const event = playUpdateToEvent({input: {data}, patch});

View file

@ -13,6 +13,7 @@ import {
albumSearchToMusicService,
artistSearchToMusicService,
playEditStrictCreateSchema,
type PlayObject,
} from "../../core/Atomic.ts";
import type {LeveledLogData} from "../common/infrastructure/Atomic.ts";
import { getRoot } from "../ioc.ts";
@ -42,6 +43,7 @@ import pMap from "p-map";
import type { PlayWith } from "../common/database/drizzle/drizzleTypes.ts";
import { stripIndents } from "common-tags";
import { nameToCredit } from "../../core/MusicMetadata.ts";
import { asPlayCheap } from "../../core/PlayMarshalUtils.ts";
const maxBufferSize = 300;
const output: Record<number, FixedSizeList<LogDataPretty>> = {};
@ -497,9 +499,9 @@ Note: this is only supported by some components.`
body
} = req;
const playRes = await component.updatePlay(playUid as string, body.data);
//PlayApiCommonDetailed
// plus paginatioon
const play: PlayObject = asPlayCheap(body);
const playRes = await component.updatePlay(playUid as string, play.data);
return res.json(asSerializablePlaySelect(playRes));
});