19 Commits
1.1.2 ... 1.1.5

Author SHA1 Message Date
William Oldham
e173003f55 Merge pull request #22 from movie-web/dev
v1.1.5 - Progress importing now uses the user's date
2023-12-06 20:03:22 +00:00
William Oldham
9f90ba7da2 Merge pull request #21 from movie-web/progress-date
Add UpdatedAt from User date for Progress
2023-12-06 20:01:35 +00:00
William Oldham
05bf651939 Revert "Use date to compare progress items"
This reverts commit cf0125755c.
2023-12-06 19:59:50 +00:00
William Oldham
cf0125755c Use date to compare progress items 2023-12-06 19:55:09 +00:00
William Oldham
4129b80828 Use movie-web birthday 2023-12-06 19:49:30 +00:00
William Oldham
e5c3cde51b Only use user date on bulk import 2023-12-06 19:46:22 +00:00
William Oldham
4bf0285d06 Bump version 2023-12-06 19:43:57 +00:00
William Oldham
53d5ca1461 Add updatedAt saving into progress imports 2023-12-06 19:43:37 +00:00
mrjvs
3211f74387 Merge pull request #20 from movie-web/dev
V1.1.4
2023-11-25 17:21:20 +01:00
mrjvs
8cffd0e7e8 Merge branch 'master' into dev 2023-11-25 17:11:46 +01:00
mrjvs
c531329931 Merge pull request #19 from movie-web/device-name-fix
Remove duplicate session router
2023-11-25 17:09:20 +01:00
mrjvs
690357ba5a bump version 2023-11-25 16:09:55 +01:00
mrjvs
10e9e06c27 only have one session router 2023-11-25 16:09:29 +01:00
mrjvs
783d89492d Merge pull request #18 from movie-web/dev
Version 1.1.3: Add endpoint to edit device name
2023-11-24 20:07:57 +01:00
mrjvs
4663b2c1f7 Merge branch 'master' into dev 2023-11-24 20:06:42 +01:00
William Oldham
ceea274e70 Merge pull request #17 from movie-web/device-name-update
Device name update + fixing settings endpoint
2023-11-24 18:56:08 +00:00
William Oldham
6d2dcd04e9 Apply suggestions from code review 2023-11-24 18:55:20 +00:00
mrjvs
8a3c0d6edb add settings nullable + undefined difference 2023-11-24 18:40:54 +01:00
mrjvs
72657e73c8 add update session endpoint 2023-11-24 18:00:06 +01:00
6 changed files with 29 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "1.1.2",
"version": "1.1.5",
"private": true,
"homepage": "https://github.com/movie-web/backend",
"engines": {

View File

@@ -2,7 +2,7 @@ import { loginAuthRouter } from '@/routes/auth/login';
import { manageAuthRouter } from '@/routes/auth/manage';
import { metaRouter } from '@/routes/meta';
import { metricsRouter } from '@/routes/metrics';
import { sessionsRouter } from '@/routes/sessions';
import { sessionsRouter } from '@/routes/sessions/sessions';
import { userBookmarkRouter } from '@/routes/users/bookmark';
import { userDeleteRouter } from '@/routes/users/delete';
import { userEditRouter } from '@/routes/users/edit';

View File

@@ -1,35 +0,0 @@
import { Session } from '@/db/models/Session';
import { StatusError } from '@/services/error';
import { handle } from '@/services/handler';
import { makeRouter } from '@/services/router';
import { z } from 'zod';
export const sessionRouter = makeRouter((app) => {
app.delete(
'/sessions/:sid',
{
schema: {
params: z.object({
sid: z.string(),
}),
},
},
handle(async ({ auth, params, em }) => {
await auth.assert();
const targetedSession = await em.findOne(Session, { id: params.sid });
if (!targetedSession)
return {
id: params.sid,
};
if (targetedSession.user !== auth.user.id)
throw new StatusError('Cannot delete sessions you do not own', 401);
await em.removeAndFlush(targetedSession);
return {
id: params.sid,
};
}),
);
});

View File

@@ -13,7 +13,7 @@ export const sessionsRouter = makeRouter((app) => {
sid: z.string(),
}),
body: z.object({
name: z.string().max(500).min(1).optional(),
deviceName: z.string().max(500).min(1).optional(),
}),
},
},
@@ -25,10 +25,10 @@ export const sessionsRouter = makeRouter((app) => {
if (!targetedSession)
throw new StatusError('Session cannot be found', 404);
if (targetedSession.user !== auth.user.id)
throw new StatusError('Cannot modify sessions you do not own', 401);
if (targetedSession.id !== params.sid)
throw new StatusError('Cannot edit sessions other than your own', 401);
if (body.name) targetedSession.device = body.name;
if (body.deviceName) targetedSession.device = body.deviceName;
await em.persistAndFlush(targetedSession);

View File

@@ -18,6 +18,7 @@ const progressItemSchema = z.object({
episodeId: z.string().optional(),
seasonNumber: z.number().optional(),
episodeNumber: z.number().optional(),
updatedAt: z.string().datetime({ offset: true }).optional(),
});
export const userProgressRouter = makeRouter((app) => {
@@ -100,7 +101,9 @@ export const userProgressRouter = makeRouter((app) => {
if (newItemIndex > -1) {
const newItem = newItems[newItemIndex];
if (existingItem.watched < newItem.watched) {
existingItem.updatedAt = new Date();
existingItem.updatedAt = defaultAndCoerceDateTime(
newItem.updatedAt,
);
existingItem.watched = newItem.watched;
}
itemsUpserted.push(existingItem);
@@ -123,7 +126,7 @@ export const userProgressRouter = makeRouter((app) => {
tmdbId: newItem.tmdbId,
userId: params.uid,
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);
}

View File

@@ -38,9 +38,9 @@ export const userSettingsRouter = makeRouter((app) => {
uid: z.string(),
}),
body: z.object({
applicationLanguage: z.string().optional(),
applicationTheme: z.string().optional(),
defaultSubtitleLanguage: z.string().optional(),
applicationLanguage: z.string().nullable().optional(),
applicationTheme: z.string().nullable().optional(),
defaultSubtitleLanguage: z.string().nullable().optional(),
}),
},
},
@@ -58,12 +58,12 @@ export const userSettingsRouter = makeRouter((app) => {
settings.id = params.uid;
}
if (body.applicationLanguage)
if (body.applicationLanguage !== undefined)
settings.applicationLanguage = body.applicationLanguage;
if (body.applicationTheme)
settings.applicationTheme = body.applicationTheme;
if (body.defaultSubtitleLanguage)
if (body.defaultSubtitleLanguage !== undefined)
settings.defaultSubtitleLanguage = body.defaultSubtitleLanguage;
if (body.applicationTheme !== undefined)
settings.applicationTheme = body.applicationTheme;
await em.persistAndFlush(settings);
return formatUserSettings(settings);