mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-23 07:32:28 -04:00
Use real dates instead of iso string everywhere
This commit is contained in:
@@ -18,7 +18,6 @@ import {
|
||||
jsonbAgg,
|
||||
jsonbBuildObject,
|
||||
jsonbObjectAgg,
|
||||
normalizeDate,
|
||||
sqlarr,
|
||||
} from "~/db/utils";
|
||||
import {
|
||||
@@ -173,9 +172,6 @@ const entryRelations = {
|
||||
.select({
|
||||
json: jsonbBuildObject<Show>({
|
||||
...getColumns(shows),
|
||||
createdAt: normalizeDate(shows.createdAt),
|
||||
updatedAt: normalizeDate(shows.updatedAt),
|
||||
|
||||
airDate: shows.startAir,
|
||||
isAvailable: sql<boolean>`${shows.availableCount} != 0`,
|
||||
...getColumns(transQ),
|
||||
@@ -232,7 +228,7 @@ export const mapProgress = ({ aliased }: { aliased: boolean }) => {
|
||||
const ret = {
|
||||
time: coalesce(time, sql<number>`0`),
|
||||
percent: coalesce(percent, sql<number>`0`),
|
||||
playedDate: normalizeDate(playedDate),
|
||||
playedDate: sql<Date>`${playedDate}`,
|
||||
videoId: sql<string>`${videoId}`,
|
||||
};
|
||||
if (!aliased) return ret;
|
||||
|
||||
@@ -177,7 +177,7 @@ async function updateWatchlist(
|
||||
histArr: {
|
||||
entryPk: number;
|
||||
percent: number;
|
||||
playedDate: string;
|
||||
playedDate: Date;
|
||||
}[],
|
||||
) {
|
||||
if (histArr.length === 0) return;
|
||||
|
||||
@@ -407,6 +407,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] })
|
||||
}),
|
||||
response: {
|
||||
200: t.Intersect([SerieWatchStatus, DbMetadata]),
|
||||
401: KError,
|
||||
404: KError,
|
||||
},
|
||||
permissions: ["core.read"],
|
||||
|
||||
@@ -18,7 +18,7 @@ export const insertCollection = record(
|
||||
| ({ kind: "movie" } & SeedMovie)
|
||||
| ({ kind: "serie" } & SeedSerie)
|
||||
) & {
|
||||
nextRefresh: string;
|
||||
nextRefresh: Date;
|
||||
},
|
||||
) => {
|
||||
if (!collection) return null;
|
||||
|
||||
@@ -8,5 +8,5 @@ export const guessNextRefresh = (airDate: Date | string) => {
|
||||
if (days <= 4) ret.setDate(ret.getDate() + 4);
|
||||
else if (days <= 21) ret.setDate(ret.getDate() + 14);
|
||||
else ret.setMonth(ret.getMonth() + 2);
|
||||
return ret.toISOString().substring(0, 10);
|
||||
return ret;
|
||||
};
|
||||
|
||||
@@ -23,8 +23,8 @@ import {
|
||||
processLanguages,
|
||||
} from "~/models/utils";
|
||||
import { desc } from "~/models/utils/descriptions";
|
||||
import { getShows, showFilters, showSort } from "./logic";
|
||||
import { toQueryStr } from "~/utils";
|
||||
import { getShows, showFilters, showSort } from "./logic";
|
||||
|
||||
export const collections = new Elysia({
|
||||
prefix: "/collections",
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
jsonbAgg,
|
||||
jsonbBuildObject,
|
||||
jsonbObjectAgg,
|
||||
normalizeDate,
|
||||
sqlarr,
|
||||
} from "~/db/utils";
|
||||
import type { Entry } from "~/models/entry";
|
||||
@@ -47,10 +46,6 @@ export const watchStatusQ = db
|
||||
.select({
|
||||
...getColumns(watchlist),
|
||||
percent: sql<number>`${watchlist.seenCount}`.as("percent"),
|
||||
// needed when watchStatusQ is embedded in a jsonbBuildObject
|
||||
startedAt: normalizeDate(watchlist.startedAt),
|
||||
lastPlayedAt: normalizeDate(watchlist.lastPlayedAt),
|
||||
completedAt: normalizeDate(watchlist.completedAt),
|
||||
})
|
||||
.from(watchlist)
|
||||
.innerJoin(profiles, eq(watchlist.profilePk, profiles.pk))
|
||||
@@ -130,7 +125,6 @@ export const showRelations = {
|
||||
.as("translations");
|
||||
},
|
||||
studios: ({ languages }: { languages: string[] }) => {
|
||||
const { pk: _, createdAt, updatedAt, ...studioCol } = getColumns(studios);
|
||||
const studioTransQ = db
|
||||
.selectDistinctOn([studioTranslations.pk])
|
||||
.from(studioTranslations)
|
||||
@@ -146,10 +140,8 @@ export const showRelations = {
|
||||
json: coalesce(
|
||||
jsonbAgg(
|
||||
jsonbBuildObject<Studio>({
|
||||
...getColumns(studios),
|
||||
...studioTrans,
|
||||
...studioCol,
|
||||
createdAt: normalizeDate(createdAt),
|
||||
updatedAt: normalizeDate(updatedAt),
|
||||
}),
|
||||
),
|
||||
sql`'[]'::jsonb`,
|
||||
@@ -204,8 +196,6 @@ export const showRelations = {
|
||||
number: entries.episodeNumber,
|
||||
videos: entryVideosQ.videos,
|
||||
progress: mapProgress({ aliased: false }),
|
||||
createdAt: normalizeDate(entries.createdAt),
|
||||
updatedAt: normalizeDate(entries.updatedAt),
|
||||
}).as("firstEntry"),
|
||||
})
|
||||
.from(entries)
|
||||
@@ -228,8 +218,6 @@ export const showRelations = {
|
||||
number: entries.episodeNumber,
|
||||
videos: entryVideosQ.videos,
|
||||
progress: mapProgress({ aliased: false }),
|
||||
createdAt: normalizeDate(entries.createdAt),
|
||||
updatedAt: normalizeDate(entries.updatedAt),
|
||||
}).as("nextEntry"),
|
||||
})
|
||||
.from(entries)
|
||||
|
||||
@@ -16,8 +16,8 @@ import {
|
||||
processLanguages,
|
||||
} from "~/models/utils";
|
||||
import { desc } from "~/models/utils/descriptions";
|
||||
import { getShows, showFilters, showSort } from "./logic";
|
||||
import { toQueryStr } from "~/utils";
|
||||
import { getShows, showFilters, showSort } from "./logic";
|
||||
|
||||
export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
||||
.model({
|
||||
|
||||
@@ -16,8 +16,8 @@ import {
|
||||
processLanguages,
|
||||
} from "~/models/utils";
|
||||
import { desc } from "~/models/utils/descriptions";
|
||||
import { getShows, showFilters, showSort } from "./logic";
|
||||
import { toQueryStr } from "~/utils";
|
||||
import { getShows, showFilters, showSort } from "./logic";
|
||||
|
||||
export const series = new Elysia({ prefix: "/series", tags: ["series"] })
|
||||
.model({
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
jsonbAgg,
|
||||
jsonbBuildObject,
|
||||
jsonbObjectAgg,
|
||||
normalizeDate,
|
||||
sqlarr,
|
||||
unnest,
|
||||
unnestValues,
|
||||
@@ -251,7 +250,7 @@ const videoRelations = {
|
||||
json: jsonbBuildObject<Progress>({
|
||||
percent: history.percent,
|
||||
time: history.time,
|
||||
playedDate: normalizeDate(history.playedDate),
|
||||
playedDate: history.playedDate,
|
||||
videoId: videos.id,
|
||||
}),
|
||||
})
|
||||
@@ -287,9 +286,6 @@ const videoRelations = {
|
||||
number: entries.episodeNumber,
|
||||
videos: entryVideosQ.videos,
|
||||
progress: mapProgress({ aliased: false }),
|
||||
createdAt: normalizeDate(entries.createdAt),
|
||||
updatedAt: normalizeDate(entries.updatedAt),
|
||||
availableSince: normalizeDate(entries.availableSince),
|
||||
}),
|
||||
),
|
||||
sql`'[]'::jsonb`,
|
||||
@@ -319,16 +315,11 @@ const videoRelations = {
|
||||
)
|
||||
.as("t");
|
||||
|
||||
const { startedAt, lastPlayedAt, completedAt, ...watchlistCols } =
|
||||
getColumns(watchlist);
|
||||
const watchStatusQ = db
|
||||
.select({
|
||||
watchStatus: jsonbBuildObject<MovieWatchStatus & SerieWatchStatus>({
|
||||
...watchlistCols,
|
||||
...getColumns(watchlist),
|
||||
percent: watchlist.seenCount,
|
||||
startedAt: normalizeDate(startedAt),
|
||||
lastPlayedAt: normalizeDate(lastPlayedAt),
|
||||
completedAt: normalizeDate(completedAt),
|
||||
}).as("watchStatus"),
|
||||
})
|
||||
.from(watchlist)
|
||||
@@ -350,8 +341,6 @@ const videoRelations = {
|
||||
airDate: shows.startAir,
|
||||
kind: sql<any>`${shows.kind}`,
|
||||
isAvailable: sql<boolean>`${shows.availableCount} != 0`,
|
||||
createdAt: normalizeDate(shows.createdAt),
|
||||
updatedAt: normalizeDate(shows.updatedAt),
|
||||
|
||||
...(preferOriginal && {
|
||||
poster: sql<Image>`coalesce(nullif(${shows.original}->'poster', 'null'::jsonb), ${transQ.poster})`,
|
||||
@@ -405,8 +394,6 @@ function getNextVideoEntry({
|
||||
number: entries.episodeNumber,
|
||||
videos: entryVideosQ.videos,
|
||||
progress: mapProgress({ aliased: false }),
|
||||
createdAt: normalizeDate(entries.createdAt),
|
||||
updatedAt: normalizeDate(entries.updatedAt),
|
||||
},
|
||||
}).as("json"),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user