mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 04:22:09 +10:00
refactor: remove momentjs
This commit is contained in:
@ -29,8 +29,8 @@
|
||||
"file-type-mime": "^0.4.3",
|
||||
"jdenticon": "^3.3.0",
|
||||
"lru-cache": "^11.1.0",
|
||||
"luxon": "^3.6.1",
|
||||
"micromark": "^4.0.1",
|
||||
"moment": "^2.30.1",
|
||||
"nuxt": "3.15.4",
|
||||
"nuxt-security": "2.2.0",
|
||||
"prisma": "^6.5.0",
|
||||
@ -49,6 +49,7 @@
|
||||
"@tailwindcss/forms": "^0.5.9",
|
||||
"@tailwindcss/typography": "^0.5.15",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/luxon": "^3.6.2",
|
||||
"@types/node": "^22.13.16",
|
||||
"@types/turndown": "^5.0.5",
|
||||
"autoprefixer": "^10.4.20",
|
||||
|
||||
@ -68,7 +68,9 @@
|
||||
</ul>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-zinc-400">
|
||||
{{ moment(client.lastConnected).fromNow() }}
|
||||
{{
|
||||
DateTime.fromISO(client.lastConnected).diffNow().toHuman()
|
||||
}}
|
||||
</td>
|
||||
<td
|
||||
class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-3"
|
||||
@ -91,7 +93,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { CheckIcon } from "@heroicons/vue/24/outline";
|
||||
import moment from "moment";
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
const clients = await $dropFetch("/api/v1/user/client");
|
||||
|
||||
|
||||
@ -352,7 +352,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ClientOnly } from "#build/components";
|
||||
import {
|
||||
Dialog,
|
||||
DialogPanel,
|
||||
@ -380,8 +379,8 @@ import {
|
||||
XCircleIcon,
|
||||
} from "@heroicons/vue/24/solid";
|
||||
import type { Invitation } from "@prisma/client";
|
||||
import moment from "moment";
|
||||
import type { SerializeObject } from "nitropack";
|
||||
import { DateTime, DurationLike } from "luxon";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
@ -439,13 +438,25 @@ const validEmail = computed(() =>
|
||||
const isAdmin = ref(false);
|
||||
|
||||
// Label to parameters to moment.js .add()
|
||||
const expiry = {
|
||||
"3 days": [3, "days"],
|
||||
"7 days": [7, "days"],
|
||||
"1 month": [1, "month"],
|
||||
"6 months": [6, "month"],
|
||||
"1 year": [1, "year"],
|
||||
Never: [3000, "year"], // Never is relative, right?
|
||||
const expiry: Record<string, DurationLike> = {
|
||||
"3 days": {
|
||||
days: 3,
|
||||
},
|
||||
"7 days": {
|
||||
days: 7,
|
||||
},
|
||||
"1 month": {
|
||||
month: 1,
|
||||
},
|
||||
"6 months": {
|
||||
months: 6,
|
||||
},
|
||||
"1 year": {
|
||||
year: 1,
|
||||
},
|
||||
Never: {
|
||||
year: 3000,
|
||||
}, // Never is relative, right?
|
||||
};
|
||||
const expiryKey = ref<keyof typeof expiry>(Object.keys(expiry)[0] as any); // Cast to any because we just know it's okay
|
||||
|
||||
@ -453,9 +464,7 @@ const loading = ref(false);
|
||||
const error = ref<undefined | string>();
|
||||
|
||||
async function invite() {
|
||||
const expiryDate = moment()
|
||||
.add(...expiry[expiryKey.value])
|
||||
.toJSON();
|
||||
const expiryDate = DateTime.now().plus(expiry[expiryKey.value]).toJSON();
|
||||
|
||||
const newInvitation = await $dropFetch("/api/v1/admin/auth/invitation", {
|
||||
method: "POST",
|
||||
|
||||
@ -54,7 +54,11 @@
|
||||
Released
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-zinc-400">
|
||||
{{ moment(game.mReleased).format("Do MMMM, YYYY") }}
|
||||
{{
|
||||
DateTime.fromJSDate(game.mReleased).toFormat(
|
||||
"Do MMMM, YYYY"
|
||||
)
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -166,7 +170,7 @@ import { ArrowTopRightOnSquareIcon } from "@heroicons/vue/24/outline";
|
||||
import { StarIcon } from "@heroicons/vue/24/solid";
|
||||
import { type Game, type GameVersion } from "@prisma/client";
|
||||
import { micromark } from "micromark";
|
||||
import moment from "moment";
|
||||
import { DateTime } from "luxon";
|
||||
import { PlatformClient } from "~/composables/types";
|
||||
import { ref } from "vue";
|
||||
import AddLibraryButton from "~/components/AddLibraryButton.vue";
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
15
yarn.lock
15
yarn.lock
@ -1743,6 +1743,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.7.tgz#4158d3105276773d5b7695cd4834b1722e4f37a8"
|
||||
integrity sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==
|
||||
|
||||
"@types/luxon@^3.6.2":
|
||||
version "3.6.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.6.2.tgz#be6536931801f437eafcb9c0f6d6781f72308041"
|
||||
integrity sha512-R/BdP7OxEMc44l2Ex5lSXHoIXTB2JLNa3y2QISIbr58U/YcsffyQrYW//hZSdrfxrjRZj3GcUoxMPGdO8gSYuw==
|
||||
|
||||
"@types/ms@*":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-2.1.0.tgz#052aa67a48eccc4309d7f0191b7e41434b90bb78"
|
||||
@ -4508,6 +4513,11 @@ lru-cache@^5.1.1:
|
||||
dependencies:
|
||||
yallist "^3.0.2"
|
||||
|
||||
luxon@^3.6.1:
|
||||
version "3.6.1"
|
||||
resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.6.1.tgz#d283ffc4c0076cb0db7885ec6da1c49ba97e47b0"
|
||||
integrity sha512-tJLxrKJhO2ukZ5z0gyjY1zPh3Rh88Ej9P7jNrZiHMUXHae1yvI2imgOZtL1TO8TW6biMMKfTtAOoEJANgtWBMQ==
|
||||
|
||||
magic-regexp@^0.8.0:
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/magic-regexp/-/magic-regexp-0.8.0.tgz#c67de16456522a83672c22aa408b774facfd882e"
|
||||
@ -4912,11 +4922,6 @@ mocked-exports@^0.1.0:
|
||||
resolved "https://registry.yarnpkg.com/mocked-exports/-/mocked-exports-0.1.1.tgz#6916efea9a9dd0f4abd6a0a72526f56a76c966ea"
|
||||
integrity sha512-aF7yRQr/Q0O2/4pIXm6PZ5G+jAd7QS4Yu8m+WEeEHGnbo+7mE36CbLSDQiXYV8bVL3NfmdeqPJct0tUlnjVSnA==
|
||||
|
||||
moment@^2.30.1:
|
||||
version "2.30.1"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
|
||||
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==
|
||||
|
||||
mrmime@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/mrmime/-/mrmime-2.0.1.tgz#bc3e87f7987853a54c9850eeb1f1078cd44adddc"
|
||||
|
||||
Reference in New Issue
Block a user