Merge pull request #22 from movie-web/dev
v1.1.5 - Progress importing now uses the user's date
This commit is contained in:
commit
e173003f55
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "backend",
|
"name": "backend",
|
||||||
"version": "1.1.4",
|
"version": "1.1.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"homepage": "https://github.com/movie-web/backend",
|
"homepage": "https://github.com/movie-web/backend",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -18,6 +18,7 @@ const progressItemSchema = z.object({
|
||||||
episodeId: z.string().optional(),
|
episodeId: z.string().optional(),
|
||||||
seasonNumber: z.number().optional(),
|
seasonNumber: z.number().optional(),
|
||||||
episodeNumber: z.number().optional(),
|
episodeNumber: z.number().optional(),
|
||||||
|
updatedAt: z.string().datetime({ offset: true }).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const userProgressRouter = makeRouter((app) => {
|
export const userProgressRouter = makeRouter((app) => {
|
||||||
|
@ -100,7 +101,9 @@ export const userProgressRouter = makeRouter((app) => {
|
||||||
if (newItemIndex > -1) {
|
if (newItemIndex > -1) {
|
||||||
const newItem = newItems[newItemIndex];
|
const newItem = newItems[newItemIndex];
|
||||||
if (existingItem.watched < newItem.watched) {
|
if (existingItem.watched < newItem.watched) {
|
||||||
existingItem.updatedAt = new Date();
|
existingItem.updatedAt = defaultAndCoerceDateTime(
|
||||||
|
newItem.updatedAt,
|
||||||
|
);
|
||||||
existingItem.watched = newItem.watched;
|
existingItem.watched = newItem.watched;
|
||||||
}
|
}
|
||||||
itemsUpserted.push(existingItem);
|
itemsUpserted.push(existingItem);
|
||||||
|
@ -123,7 +126,7 @@ export const userProgressRouter = makeRouter((app) => {
|
||||||
tmdbId: newItem.tmdbId,
|
tmdbId: newItem.tmdbId,
|
||||||
userId: params.uid,
|
userId: params.uid,
|
||||||
watched: newItem.watched,
|
watched: newItem.watched,
|
||||||
updatedAt: new Date(),
|
updatedAt: defaultAndCoerceDateTime(newItem.updatedAt),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,3 +210,14 @@ export const userProgressRouter = makeRouter((app) => {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 13th July 2021 - movie-web epoch
|
||||||
|
const minEpoch = 1626134400000;
|
||||||
|
|
||||||
|
function defaultAndCoerceDateTime(dateTime: string | undefined) {
|
||||||
|
const epoch = dateTime ? new Date(dateTime).getTime() : Date.now();
|
||||||
|
|
||||||
|
const clampedEpoch = Math.max(minEpoch, Math.min(epoch, Date.now()));
|
||||||
|
|
||||||
|
return new Date(clampedEpoch);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue