mirror of
https://github.com/BillyOutlast/drop.git
synced 2026-02-04 08:41:17 +01:00
refactor: remove momentjs
This commit is contained in:
@@ -3,7 +3,6 @@ import { EventHandlerRequest, H3Event } from "h3";
|
||||
import droplet from "@drop-oss/droplet";
|
||||
import prisma from "../db/database";
|
||||
import { useCertificateAuthority } from "~/server/plugins/ca";
|
||||
import moment from "moment";
|
||||
|
||||
export type EventHandlerFunction<T> = (
|
||||
h3: H3Event<EventHandlerRequest>,
|
||||
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
DeveloperMetadata,
|
||||
} from "./types";
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import moment from "moment";
|
||||
import TurndownService from "turndown";
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
interface GiantBombResponseType<T> {
|
||||
error: "OK" | string;
|
||||
@@ -140,7 +140,7 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
const mapped = results.data.results.map((result) => {
|
||||
const date =
|
||||
(result.original_release_date
|
||||
? moment(result.original_release_date).year()
|
||||
? DateTime.fromISO(result.original_release_date).year
|
||||
: result.expected_release_year) ?? 0;
|
||||
|
||||
const metadata: GameMetadataSearchResult = {
|
||||
@@ -191,12 +191,12 @@ export class GiantBombProvider implements MetadataProvider {
|
||||
const images = [banner, ...imageURLs.map(createObject)];
|
||||
|
||||
const releaseDate = gameData.original_release_date
|
||||
? moment(gameData.original_release_date).toDate()
|
||||
: moment(
|
||||
`${gameData.expected_release_day ?? 1}/${
|
||||
? DateTime.fromISO(gameData.original_release_date).toJSDate()
|
||||
: DateTime.fromISO(
|
||||
`${gameData.expected_release_year ?? new Date().getFullYear()}-${
|
||||
gameData.expected_release_month ?? 1
|
||||
}/${gameData.expected_release_year ?? new Date().getFullYear()}`
|
||||
).toDate();
|
||||
}-${gameData.expected_release_day ?? 1}`
|
||||
).toJSDate();
|
||||
|
||||
const metadata: GameMetadata = {
|
||||
id: gameData.guid,
|
||||
|
||||
@@ -10,8 +10,7 @@ import {
|
||||
DeveloperMetadata,
|
||||
} from "./types";
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import { inspect } from "util";
|
||||
import moment from "moment";
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
type IGDBID = number;
|
||||
|
||||
@@ -132,7 +131,7 @@ export class IGDBProvider implements MetadataProvider {
|
||||
private clientId: string;
|
||||
private clientSecret: string;
|
||||
private accessToken: string;
|
||||
private accessTokenExpiry: moment.Moment;
|
||||
private accessTokenExpiry: DateTime;
|
||||
|
||||
constructor() {
|
||||
const client_id = process.env.IGDB_CLIENT_ID;
|
||||
@@ -149,7 +148,9 @@ export class IGDBProvider implements MetadataProvider {
|
||||
this.clientSecret = client_secret;
|
||||
|
||||
this.accessToken = "";
|
||||
this.accessTokenExpiry = moment(new Date(0));
|
||||
this.accessTokenExpiry = DateTime.now().minus({
|
||||
year: 1,
|
||||
});
|
||||
}
|
||||
|
||||
private async authWithTwitch() {
|
||||
@@ -167,15 +168,18 @@ export class IGDBProvider implements MetadataProvider {
|
||||
});
|
||||
|
||||
this.accessToken = response.data.access_token;
|
||||
this.accessTokenExpiry = moment().add(response.data.expires_in, "seconds");
|
||||
this.accessTokenExpiry = DateTime.now().plus({
|
||||
seconds: response.data.expires_in,
|
||||
});
|
||||
}
|
||||
|
||||
private async refreshCredentials() {
|
||||
const futureTime = moment().add(1, "day");
|
||||
const futureTime = DateTime.now().plus({
|
||||
day: 1,
|
||||
});
|
||||
|
||||
// if the token expires in less than a day
|
||||
if (this.accessTokenExpiry.isBefore(futureTime))
|
||||
await this.authWithTwitch();
|
||||
if (this.accessTokenExpiry < futureTime) await this.authWithTwitch();
|
||||
}
|
||||
|
||||
private async request<T extends Object>(
|
||||
@@ -279,7 +283,7 @@ export class IGDBProvider implements MetadataProvider {
|
||||
name: response[i].name,
|
||||
icon: await this.getCoverURL(response[i].cover),
|
||||
description: response[i].summary,
|
||||
year: moment.unix(response[i].first_release_date).year(),
|
||||
year: DateTime.fromSeconds(response[i].first_release_date).year,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -340,7 +344,9 @@ export class IGDBProvider implements MetadataProvider {
|
||||
name: response[i].name,
|
||||
shortDescription: this.trimMessage(response[i].summary, 280),
|
||||
description: response[i].summary,
|
||||
released: moment.unix(response[i].first_release_date).toDate(),
|
||||
released: DateTime.fromSeconds(
|
||||
response[i].first_release_date
|
||||
).toJSDate(),
|
||||
|
||||
reviewCount: response[i]?.total_rating_count ?? 0,
|
||||
reviewRating: (response[i]?.total_rating ?? 0) / 100,
|
||||
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
DeveloperMetadata,
|
||||
} from "./types";
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import moment from "moment";
|
||||
import * as jdenticon from "jdenticon";
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
interface PCGamingWikiPage {
|
||||
PageID: string;
|
||||
@@ -116,7 +116,8 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
||||
description: "", // TODO: need to render the `Introduction` template somehow (or we could just hardcode it)
|
||||
year:
|
||||
game.Released !== null && game.Released.length > 0
|
||||
? moment(game.Released).year()
|
||||
? // sometimes will provide multiple dates
|
||||
DateTime.fromISO(game.Released.split(";")[0]).year
|
||||
: 0,
|
||||
};
|
||||
return metadata;
|
||||
@@ -193,7 +194,7 @@ export class PCGamingWikiProvider implements MetadataProvider {
|
||||
shortDescription: "", // TODO: (again) need to render the `Introduction` template somehow (or we could just hardcode it)
|
||||
description: "",
|
||||
released: game.Released
|
||||
? moment(game.Released.split(";").at(0)).toDate()
|
||||
? DateTime.fromISO(game.Released.split(";")[0]).toJSDate()
|
||||
: new Date(),
|
||||
|
||||
reviewCount: 0,
|
||||
|
||||
@@ -2,10 +2,10 @@ import { H3Event } from "h3";
|
||||
import createMemorySessionProvider from "./memory";
|
||||
import { Session, SessionProvider } from "./types";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import moment from "moment";
|
||||
import { parse as parseCookies } from "cookie-es";
|
||||
import { MinimumRequestObject } from "~/server/h3";
|
||||
import createDBSessionHandler from "./db";
|
||||
import { DateTime, DurationLike } from "luxon";
|
||||
|
||||
/*
|
||||
This implementation may need work.
|
||||
@@ -14,8 +14,12 @@ It exposes an API that should stay static, but there are plenty of opportunities
|
||||
*/
|
||||
|
||||
const dropTokenCookieName = "drop-token";
|
||||
const normalSessionLength = [31, "days"];
|
||||
const extendedSessionLength = [1, "year"];
|
||||
const normalSessionLength: DurationLike = {
|
||||
days: 31,
|
||||
};
|
||||
const extendedSessionLength: DurationLike = {
|
||||
year: 1,
|
||||
};
|
||||
|
||||
export class SessionHandler {
|
||||
private sessionProvider: SessionProvider;
|
||||
@@ -96,9 +100,9 @@ export class SessionHandler {
|
||||
}
|
||||
|
||||
private createExipreAt(rememberMe: boolean) {
|
||||
return moment()
|
||||
.add(...(rememberMe ? extendedSessionLength : normalSessionLength))
|
||||
.toDate();
|
||||
return DateTime.now()
|
||||
.plus(rememberMe ? extendedSessionLength : normalSessionLength)
|
||||
.toJSDate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user