fix: eslint errors, switch to using maps

This commit is contained in:
Huskydog9988
2025-04-15 20:04:45 -04:00
parent 3961323cca
commit 0eb29650ca
21 changed files with 158 additions and 159 deletions
@@ -91,6 +91,4 @@ const navigation: NavigationItem[] = [
prefix: "", prefix: "",
}, },
].filter((e) => e !== undefined); ].filter((e) => e !== undefined);
const router = useRouter();
</script> </script>
+1
View File
@@ -31,6 +31,7 @@ export const fetchNews = async (options?: {
const news = useNews(); const news = useNews();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore forget why this ignor exists // @ts-ignore forget why this ignor exists
const newValue = await $dropFetch(`/api/v1/news?${query.toString()}`); const newValue = await $dropFetch(`/api/v1/news?${query.toString()}`);
+5 -3
View File
@@ -17,6 +17,8 @@ interface DropFetch<
request: R, request: R,
opts?: O, opts?: O,
): Promise< ): Promise<
// sometimes there is an error, other times there isn't
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
TypedInternalResponse< TypedInternalResponse<
R, R,
@@ -28,7 +30,7 @@ interface DropFetch<
export const $dropFetch: DropFetch = async (request, opts) => { export const $dropFetch: DropFetch = async (request, opts) => {
if (!getCurrentInstance()?.proxy) { if (!getCurrentInstance()?.proxy) {
return (await $fetch(request, opts)) as any; return await $fetch(request, opts);
} }
const id = request.toString(); const id = request.toString();
@@ -45,7 +47,7 @@ export const $dropFetch: DropFetch = async (request, opts) => {
const data = await $fetch(request, { const data = await $fetch(request, {
...opts, ...opts,
headers: { ...opts?.headers, ...headers }, headers: { ...opts?.headers, ...headers },
} as any); });
if (import.meta.server) state.value = data; if (import.meta.server) state.value = data;
return data as any; return data;
}; };
@@ -7,33 +7,35 @@ import { randomUUID } from "node:crypto";
import objectHandler from "."; import objectHandler from ".";
export type TransactionDataType = string | Readable | Buffer; export type TransactionDataType = string | Readable | Buffer;
type TransactionTable = { [key: string]: TransactionDataType }; // ID to data type TransactionTable = Map<string, TransactionDataType>; // ID to data
type GlobalTransactionRecord = { [key: string]: TransactionTable }; // Transaction ID to table type GlobalTransactionRecord = Map<string, TransactionTable>; // Transaction ID to table
export type Register = (url: TransactionDataType) => string; export type Register = (url: TransactionDataType) => string;
export type Pull = () => Promise<void>; export type Pull = () => Promise<void>;
export type Dump = () => void; export type Dump = () => void;
export class ObjectTransactionalHandler { export class ObjectTransactionalHandler {
private record: GlobalTransactionRecord = {}; private record: GlobalTransactionRecord = new Map();
new( new(
metadata: { [key: string]: string }, metadata: { [key: string]: string },
permissions: Array<string> permissions: Array<string>,
): [Register, Pull, Dump] { ): [Register, Pull, Dump] {
const transactionId = randomUUID(); const transactionId = randomUUID();
this.record[transactionId] ??= {}; this.record.set(transactionId, new Map());
const register = (data: TransactionDataType) => { const register = (data: TransactionDataType) => {
const objectId = randomUUID(); const objectId = randomUUID();
this.record[transactionId][objectId] = data; this.record.get(transactionId)?.set(objectId, data);
return objectId; return objectId;
}; };
const pull = async () => { const pull = async () => {
for (const [id, data] of Object.entries(this.record[transactionId])) { const transaction = this.record.get(transactionId);
if (!transaction) return;
for (const [id, data] of transaction) {
await objectHandler.createFromSource( await objectHandler.createFromSource(
id, id,
() => { () => {
@@ -43,13 +45,13 @@ export class ObjectTransactionalHandler {
return (async () => data)(); return (async () => data)();
}, },
metadata, metadata,
permissions permissions,
); );
} }
}; };
const dump = () => { const dump = () => {
delete this.record[transactionId]; this.record.delete(transactionId);
}; };
return [register, pull, dump]; return [register, pull, dump];
+6 -7
View File
@@ -1,4 +1,4 @@
import Stream, { Readable } from "stream"; import Stream from "stream";
import prisma from "../db/database"; import prisma from "../db/database";
import { applicationSettings } from "../config/application-configuration"; import { applicationSettings } from "../config/application-configuration";
import objectHandler from "../objects"; import objectHandler from "../objects";
@@ -10,7 +10,7 @@ class SaveManager {
gameId: string, gameId: string,
userId: string, userId: string,
index: number, index: number,
objectId: string objectId: string,
) { ) {
await objectHandler.deleteWithPermission(objectId, userId); await objectHandler.deleteWithPermission(objectId, userId);
} }
@@ -20,7 +20,7 @@ class SaveManager {
userId: string, userId: string,
index: number, index: number,
stream: IncomingMessage, stream: IncomingMessage,
clientId: string | undefined = undefined clientId: string | undefined = undefined,
) { ) {
const save = await prisma.saveSlot.findUnique({ const save = await prisma.saveSlot.findUnique({
where: { where: {
@@ -38,7 +38,7 @@ class SaveManager {
const newSaveStream = await objectHandler.createWithStream( const newSaveStream = await objectHandler.createWithStream(
newSaveObjectId, newSaveObjectId,
{ saveSlot: JSON.stringify({ userId, gameId, index }) }, { saveSlot: JSON.stringify({ userId, gameId, index }) },
[] [],
); );
if (!newSaveStream) if (!newSaveStream)
throw createError({ throw createError({
@@ -51,10 +51,9 @@ class SaveManager {
stream, stream,
createHash("sha256").setEncoding("hex"), createHash("sha256").setEncoding("hex"),
async function (source) { async function (source) {
// Not sure how to get this to be typed // @ts-expect-error Not sure how to get this to be typed
// @ts-expect-error
hash = (await source.toArray())[0]; hash = (await source.toArray())[0];
} },
); );
const uploadStream = Stream.promises.pipeline(stream, newSaveStream); const uploadStream = Stream.promises.pipeline(stream, newSaveStream);
@@ -1,6 +1,5 @@
import bcrypt from "bcryptjs"; import bcrypt from "bcryptjs";
import * as argon2 from "argon2"; import * as argon2 from "argon2";
import { type } from "arktype";
export async function checkHashBcrypt(password: string, hash: string) { export async function checkHashBcrypt(password: string, hash: string) {
return await bcrypt.compare(password, hash); return await bcrypt.compare(password, hash);
-1
View File
@@ -1,7 +1,6 @@
import { LRUCache } from "lru-cache"; import { LRUCache } from "lru-cache";
import prisma from "../db/database"; import prisma from "../db/database";
import type { Session, SessionProvider } from "./types"; import type { Session, SessionProvider } from "./types";
import { Prisma } from "@prisma/client";
export default function createDBSessionHandler(): SessionProvider { export default function createDBSessionHandler(): SessionProvider {
const cache = new LRUCache<string, Session>({ const cache = new LRUCache<string, Session>({
+1 -2
View File
@@ -1,5 +1,4 @@
import type { H3Event } from "h3"; import type { H3Event } from "h3";
import createMemorySessionProvider from "./memory";
import type { Session, SessionProvider } from "./types"; import type { Session, SessionProvider } from "./types";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import { parse as parseCookies } from "cookie-es"; import { parse as parseCookies } from "cookie-es";
@@ -90,7 +89,7 @@ export class SessionHandler {
* @returns session token * @returns session token
*/ */
private getSessionToken( private getSessionToken(
request: MinimumRequestObject | undefined request: MinimumRequestObject | undefined,
): string | undefined { ): string | undefined {
if (!request) throw new Error("Native web request not available"); if (!request) throw new Error("Native web request not available");
const cookieHeader = request.headers.get("Cookie"); const cookieHeader = request.headers.get("Cookie");
+6 -6
View File
@@ -1,29 +1,29 @@
import type { Session, SessionProvider } from "./types"; import type { Session, SessionProvider } from "./types";
export default function createMemorySessionHandler() { export default function createMemorySessionHandler() {
const sessions: { [key: string]: Session } = {}; const sessions = new Map<string, Session>();
const memoryProvider: SessionProvider = { const memoryProvider: SessionProvider = {
async setSession(token, data) { async setSession(token, data) {
sessions[token] = data; sessions.set(token, data);
return true; return true;
}, },
async getSession<T extends Session>(token: string): Promise<T | undefined> { async getSession<T extends Session>(token: string): Promise<T | undefined> {
const session = sessions[token]; const session = sessions.get(token);
return session ? (session as T) : undefined; // Ensure undefined is returned if session is not found return session ? (session as T) : undefined; // Ensure undefined is returned if session is not found
}, },
async updateSession(token, data) { async updateSession(token, data) {
return this.setSession(token, data); return this.setSession(token, data);
}, },
async removeSession(token) { async removeSession(token) {
delete sessions[token]; sessions.delete(token);
return true; return true;
}, },
async cleanupSessions() { async cleanupSessions() {
const now = new Date(); const now = new Date();
for (const token in sessions) { for (const [token, session] of sessions) {
// if expires at time is before now, the session is expired // if expires at time is before now, the session is expired
if (sessions[token].expiresAt < now) await this.removeSession(token); if (session.expiresAt < now) await this.removeSession(token);
} }
}, },
}; };
+1 -2
View File
@@ -1,9 +1,8 @@
import { H3Event } from "h3";
export type Session = { export type Session = {
userId: string; userId: string;
expiresAt: Date; expiresAt: Date;
data: { data: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any; [key: string]: any;
}; };
}; };
+39 -37
View File
@@ -13,18 +13,18 @@ type TaskRegistryEntry = {
progress: number; progress: number;
log: string[]; log: string[];
error: { title: string; description: string } | undefined; error: { title: string; description: string } | undefined;
clients: { [key: string]: boolean }; clients: Map<string, boolean>;
name: string; name: string;
acls: string[]; acls: string[];
}; };
class TaskHandler { class TaskHandler {
private taskRegistry: { [key: string]: TaskRegistryEntry } = {}; // TODO: make these maps, using objects like this has performance impacts
private clientRegistry: { [key: string]: PeerImpl } = {}; // https://typescript-eslint.io/rules/no-dynamic-delete/
private taskRegistry = new Map<string, TaskRegistryEntry>();
private clientRegistry = new Map<string, PeerImpl>();
startTasks: (() => void)[] = []; startTasks: (() => void)[] = [];
constructor() {}
create(task: Task) { create(task: Task) {
let updateCollectTimeout: NodeJS.Timeout | undefined; let updateCollectTimeout: NodeJS.Timeout | undefined;
let updateCollectResolves: Array<(value: unknown) => void> = []; let updateCollectResolves: Array<(value: unknown) => void> = [];
@@ -37,7 +37,7 @@ class TaskHandler {
return; return;
} }
updateCollectTimeout = setTimeout(() => { updateCollectTimeout = setTimeout(() => {
const taskEntry = this.taskRegistry[task.id]; const taskEntry = this.taskRegistry.get(task.id);
if (!taskEntry) return; if (!taskEntry) return;
const taskMessage: TaskMessage = { const taskMessage: TaskMessage = {
@@ -51,9 +51,10 @@ class TaskHandler {
}; };
logOffset = taskEntry.log.length; logOffset = taskEntry.log.length;
for (const client of Object.keys(taskEntry.clients)) { for (const clientId of Object.keys(taskEntry.clients)) {
if (!this.clientRegistry[client]) continue; const client = this.clientRegistry.get(clientId);
this.clientRegistry[client].send(JSON.stringify(taskMessage)); if (!client) continue;
client.send(JSON.stringify(taskMessage));
} }
updateCollectTimeout = undefined; updateCollectTimeout = undefined;
@@ -66,65 +67,65 @@ class TaskHandler {
}); });
const progress = (progress: number) => { const progress = (progress: number) => {
const taskEntry = this.taskRegistry[task.id]; const taskEntry = this.taskRegistry.get(task.id);
if (!taskEntry) return; if (!taskEntry) return;
this.taskRegistry[task.id].progress = progress; taskEntry.progress = progress;
updateAllClients(); updateAllClients();
}; };
const log = (entry: string) => { const log = (entry: string) => {
const taskEntry = this.taskRegistry[task.id]; const taskEntry = this.taskRegistry.get(task.id);
if (!taskEntry) return; if (!taskEntry) return;
this.taskRegistry[task.id].log.push(entry); taskEntry.log.push(entry);
updateAllClients(); updateAllClients();
}; };
this.taskRegistry[task.id] = { this.taskRegistry.set(task.id, {
name: task.name, name: task.name,
success: false, success: false,
progress: 0, progress: 0,
error: undefined, error: undefined,
log: [], log: [],
clients: {}, clients: new Map(),
acls: task.acls, acls: task.acls,
}; });
updateAllClients(true); updateAllClients(true);
droplet.callAltThreadFunc(async () => { droplet.callAltThreadFunc(async () => {
const taskEntry = this.taskRegistry[task.id]; const taskEntry = this.taskRegistry.get(task.id);
if (!taskEntry) throw new Error("No task entry"); if (!taskEntry) throw new Error("No task entry");
try { try {
await task.run({ progress, log }); await task.run({ progress, log });
this.taskRegistry[task.id].success = true; taskEntry.success = true;
} catch (error: unknown) { } catch (error: unknown) {
this.taskRegistry[task.id].success = false; taskEntry.success = false;
this.taskRegistry[task.id].error = { taskEntry.error = {
title: "An error occurred", title: "An error occurred",
description: (error as string).toString(), description: (error as string).toString(),
}; };
} }
await updateAllClients(); await updateAllClients();
for (const client of Object.keys(taskEntry.clients)) { for (const clientId of Object.keys(taskEntry.clients)) {
if (!this.clientRegistry[client]) continue; if (!this.clientRegistry.get(clientId)) continue;
this.disconnect(client, task.id); this.disconnect(clientId, task.id);
} }
delete this.taskRegistry[task.id]; this.taskRegistry.delete(task.id);
}); });
} }
async connect( async connect(
id: string, clientId: string,
taskId: string, taskId: string,
peer: PeerImpl, peer: PeerImpl,
request: MinimumRequestObject request: MinimumRequestObject,
) { ) {
const task = this.taskRegistry[taskId]; const task = this.taskRegistry.get(taskId);
if (!task) { if (!task) {
peer.send( peer.send(
`error/${taskId}/Unknown task/Drop couldn't find the task you're looking for.` `error/${taskId}/Unknown task/Drop couldn't find the task you're looking for.`,
); );
return; return;
} }
@@ -133,13 +134,13 @@ class TaskHandler {
if (!allowed) { if (!allowed) {
console.warn("user does not have necessary ACLs"); console.warn("user does not have necessary ACLs");
peer.send( peer.send(
`error/${taskId}/Unknown task/Drop couldn't find the task you're looking for.` `error/${taskId}/Unknown task/Drop couldn't find the task you're looking for.`,
); );
return; return;
} }
this.clientRegistry[id] = peer; this.clientRegistry.set(clientId, peer);
this.taskRegistry[taskId].clients[id] = true; // Uniquely insert client to avoid sending duplicate traffic task.clients.set(clientId, true); // Uniquely insert client to avoid sending duplicate traffic
const catchupMessage: TaskMessage = { const catchupMessage: TaskMessage = {
id: taskId, id: taskId,
@@ -153,24 +154,25 @@ class TaskHandler {
} }
sendDisconnectEvent(id: string, taskId: string) { sendDisconnectEvent(id: string, taskId: string) {
const client = this.clientRegistry[id]; const client = this.clientRegistry.get(id);
if (!client) return; if (!client) return;
client.send(`disconnect/${taskId}`); client.send(`disconnect/${taskId}`);
} }
disconnectAll(id: string) { disconnectAll(id: string) {
for (const taskId of Object.keys(this.taskRegistry)) { for (const taskId of Object.keys(this.taskRegistry)) {
delete this.taskRegistry[taskId].clients[id]; this.taskRegistry.get(taskId)?.clients.delete(id);
this.sendDisconnectEvent(id, taskId); this.sendDisconnectEvent(id, taskId);
} }
delete this.clientRegistry[id]; this.clientRegistry.delete(id);
} }
disconnect(id: string, taskId: string) { disconnect(id: string, taskId: string) {
if (!this.taskRegistry[taskId]) return false; const task = this.taskRegistry.get(taskId);
if (!task) return false;
delete this.taskRegistry[taskId].clients[id]; task.clients.delete(id);
this.sendDisconnectEvent(id, taskId); this.sendDisconnectEvent(id, taskId);
const allClientIds = Object.values(this.taskRegistry) const allClientIds = Object.values(this.taskRegistry)
@@ -178,7 +180,7 @@ class TaskHandler {
.flat(); .flat();
if (!allClientIds.includes(id)) { if (!allClientIds.includes(id)) {
delete this.clientRegistry[id]; this.clientRegistry.delete(id);
} }
return true; return true;
@@ -8,8 +8,6 @@ class UserLibraryManager {
// Caches the user's core library // Caches the user's core library
private userCoreLibraryCache: { [key: string]: string } = {}; private userCoreLibraryCache: { [key: string]: string } = {};
constructor() {}
private async fetchUserLibrary(userId: string) { private async fetchUserLibrary(userId: string) {
if (this.userCoreLibraryCache[userId]) if (this.userCoreLibraryCache[userId])
return this.userCoreLibraryCache[userId]; return this.userCoreLibraryCache[userId];
+67 -63
View File
@@ -1,89 +1,93 @@
import type { FilterConditionally } from "./types"; import type { FilterConditionally } from "./types";
interface PriorityTagged<T> { interface PriorityTagged<T> {
object: T, object: T;
priority: number, // Higher takes priority priority: number; // Higher takes priority
addedIndex: number, // Lower takes priority addedIndex: number; // Lower takes priority
} }
export class PriorityList<T> { export class PriorityList<T> {
private source: Array<PriorityTagged<T>> = []; private source: Array<PriorityTagged<T>> = [];
private cachedSorted: Array<T> | undefined; private cachedSorted: Array<T> | undefined;
push(item: T, priority: number = 0) { push(item: T, priority: number = 0) {
this.source.push({ this.source.push({
object: item, object: item,
priority, priority,
addedIndex: this.source.length, addedIndex: this.source.length,
}); });
this.cachedSorted = undefined; this.cachedSorted = undefined;
}
pop(index: number = 0) {
this.cachedSorted = undefined;
return this.source.splice(index, 1)[0];
}
values() {
if (this.cachedSorted !== undefined) {
return this.cachedSorted;
} }
pop(index: number = 0) { const sorted = this.source
this.cachedSorted = undefined; .sort((a, b) => {
return this.source.splice(index, 1)[0]; if (a.priority == a.priority) {
} return a.addedIndex - b.addedIndex;
values() {
if (this.cachedSorted !== undefined) {
return this.cachedSorted;
} }
const sorted = this.source.sort((a, b) => { return b.priority - a.priority;
if (a.priority == a.priority) { })
return a.addedIndex - b.addedIndex; .map((e) => e.object);
} this.cachedSorted = sorted;
return b.priority - a.priority; return this.cachedSorted;
}).map((e) => e.object); }
this.cachedSorted = sorted;
return this.cachedSorted; find(predicate: (value: T, index: number, obj: T[]) => boolean) {
} return this.source.map((e) => e.object).find(predicate);
}
find(predicate: (value: T, index: number, obj: T[]) => boolean) {
return this.source.map((e) => e.object).find(predicate);
}
} }
type IndexableProperty<T> = keyof FilterConditionally<
type IndexableProperty<T> = keyof FilterConditionally<T, (() => string) | string>; T,
(() => string) | string
>;
export class PriorityListIndexed<T> extends PriorityList<T> { export class PriorityListIndexed<T> extends PriorityList<T> {
private indexName: IndexableProperty<T>; private indexName: IndexableProperty<T>;
private indexMap: { [key: string]: T } = {}; private indexMap = new Map<string, T>();
constructor(indexName: IndexableProperty<T>) { constructor(indexName: IndexableProperty<T>) {
super(); super();
this.indexName = indexName; this.indexName = indexName;
}
private getIndex(object: T): string {
const index = object[this.indexName];
if (typeof index === "function") {
return index();
} }
private getIndex(object: T): string { return index as string;
const index = object[this.indexName]; }
if (typeof index === 'function') { override push(item: T, priority?: number): void {
return index(); const index = this.getIndex(item);
} this.indexMap.set(index, item);
return index as string; super.push(item, priority);
} }
override push(item: T, priority?: number): void { override pop(position?: number): PriorityTagged<T> {
const index = this.getIndex(item); const value = super.pop(position);
this.indexMap[index] = item;
super.push(item, priority); const index = this.getIndex(value.object);
} this.indexMap.delete(index);
override pop(position?: number): PriorityTagged<T> { return value;
const value = super.pop(position); }
const index = this.getIndex(value.object); get(index: string) {
delete this.indexMap[index]; return this.indexMap.get(index);
}
return value;
}
get(index: string) {
return this.indexMap[index];
}
} }
+2
View File
@@ -3,6 +3,8 @@ export type FilterConditionally<Source, Condition> = Pick<
{ [K in keyof Source]: Source[K] extends Condition ? K : never }[keyof Source] { [K in keyof Source]: Source[K] extends Condition ? K : never }[keyof Source]
>; >;
export type KeyOfType<T, V> = keyof { export type KeyOfType<T, V> = keyof {
// TODO: should switch to unknown??
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[P in keyof T as T[P] extends V ? P : never]: any; [P in keyof T as T[P] extends V ? P : never]: any;
}; };
+1 -2
View File
@@ -1,7 +1,6 @@
import { applicationSettings } from "../internal/config/application-configuration";
import prisma from "../internal/db/database"; import prisma from "../internal/db/database";
export default defineNitroPlugin(async (nitro) => { export default defineNitroPlugin(async () => {
// Ensure system user exists // Ensure system user exists
// The system user owns any user-based code // The system user owns any user-based code
// that we want to re-use for the app // that we want to re-use for the app
+1 -1
View File
@@ -1,6 +1,6 @@
import prisma from "../internal/db/database"; import prisma from "../internal/db/database";
export default defineNitroPlugin(async (nitro) => { export default defineNitroPlugin(async () => {
const userCount = await prisma.user.count({ const userCount = await prisma.user.count({
where: { id: { not: "system" } }, where: { id: { not: "system" } },
}); });
+9 -10
View File
@@ -6,20 +6,20 @@ import { IGDBProvider } from "../internal/metadata/igdb";
import { ManualMetadataProvider } from "../internal/metadata/manual"; import { ManualMetadataProvider } from "../internal/metadata/manual";
import { PCGamingWikiProvider } from "../internal/metadata/pcgamingwiki"; import { PCGamingWikiProvider } from "../internal/metadata/pcgamingwiki";
export default defineNitroPlugin(async (nitro) => { export default defineNitroPlugin(async () => {
const metadataProviders = [ const metadataProviders = [
GiantBombProvider, GiantBombProvider,
PCGamingWikiProvider, PCGamingWikiProvider,
IGDBProvider, IGDBProvider,
]; ];
const providers: { [key: string]: MetadataProvider } = {}; const providers = new Map<string, MetadataProvider>();
for (const provider of metadataProviders) { for (const provider of metadataProviders) {
try { try {
const prov = new provider(); const prov = new provider();
const id = prov.id(); const id = prov.id();
providers[id] = prov; providers.set(id, prov);
console.log(`enabled metadata provider: ${prov.name()}`); console.log(`enabled metadata provider: ${prov.name()}`);
} catch (e) { } catch (e) {
@@ -28,23 +28,22 @@ export default defineNitroPlugin(async (nitro) => {
} }
// Add providers based on their position in the application settings // Add providers based on their position in the application settings
const configuredProviderList = await applicationSettings.get( const configuredProviderList =
"metadataProviders" await applicationSettings.get("metadataProviders");
);
const max = configuredProviderList.length; const max = configuredProviderList.length;
for (const [index, providerId] of configuredProviderList.entries()) { for (const [index, providerId] of configuredProviderList.entries()) {
const priority = max * 2 - index; // Offset by the length --- (max - index) + max const priority = max * 2 - index; // Offset by the length --- (max - index) + max
const provider = providers[providerId]; const provider = providers.get(providerId);
if (!provider) { if (!provider) {
console.warn(`failed to add existing metadata provider: ${providerId}`); console.warn(`failed to add existing metadata provider: ${providerId}`);
continue; continue;
} }
metadataHandler.addProvider(provider, priority); metadataHandler.addProvider(provider, priority);
delete providers[providerId]; providers.delete(providerId);
} }
// Add the rest with no position // Add the rest with no position
for (const [providerId, provider] of Object.entries(providers)) { for (const [, provider] of Object.entries(providers)) {
metadataHandler.addProvider(provider); metadataHandler.addProvider(provider);
} }
@@ -53,6 +52,6 @@ export default defineNitroPlugin(async (nitro) => {
// Update the applicatonConfig // Update the applicatonConfig
await applicationSettings.set( await applicationSettings.set(
"metadataProviders", "metadataProviders",
metadataHandler.fetchProviderIdsInOrder() metadataHandler.fetchProviderIdsInOrder(),
); );
}); });
+2 -6
View File
@@ -1,9 +1,5 @@
import { CertificateAuthority } from "../internal/clients/ca"; import { CertificateAuthority } from "../internal/clients/ca";
import fs from "fs"; import { dbCertificateStore } from "../internal/clients/ca-store";
import {
dbCertificateStore,
fsCertificateStore,
} from "../internal/clients/ca-store";
let ca: CertificateAuthority | undefined; let ca: CertificateAuthority | undefined;
@@ -12,7 +8,7 @@ export const useCertificateAuthority = () => {
return ca; return ca;
}; };
export default defineNitroPlugin(async (nitro) => { export default defineNitroPlugin(async () => {
// const basePath = process.env.CLIENT_CERTIFICATES ?? "./certs"; // const basePath = process.env.CLIENT_CERTIFICATES ?? "./certs";
// fs.mkdirSync(basePath, { recursive: true }); // fs.mkdirSync(basePath, { recursive: true });
// const store = fsCertificateStore(basePath); // const store = fsCertificateStore(basePath);
+3 -2
View File
@@ -13,13 +13,14 @@ export default defineNitroPlugin((nitro) => {
switch (error.statusCode) { switch (error.statusCode) {
case 401: case 401:
case 403: case 403: {
const user = await sessionHandler.getSession(event); const user = await sessionHandler.getSession(event);
if (user) break; if (user) break;
return sendRedirect( return sendRedirect(
event, event,
`/auth/signin?redirect=${encodeURIComponent(event.path)}` `/auth/signin?redirect=${encodeURIComponent(event.path)}`,
); );
}
} }
}); });
}); });
+1 -1
View File
@@ -4,7 +4,7 @@ export default defineTask({
meta: { meta: {
name: "cleanup:invitations", name: "cleanup:invitations",
}, },
async run({}) { async run() {
const now = new Date(); const now = new Date();
await prisma.invitation.deleteMany({ await prisma.invitation.deleteMany({
+1 -1
View File
@@ -4,7 +4,7 @@ export default defineTask({
meta: { meta: {
name: "cleanup:invitations", name: "cleanup:invitations",
}, },
async run({}) { async run() {
await sessionHandler.cleanupSessions(); await sessionHandler.cleanupSessions();
return { result: true }; return { result: true };