File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { GEMINI_API_KEY } from '$env/static/private ' ;
1+ import { env } from '$/lib/server/env ' ;
22import { GoogleGenerativeAI } from '@google/generative-ai' ;
33import { MiddleWareError } from '@patrick115/sveltekitapi' ;
44import { z } from 'zod' ;
55import { loggedProcedure } from '../api' ;
66
7- const genAI = new GoogleGenerativeAI ( GEMINI_API_KEY ) ;
7+ const genAI = new GoogleGenerativeAI ( env . GEMINI_API_KEY ) ;
88const model = genAI . getGenerativeModel ( { model : 'gemini-2.5-flash-lite' } ) ;
99
1010export default {
Original file line number Diff line number Diff line change 11import { languages , type ErrorPath } from '$/lib/lang' ;
2+ import { env } from '$/lib/server/env' ;
23import { articleSchema as _articleSchema } from '$/types/schemes' ;
34import type { ActionsResponse , Response } from '$/types/types' ;
4- import { FILE_FOLDER } from '$env/static/private' ;
55import { AnyFormDataInput , type ErrorApiResponse } from '@patrick115/sveltekitapi' ;
66import { fail } from '@sveltejs/kit' ;
77import fs from 'node:fs/promises' ;
@@ -12,6 +12,8 @@ import { loggedProcedure } from '../api';
1212import { insertTranslations , parseFormData , updateTranslations } from '../functions' ;
1313import { conn } from '../variables' ;
1414
15+ const FILE_FOLDER = env . FILE_FOLDER ;
16+
1517const articleSchema = _articleSchema ( 'cs' ) ;
1618
1719const TRANSLATION_FIELDS = [ 'title' , 'description' , 'content_md' ] as const ;
Original file line number Diff line number Diff line change 1- import { FormDataInput } from '@patrick115/sveltekitapi' ;
2- import { procedure } from '../api' ;
31import type { ErrorPath } from '$/lib/lang' ;
2+ import { env } from '$/lib/server/env' ;
43import type { ActionsResponse , Response } from '$/types/types' ;
4+ import { FormDataInput } from '@patrick115/sveltekitapi' ;
55import { fail } from '@sveltejs/kit' ;
6- import { conn , jwt } from '../variables' ;
76import bcrypt from 'bcrypt' ;
8- import { COOKIE_EXPIRE } from '$env/static/private' ;
7+ import { procedure } from '../api' ;
8+ import { conn , jwt } from '../variables' ;
99
1010export default procedure . POST . input ( FormDataInput ) . query (
1111 async ( { input, ev : { cookies } } ) => {
1212 const username = input . get ( 'username' ) as string | null ;
1313 const password = input . get ( 'password' ) as string | null ;
14+ const COOKIE_EXPIRE = env . COOKIE_EXPIRE ;
1415
1516 if ( ! username || ! password ) {
1617 return fail ( 401 , {
@@ -48,7 +49,7 @@ export default procedure.POST.input(FormDataInput).query(
4849
4950 cookies . set ( 'session' , session , {
5051 path : '/' ,
51- maxAge : parseInt ( COOKIE_EXPIRE )
52+ maxAge : COOKIE_EXPIRE
5253 } ) ;
5354
5455 return {
Original file line number Diff line number Diff line change 1- import { FormDataInput , type ErrorApiResponse } from '@patrick115/sveltekitapi' ;
2- import { loggedProcedure } from '../api' ;
31import type { ErrorPath } from '$/lib/lang' ;
4- import { isFile , uploadFile } from '../functions ' ;
2+ import { env } from '$/lib/server/env ' ;
53import type { Response , ResponseWithData } from '$/types/types' ;
6- import { z } from 'zod ' ;
4+ import { FormDataInput , type ErrorApiResponse } from '@patrick115/sveltekitapi ' ;
75import fs from 'node:fs/promises' ;
86import Path from 'node:path' ;
9- import { FILE_FOLDER } from '$env/static/private' ;
7+ import { z } from 'zod' ;
8+ import { loggedProcedure } from '../api' ;
9+ import { isFile , uploadFile } from '../functions' ;
10+
11+ const FILE_FOLDER = env . FILE_FOLDER ;
1012
1113export default [
1214 loggedProcedure . POST . input ( FormDataInput ) . query ( async ( { input } ) => {
Original file line number Diff line number Diff line change 1+ import { env as dynamicEnv } from '$env/dynamic/private' ;
2+ import { z } from 'zod' ;
3+
4+ const envSchema = z . object ( {
5+ NINA_BASE_URL : z . string ( ) . default ( 'http://10.10.10.211:1888/' ) ,
6+ UPDATE_THRESHOLD_COUNT : z . coerce . number ( ) . default ( 30 ) ,
7+ JWT_SECRET : z . string ( ) . min ( 1 ) ,
8+ DATABASE_IP : z . string ( ) . min ( 1 ) ,
9+ DATABASE_PORT : z . coerce . number ( ) ,
10+ DATABASE_USER : z . string ( ) . min ( 1 ) ,
11+ DATABASE_PASSWORD : z . string ( ) . min ( 1 ) ,
12+ DATABASE_NAME : z . string ( ) . min ( 1 ) ,
13+ FILE_FOLDER : z . string ( ) . min ( 1 ) ,
14+ GEMINI_API_KEY : z . string ( ) . min ( 1 ) ,
15+ COOKIE_EXPIRE : z . coerce . number ( )
16+ } ) ;
17+
18+ export const env = envSchema . parse ( dynamicEnv ) ;
Original file line number Diff line number Diff line change 1+ import { env } from '$/lib/server/env' ;
12import type { DB , Translations } from '$/types/database' ;
23import {
34 extensions ,
67 type UserData ,
78 type UserState
89} from '$/types/types' ;
9- import { FILE_FOLDER } from '$env/static/private' ;
1010import type { Cookies } from '@sveltejs/kit' ;
1111import { redirect as _redirect } from '@sveltejs/kit' ;
1212import type { ControlledTransaction , Insertable } from 'kysely' ;
@@ -20,6 +20,8 @@ import { languages } from '../lang';
2020import { getState } from '../state.svelte' ;
2121import { conn , jwt } from './variables' ;
2222
23+ const FILE_FOLDER = env . FILE_FOLDER ;
24+
2325const randomBytesAsync = promisify ( crypto . randomBytes ) ;
2426
2527export const getUserState = ( cookies : Cookies ) : UserState => {
Original file line number Diff line number Diff line change @@ -61,8 +61,8 @@ export class NinaClient {
6161 private cachedLiveImage : Buffer | undefined ;
6262
6363 constructor ( ) {
64- this . baseUrl = NINA_BASE_URL ?? 'http://10.10.10.211:1888/' ;
65- this . updateThreshold = parseInt ( UPDATE_THRESHOLD_COUNT || '30' ) ; // Default 30 seconds
64+ this . baseUrl = NINA_BASE_URL ;
65+ this . updateThreshold = UPDATE_THRESHOLD_COUNT ;
6666 }
6767
6868 private async fetch < T > ( endpoint : string ) : Promise < T | null > {
Original file line number Diff line number Diff line change 11import type { DB } from '$/types/database' ;
2- import { env } from '$env/dynamic/private' ;
3- import {
4- DATABASE_IP ,
5- DATABASE_NAME ,
6- DATABASE_PASSWORD ,
7- DATABASE_PORT ,
8- DATABASE_USER ,
9- JWT_SECRET
10- } from '$env/static/private' ;
112import { Kysely , MysqlDialect } from 'kysely' ;
123import { createPool } from 'mysql2' ;
134import { JWTCookies } from './cookies/main' ;
5+ import { env } from './env' ;
146
157export const NINA_BASE_URL = env . NINA_BASE_URL ;
168export const UPDATE_THRESHOLD_COUNT = env . UPDATE_THRESHOLD_COUNT ;
179
18- export const jwt = new JWTCookies ( JWT_SECRET ) ;
10+ export const jwt = new JWTCookies ( env . JWT_SECRET ) ;
1911const dialect = new MysqlDialect ( {
2012 pool : createPool ( {
21- host : DATABASE_IP ,
22- port : parseInt ( DATABASE_PORT ) ,
23- user : DATABASE_USER ,
24- password : DATABASE_PASSWORD ,
25- database : DATABASE_NAME
13+ host : env . DATABASE_IP ,
14+ port : env . DATABASE_PORT ,
15+ user : env . DATABASE_USER ,
16+ password : env . DATABASE_PASSWORD ,
17+ database : env . DATABASE_NAME
2618 } )
2719} ) ;
2820
Original file line number Diff line number Diff line change 1+ import { env } from '$/lib/server/env' ;
2+ import { isDirectory , isFile } from '$/lib/server/functions' ;
3+ import { extensions , type ImageExtension } from '$/types/types' ;
14import { error , type RequestHandler } from '@sveltejs/kit' ;
2- import Path from 'node:path' ;
3- import fs from 'node:fs/promises' ;
45import { createReadStream } from 'node:fs' ;
6+ import fs from 'node:fs/promises' ;
7+ import Path from 'node:path' ;
58import { Readable } from 'node:stream' ;
6- import { FILE_FOLDER } from '$env/static/private' ;
79import sharp from 'sharp' ;
8- import { isDirectory , isFile } from '$/lib/server/functions' ;
9- import { extensions , type ImageExtension } from '$/types/types' ;
10+
11+ const FILE_FOLDER = env . FILE_FOLDER ;
1012
1113const CACHE_FOLDER = '.cache' ;
1214const DEFAULT_IMAGE_QUALITY = 75 ;
You can’t perform that action at this time.
0 commit comments