mirror of
https://github.com/movie-web/backend.git
synced 2025-09-13 14:53:25 +00:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
befa173445 | ||
|
1c1d70fa05 | ||
|
6b83fcd158 | ||
|
f8870b5929 | ||
|
727a9cdd43 | ||
|
206844e758 | ||
|
b2e0841d0b | ||
|
886df2ffb4 | ||
|
6ea07ea685 | ||
|
1010eaf71e | ||
|
ebe00ecbd6 | ||
|
3bb427401f | ||
|
b2598e3d82 | ||
|
bf55be2978 | ||
|
8f52dad296 | ||
|
9a27b0b0b4 | ||
|
46baac466d |
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "backend",
|
"name": "backend",
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"homepage": "https://github.com/movie-web/backend",
|
"homepage": "https://github.com/movie-web/backend",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -8,16 +8,16 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon -r tsconfig-paths/register src/main.ts",
|
"dev": "nodemon -r tsconfig-paths/register src/main.ts",
|
||||||
"build": "npm run build:pre && npm run build:compile",
|
"build": "pnpm run build:pre && pnpm run build:compile",
|
||||||
"start": "node dist/main.js",
|
"start": "node dist/main.js",
|
||||||
"lint": "eslint --ext .ts,.js,.json,.tsx src/",
|
"lint": "eslint --ext .ts,.js,.json,.tsx src/",
|
||||||
"lint:fix": "eslint --fix --ext .ts,.js,.json,.tsx src/",
|
"lint:fix": "eslint --fix --ext .ts,.js,.json,.tsx src/",
|
||||||
"build:pre": "rimraf dist/",
|
"build:pre": "rimraf dist/",
|
||||||
"build:compile": "tsc && tsc-alias",
|
"build:compile": "tsc && tsc-alias",
|
||||||
"preinstall": "npx -y only-allow pnpm",
|
"preinstall": "npx -y only-allow pnpm",
|
||||||
"migration:create": "npx -y mikro-orm migration:create",
|
"migration:create": "pnpm exec mikro-orm migration:create",
|
||||||
"migration:up": "npx -y mikro-orm migration:up",
|
"migration:up": "pnpm exec mikro-orm migration:up",
|
||||||
"migration:down": "npx -y mikro-orm migration:down"
|
"migration:down": "pnpm exec mikro-orm migration:down"
|
||||||
},
|
},
|
||||||
"mikro-orm": {
|
"mikro-orm": {
|
||||||
"useTsNode": true,
|
"useTsNode": true,
|
||||||
|
@@ -12,6 +12,8 @@ export const ormConfigSchema = z.object({
|
|||||||
postgres: z.object({
|
postgres: z.object({
|
||||||
// connection URL for postgres database
|
// connection URL for postgres database
|
||||||
connection: z.string(),
|
connection: z.string(),
|
||||||
|
// whether to use SSL for the connection
|
||||||
|
ssl: z.coerce.boolean().default(false),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -48,6 +48,9 @@ export const configSchema = z.object({
|
|||||||
// Enable debug logging for MikroORM - Outputs queries and entity management logs
|
// Enable debug logging for MikroORM - Outputs queries and entity management logs
|
||||||
// Do NOT use in production, leaks all sensitive data
|
// Do NOT use in production, leaks all sensitive data
|
||||||
debugLogging: z.coerce.boolean().default(false),
|
debugLogging: z.coerce.boolean().default(false),
|
||||||
|
|
||||||
|
// Enable SSL for the postgres connection
|
||||||
|
ssl: z.coerce.boolean().default(false),
|
||||||
}),
|
}),
|
||||||
crypto: z.object({
|
crypto: z.object({
|
||||||
// session secret. used for signing session tokens
|
// session secret. used for signing session tokens
|
||||||
|
@@ -483,6 +483,15 @@
|
|||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
"mappedType": "string"
|
"mappedType": "string"
|
||||||
|
},
|
||||||
|
"proxy_urls": {
|
||||||
|
"name": "proxy_urls",
|
||||||
|
"type": "text[]",
|
||||||
|
"unsigned": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"primary": false,
|
||||||
|
"nullable": true,
|
||||||
|
"mappedType": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "user_settings",
|
"name": "user_settings",
|
||||||
|
13
src/db/migrations/Migration20231229214215.ts
Normal file
13
src/db/migrations/Migration20231229214215.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Migration } from '@mikro-orm/migrations';
|
||||||
|
|
||||||
|
export class Migration20231229214215 extends Migration {
|
||||||
|
|
||||||
|
async up(): Promise<void> {
|
||||||
|
this.addSql('alter table "user_settings" add column "proxy_urls" text[] null;');
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(): Promise<void> {
|
||||||
|
this.addSql('alter table "user_settings" drop column "proxy_urls";');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
|
import { ArrayType, Entity, PrimaryKey, Property } from '@mikro-orm/core';
|
||||||
|
|
||||||
@Entity({ tableName: 'user_settings' })
|
@Entity({ tableName: 'user_settings' })
|
||||||
export class UserSettings {
|
export class UserSettings {
|
||||||
@@ -13,6 +13,9 @@ export class UserSettings {
|
|||||||
|
|
||||||
@Property({ name: 'default_subtitle_language', nullable: true })
|
@Property({ name: 'default_subtitle_language', nullable: true })
|
||||||
defaultSubtitleLanguage?: string | null;
|
defaultSubtitleLanguage?: string | null;
|
||||||
|
|
||||||
|
@Property({ name: 'proxy_urls', type: ArrayType, nullable: true })
|
||||||
|
proxyUrls?: string[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserSettingsDTO {
|
export interface UserSettingsDTO {
|
||||||
@@ -20,6 +23,7 @@ export interface UserSettingsDTO {
|
|||||||
applicationTheme?: string | null;
|
applicationTheme?: string | null;
|
||||||
applicationLanguage?: string | null;
|
applicationLanguage?: string | null;
|
||||||
defaultSubtitleLanguage?: string | null;
|
defaultSubtitleLanguage?: string | null;
|
||||||
|
proxyUrls?: string[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatUserSettings(
|
export function formatUserSettings(
|
||||||
@@ -30,5 +34,6 @@ export function formatUserSettings(
|
|||||||
applicationTheme: userSettings.applicationTheme,
|
applicationTheme: userSettings.applicationTheme,
|
||||||
applicationLanguage: userSettings.applicationLanguage,
|
applicationLanguage: userSettings.applicationLanguage,
|
||||||
defaultSubtitleLanguage: userSettings.defaultSubtitleLanguage,
|
defaultSubtitleLanguage: userSettings.defaultSubtitleLanguage,
|
||||||
|
proxyUrls: userSettings.proxyUrls,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { ormConf } from '@/config/orm';
|
import { ormConf } from '@/config/orm';
|
||||||
import { makeOrmConfig } from '@/modules/mikro/orm';
|
import { makeOrmConfig } from '@/modules/mikro/orm';
|
||||||
|
|
||||||
export default makeOrmConfig(ormConf.postgres.connection);
|
export default makeOrmConfig(ormConf.postgres.connection, ormConf.postgres.ssl);
|
||||||
|
@@ -67,6 +67,7 @@ export async function setupMetrics(app: FastifyInstance) {
|
|||||||
promClient.register.registerMetric(metrics.providerHostnames);
|
promClient.register.registerMetric(metrics.providerHostnames);
|
||||||
promClient.register.registerMetric(metrics.providerStatuses);
|
promClient.register.registerMetric(metrics.providerStatuses);
|
||||||
promClient.register.registerMetric(metrics.watchMetrics);
|
promClient.register.registerMetric(metrics.watchMetrics);
|
||||||
|
promClient.register.registerMetric(metrics.captchaSolves);
|
||||||
|
|
||||||
const orm = getORM();
|
const orm = getORM();
|
||||||
const em = orm.em.fork();
|
const em = orm.em.fork();
|
||||||
|
@@ -18,6 +18,7 @@ export async function setupMikroORM() {
|
|||||||
conf.postgres.connection,
|
conf.postgres.connection,
|
||||||
conf.postgres.debugLogging,
|
conf.postgres.debugLogging,
|
||||||
(msg) => log.info(msg),
|
(msg) => log.info(msg),
|
||||||
|
conf.postgres.ssl,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (conf.postgres.syncSchema) {
|
if (conf.postgres.syncSchema) {
|
||||||
|
@@ -2,7 +2,10 @@ import { Options } from '@mikro-orm/core';
|
|||||||
import { MikroORM, PostgreSqlDriver } from '@mikro-orm/postgresql';
|
import { MikroORM, PostgreSqlDriver } from '@mikro-orm/postgresql';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export function makeOrmConfig(url: string): Options<PostgreSqlDriver> {
|
export function makeOrmConfig(
|
||||||
|
url: string,
|
||||||
|
ssl: boolean,
|
||||||
|
): Options<PostgreSqlDriver> {
|
||||||
return {
|
return {
|
||||||
type: 'postgresql',
|
type: 'postgresql',
|
||||||
clientUrl: url,
|
clientUrl: url,
|
||||||
@@ -13,6 +16,11 @@ export function makeOrmConfig(url: string): Options<PostgreSqlDriver> {
|
|||||||
pathTs: './migrations',
|
pathTs: './migrations',
|
||||||
path: './migrations',
|
path: './migrations',
|
||||||
},
|
},
|
||||||
|
driverOptions: {
|
||||||
|
connection: {
|
||||||
|
ssl,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,9 +28,10 @@ export async function createORM(
|
|||||||
url: string,
|
url: string,
|
||||||
debug: boolean,
|
debug: boolean,
|
||||||
log: (msg: string) => void,
|
log: (msg: string) => void,
|
||||||
|
ssl: boolean,
|
||||||
) {
|
) {
|
||||||
return await MikroORM.init<PostgreSqlDriver>({
|
return await MikroORM.init<PostgreSqlDriver>({
|
||||||
...makeOrmConfig(url),
|
...makeOrmConfig(url, ssl),
|
||||||
logger: log,
|
logger: log,
|
||||||
debug,
|
debug,
|
||||||
});
|
});
|
||||||
|
@@ -41,6 +41,7 @@ export const userSettingsRouter = makeRouter((app) => {
|
|||||||
applicationLanguage: z.string().nullable().optional(),
|
applicationLanguage: z.string().nullable().optional(),
|
||||||
applicationTheme: z.string().nullable().optional(),
|
applicationTheme: z.string().nullable().optional(),
|
||||||
defaultSubtitleLanguage: z.string().nullable().optional(),
|
defaultSubtitleLanguage: z.string().nullable().optional(),
|
||||||
|
proxyUrls: z.string().array().nullable().optional(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -64,6 +65,7 @@ export const userSettingsRouter = makeRouter((app) => {
|
|||||||
settings.defaultSubtitleLanguage = body.defaultSubtitleLanguage;
|
settings.defaultSubtitleLanguage = body.defaultSubtitleLanguage;
|
||||||
if (body.applicationTheme !== undefined)
|
if (body.applicationTheme !== undefined)
|
||||||
settings.applicationTheme = body.applicationTheme;
|
settings.applicationTheme = body.applicationTheme;
|
||||||
|
if (body.proxyUrls !== undefined) settings.proxyUrls = body.proxyUrls;
|
||||||
|
|
||||||
await em.persistAndFlush(settings);
|
await em.persistAndFlush(settings);
|
||||||
return formatUserSettings(settings);
|
return formatUserSettings(settings);
|
||||||
|
Reference in New Issue
Block a user