💄 Prettier codebase

This commit is contained in:
ajnart
2023-10-25 15:29:45 +02:00
parent 01ab01d159
commit 5ab0e5207b
99 changed files with 375 additions and 358 deletions

View File

@@ -10,54 +10,60 @@ import { AppType } from '~/types/app';
import { createTRPCRouter, publicProcedure } from '../trpc';
export const appRouter = createTRPCRouter({
ping: publicProcedure.input(z.object({
id: z.string(),
configName: z.string()
})).query(async ({ input }) => {
const agent = new https.Agent({ rejectUnauthorized: false });
const config = getConfig(input.configName);
const app = config.apps.find((app) => app.id === input.id);
ping: publicProcedure
.input(
z.object({
id: z.string(),
configName: z.string(),
})
)
.query(async ({ input }) => {
const agent = new https.Agent({ rejectUnauthorized: false });
const config = getConfig(input.configName);
const app = config.apps.find((app) => app.id === input.id);
if (!app?.url) {
Consola.error(`App ${input} not found`);
throw new TRPCError({
code: 'NOT_FOUND',
cause: input,
message: `App ${input.id} was not found`,
});
}
const res = await axios
.get(app.url, { httpsAgent: agent, timeout: 10000 })
.then((response) => ({
status: response.status,
statusText: response.statusText,
state: isStatusOk(app as AppType, response.status) ? 'online' : 'offline'
}))
.catch((error: AxiosError) => {
if (error.response) {
return {
state: isStatusOk(app as AppType, error.response.status) ? 'online' : 'offline',
status: error.response.status,
statusText: error.response.statusText,
};
}
if (error.code === 'ECONNABORTED') {
Consola.error(`Ping timed out for app with id '${input.id}' in config '${input.configName}' -> url: ${app.url})`);
throw new TRPCError({
code: 'TIMEOUT',
cause: input,
message: `Ping timed out`,
});
}
Consola.error(`Unexpected response: ${error.message}`);
if (!app?.url) {
Consola.error(`App ${input} not found`);
throw new TRPCError({
code: 'UNPROCESSABLE_CONTENT',
code: 'NOT_FOUND',
cause: input,
message: `Unexpected response: ${error.message}`,
message: `App ${input.id} was not found`,
});
});
return res;
}),
}
const res = await axios
.get(app.url, { httpsAgent: agent, timeout: 10000 })
.then((response) => ({
status: response.status,
statusText: response.statusText,
state: isStatusOk(app as AppType, response.status) ? 'online' : 'offline',
}))
.catch((error: AxiosError) => {
if (error.response) {
return {
state: isStatusOk(app as AppType, error.response.status) ? 'online' : 'offline',
status: error.response.status,
statusText: error.response.statusText,
};
}
if (error.code === 'ECONNABORTED') {
Consola.error(
`Ping timed out for app with id '${input.id}' in config '${input.configName}' -> url: ${app.url})`
);
throw new TRPCError({
code: 'TIMEOUT',
cause: input,
message: `Ping timed out`,
});
}
Consola.error(`Unexpected response: ${error.message}`);
throw new TRPCError({
code: 'UNPROCESSABLE_CONTENT',
cause: input,
message: `Unexpected response: ${error.message}`,
});
});
return res;
}),
});

View File

@@ -1,13 +1,13 @@
import Consola from 'consola';
import { removeTrailingSlash } from 'next/dist/shared/lib/router/utils/remove-trailing-slash';
import { z } from 'zod';
import { checkIntegrationsType } from '~/tools/client/app-properties';
import { getConfig } from '~/tools/config/getConfig';
import { MediaRequestListWidget } from '~/widgets/media-requests/MediaRequestListTile';
import { MediaRequestStatsWidget } from '~/widgets/media-requests/MediaRequestStatsTile';
import { MediaRequest, Users } from '~/widgets/media-requests/media-request-types';
import { createTRPCRouter, publicProcedure } from '../trpc';
import { MediaRequestStatsWidget } from '~/widgets/media-requests/MediaRequestStatsTile';
import { removeTrailingSlash } from 'next/dist/shared/lib/router/utils/remove-trailing-slash';
export const mediaRequestsRouter = createTRPCRouter({
allMedia: publicProcedure
@@ -33,9 +33,11 @@ export const mediaRequestsRouter = createTRPCRouter({
})
.then(async (response) => {
const body = (await response.json()) as OverseerrResponse;
let appUrl = input.widget.properties.replaceLinksWithExternalHost && app.behaviour.externalUrl?.length > 0
? app.behaviour.externalUrl
: app.url;
let appUrl =
input.widget.properties.replaceLinksWithExternalHost &&
app.behaviour.externalUrl?.length > 0
? app.behaviour.externalUrl
: app.url;
appUrl = removeTrailingSlash(appUrl);
@@ -163,7 +165,7 @@ const retrieveDetailsForItem = async (
backdropPath: series.backdropPath,
posterPath: series.backdropPath,
};
};
}
const movieResponse = await fetch(`${baseUrl}/api/v1/movie/${id}`, {
headers,

View File

@@ -2,21 +2,18 @@ import { Jellyfin } from '@jellyfin/sdk';
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models';
import { getSessionApi } from '@jellyfin/sdk/lib/utils/api/session-api';
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
import Consola from 'consola';
import { z } from 'zod';
import { createTRPCRouter, publicProcedure } from '../trpc';
import { ConfigAppType } from '~/types/app';
import { checkIntegrationsType, findAppProperty } from '~/tools/client/app-properties';
import { getConfig } from '~/tools/config/getConfig';
import { PlexClient } from '~/tools/server/sdk/plex/plexClient';
import { trimStringEnding } from '~/tools/shared/strings';
import { GenericMediaServer } from '~/types/api/media-server/media-server';
import { MediaServersResponseType } from '~/types/api/media-server/response';
import { GenericCurrentlyPlaying, GenericSessionInfo } from '~/types/api/media-server/session-info';
import { PlexClient } from '~/tools/server/sdk/plex/plexClient';
import { ConfigAppType } from '~/types/app';
import { createTRPCRouter, publicProcedure } from '../trpc';
const jellyfin = new Jellyfin({
clientInfo: {
@@ -108,7 +105,13 @@ const handleServer = async (app: ConfigAppType): Promise<GenericMediaServer | un
return {
type: 'jellyfin',
appId: app.id,
serverAddress: trimStringEnding(app.url, ['/web/index.html#!/home.html', '/web', '/web/index.html', '/web/', '/web/index.html#']),
serverAddress: trimStringEnding(app.url, [
'/web/index.html#!/home.html',
'/web',
'/web/index.html',
'/web/',
'/web/index.html#',
]),
version: infoApi.data.Version ?? undefined,
sessions: sessions
.filter((session) => session.NowPlayingItem)
@@ -180,7 +183,13 @@ const handleServer = async (app: ConfigAppType): Promise<GenericMediaServer | un
if (!apiKey) {
return {
serverAddress: trimStringEnding(app.url, ['/web', '/web/index.html', '/web/index.html#!', '/web/index.html#!/settings/web/general', '/web/']),
serverAddress: trimStringEnding(app.url, [
'/web',
'/web/index.html',
'/web/index.html#!',
'/web/index.html#!/settings/web/general',
'/web/',
]),
sessions: [],
type: 'plex',
appId: app.id,

View File

@@ -70,7 +70,7 @@ export const rssRouter = createTRPCRouter({
}
if (input.feedUrls.length === 0) {
return []
return [];
}
const result = await Promise.all(

View File

@@ -1,18 +1,19 @@
import { z } from 'zod';
const GeoTz = require('browser-geo-tz/dist/geotz.js');
import { createTRPCRouter, publicProcedure } from '../trpc';
const GeoTz = require('browser-geo-tz/dist/geotz.js');
export const timezoneRouter = createTRPCRouter({
at: publicProcedure
.input(
z.object({
z.object({
longitude: z.number(),
latitude: z.number(),
})
})
)
.query(async ({ input }) => {
const timezone = GeoTz.find(input.latitude,input.longitude);
return Array.isArray(timezone) ? timezone[0] : timezone;
const timezone = GeoTz.find(input.latitude, input.longitude);
return Array.isArray(timezone) ? timezone[0] : timezone;
}),
})
});