mirror of
https://github.com/BradNut/TofuStack
synced 2025-09-08 17:40:26 +00:00
moved dtos within api folder
This commit is contained in:
parent
e512fab9f9
commit
4f38b4a6d0
16 changed files with 155 additions and 24 deletions
3
Dockerfile.minio
Normal file
3
Dockerfile.minio
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
FROM nginx:stable-alpine-slim
|
||||||
|
COPY minio-console.conf.template /etc/nginx/templates/
|
||||||
|
RUN rm /etc/nginx/conf.d/default.conf /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
|
||||||
41
minio-console.conf.template
Normal file
41
minio-console.conf.template
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
upstream minio_console {
|
||||||
|
server ${MINIO_HOST}:${MINIO_CONSOLE_PORT};
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen ${PORT};
|
||||||
|
|
||||||
|
# Allow special characters in headers
|
||||||
|
ignore_invalid_headers off;
|
||||||
|
# Allow any size file to be uploaded.
|
||||||
|
# Set to a value such as 1000m; to restrict file size to a specific value
|
||||||
|
client_max_body_size 0;
|
||||||
|
# Disable buffering
|
||||||
|
proxy_buffering off;
|
||||||
|
proxy_request_buffering off;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-NginX-Proxy true;
|
||||||
|
|
||||||
|
# This is necessary to pass the correct IP to be hashed
|
||||||
|
real_ip_header X-Real-IP;
|
||||||
|
|
||||||
|
proxy_connect_timeout 300;
|
||||||
|
|
||||||
|
# To support websockets in MinIO versions released after January 2023
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
# Some environments may encounter CORS errors (Kubernetes + Nginx Ingress)
|
||||||
|
# Uncomment the following line to set the Origin request to an empty string
|
||||||
|
# proxy_set_header Origin '';
|
||||||
|
|
||||||
|
chunked_transfer_encoding off;
|
||||||
|
|
||||||
|
proxy_pass http://minio_console; # This uses the upstream directive definition to load balance
|
||||||
|
}
|
||||||
|
}
|
||||||
68
render.yaml
68
render.yaml
|
|
@ -1,4 +1,5 @@
|
||||||
services:
|
services:
|
||||||
|
# Web
|
||||||
- type: web
|
- type: web
|
||||||
name: web
|
name: web
|
||||||
runtime: node
|
runtime: node
|
||||||
|
|
@ -9,6 +10,21 @@ services:
|
||||||
startCommand: npm run db:migrate && node build/index.js
|
startCommand: npm run db:migrate && node build/index.js
|
||||||
healthCheckPath: /
|
healthCheckPath: /
|
||||||
envVars:
|
envVars:
|
||||||
|
- key: STORAGE_API_SECRET_KEY
|
||||||
|
fromService:
|
||||||
|
name: minio-server
|
||||||
|
type: web
|
||||||
|
property: MINIO_ROOT_PASSWORD
|
||||||
|
- key: STORAGE_ACCESS_KEY
|
||||||
|
fromService:
|
||||||
|
name: minio-server
|
||||||
|
type: web
|
||||||
|
property: MINIO_ROOT_USER
|
||||||
|
- key: STORAGE_API_URL
|
||||||
|
fromService:
|
||||||
|
name: minio-server
|
||||||
|
type: web
|
||||||
|
property: connectionString
|
||||||
- key: DATABASE_URL
|
- key: DATABASE_URL
|
||||||
fromDatabase:
|
fromDatabase:
|
||||||
name: tofustack
|
name: tofustack
|
||||||
|
|
@ -23,10 +39,62 @@ services:
|
||||||
name: web
|
name: web
|
||||||
type: web
|
type: web
|
||||||
property: host
|
property: host
|
||||||
|
# Redis
|
||||||
- type: redis
|
- type: redis
|
||||||
name: redis
|
name: redis
|
||||||
ipAllowList: [] # Only allow internal connections
|
ipAllowList: [] # Only allow internal connections
|
||||||
|
|
||||||
|
# MinIO Server
|
||||||
|
- type: web
|
||||||
|
name: minio-server
|
||||||
|
healthCheckPath: /minio/health/liveweb
|
||||||
|
runtime: image
|
||||||
|
image:
|
||||||
|
url: docker.io/minio/minio:latest
|
||||||
|
dockerCommand: minio server /data --address $HOST:$PORT --console-address $HOST:$CONSOLE_PORT
|
||||||
|
# Use the following 'dockerCommand' if removing the 'minio-console'
|
||||||
|
# web service
|
||||||
|
# dockerCommand: minio server /data --address $HOST:$PORT
|
||||||
|
autoDeploy: false
|
||||||
|
disk:
|
||||||
|
name: data
|
||||||
|
mountPath: /data
|
||||||
|
envVars:
|
||||||
|
- key: MINIO_ROOT_USER
|
||||||
|
generateValue: true
|
||||||
|
- key: MINIO_ROOT_PASSWORD
|
||||||
|
generateValue: true
|
||||||
|
- key: HOST
|
||||||
|
value: "0.0.0.0"
|
||||||
|
- key: PORT
|
||||||
|
value: 9000
|
||||||
|
- key: CONSOLE_PORT
|
||||||
|
value: 9090
|
||||||
|
# Uncomment the following key/value pair if you are removing the
|
||||||
|
# 'minio-console' web service
|
||||||
|
# - key: MINIO_BROWSER
|
||||||
|
# value: "off"
|
||||||
|
# MinIO Console
|
||||||
|
- type: web
|
||||||
|
name: minio-console
|
||||||
|
runtime: docker
|
||||||
|
dockerContext: /
|
||||||
|
dockerfilePath: ./Dockerfile.minio
|
||||||
|
autoDeploy: false
|
||||||
|
envVars:
|
||||||
|
- key: PORT
|
||||||
|
value: 10000
|
||||||
|
- key: MINIO_HOST
|
||||||
|
fromService:
|
||||||
|
name: minio-server
|
||||||
|
type: web
|
||||||
|
property: host
|
||||||
|
- key: MINIO_CONSOLE_PORT
|
||||||
|
fromService:
|
||||||
|
name: minio-server
|
||||||
|
type: web
|
||||||
|
envVarKey: CONSOLE_PORT
|
||||||
|
|
||||||
databases:
|
databases:
|
||||||
- name: db
|
- name: db
|
||||||
databaseName: tofustack
|
databaseName: tofustack
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ import { LuciaProvider } from '../providers/lucia.provider';
|
||||||
import { limiter } from '../middlewares/rate-limiter.middlware';
|
import { limiter } from '../middlewares/rate-limiter.middlware';
|
||||||
import { requireAuth } from '../middlewares/auth.middleware';
|
import { requireAuth } from '../middlewares/auth.middleware';
|
||||||
import { Controler } from '../common/classes/controller.class';
|
import { Controler } from '../common/classes/controller.class';
|
||||||
import { registerEmailDto } from '$lib/dtos/register-email.dto';
|
import { registerEmailDto } from '$lib/server/api/dtos/register-email.dto';
|
||||||
import { signInEmailDto } from '$lib/dtos/signin-email.dto';
|
import { signInEmailDto } from '$lib/server/api/dtos/signin-email.dto';
|
||||||
import { updateEmailDto } from '$lib/dtos/update-email.dto';
|
import { updateEmailDto } from '$lib/server/api/dtos/update-email.dto';
|
||||||
import { verifyEmailDto } from '$lib/dtos/verify-email.dto';
|
import { verifyEmailDto } from '$lib/server/api/dtos/verify-email.dto';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class IamController extends Controler {
|
export class IamController extends Controler {
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@ import { z } from 'zod';
|
||||||
export const verifyEmailDto = z.object({
|
export const verifyEmailDto = z.object({
|
||||||
token: z.string()
|
token: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type VerifyEmailDto = z.infer<typeof verifyEmailDto>;
|
export type VerifyEmailDto = z.infer<typeof verifyEmailDto>;
|
||||||
|
|
@ -3,8 +3,8 @@ import { MailerService } from './mailer.service';
|
||||||
import { TokensService } from './tokens.service';
|
import { TokensService } from './tokens.service';
|
||||||
import { LuciaProvider } from '../providers/lucia.provider';
|
import { LuciaProvider } from '../providers/lucia.provider';
|
||||||
import { UsersRepository } from '../repositories/users.repository';
|
import { UsersRepository } from '../repositories/users.repository';
|
||||||
import type { SignInEmailDto } from '../../../dtos/signin-email.dto';
|
import type { SignInEmailDto } from '../dtos/signin-email.dto';
|
||||||
import type { RegisterEmailDto } from '../../../dtos/register-email.dto';
|
import type { RegisterEmailDto } from '../dtos/register-email.dto';
|
||||||
import { LoginRequestsRepository } from '../repositories/login-requests.repository';
|
import { LoginRequestsRepository } from '../repositories/login-requests.repository';
|
||||||
import { LoginVerificationEmail } from '../emails/login-verification.email';
|
import { LoginVerificationEmail } from '../emails/login-verification.email';
|
||||||
import { DatabaseProvider } from '../providers/database.provider';
|
import { DatabaseProvider } from '../providers/database.provider';
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,28 @@
|
||||||
import { zod } from "sveltekit-superforms/adapters";
|
import { zod } from "sveltekit-superforms/adapters";
|
||||||
import { updateEmailDto } from "$lib/dtos/update-email.dto.js";
|
|
||||||
import { verifyEmailDto } from "$lib/dtos/verify-email.dto.js";
|
|
||||||
import { fail, setError, superValidate } from "sveltekit-superforms";
|
import { fail, setError, superValidate } from "sveltekit-superforms";
|
||||||
import { StatusCodes } from "$lib/constants/status-codes.js";
|
import { StatusCodes } from "$lib/constants/status-codes.js";
|
||||||
|
import { updateEmailFormSchema, verifyEmailFormSchema } from "./schemas.js";
|
||||||
|
|
||||||
export let load = async (event) => {
|
export let load = async (event) => {
|
||||||
const authedUser = await event.locals.getAuthedUserOrThrow()
|
const authedUser = await event.locals.getAuthedUserOrThrow()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authedUser,
|
authedUser,
|
||||||
updateEmailForm: await superValidate(authedUser, zod(updateEmailDto)),
|
updateEmailForm: await superValidate(authedUser, zod(updateEmailFormSchema)),
|
||||||
verifyEmailForm: await superValidate(zod(verifyEmailDto))
|
verifyEmailForm: await superValidate(zod(verifyEmailFormSchema))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
updateEmail: async ({ request, locals }) => {
|
updateEmail: async ({ request, locals }) => {
|
||||||
const updateEmailForm = await superValidate(request, zod(updateEmailDto));
|
const updateEmailForm = await superValidate(request, zod(updateEmailFormSchema));
|
||||||
if (!updateEmailForm.valid) return fail(StatusCodes.BAD_REQUEST, { updateEmailForm })
|
if (!updateEmailForm.valid) return fail(StatusCodes.BAD_REQUEST, { updateEmailForm })
|
||||||
const { error } = await locals.api.iam.email.$patch({ json: updateEmailForm.data }).then(locals.parseApiResponse);
|
const { error } = await locals.api.iam.email.$patch({ json: updateEmailForm.data }).then(locals.parseApiResponse);
|
||||||
if (error) return setError(updateEmailForm, 'email', error);
|
if (error) return setError(updateEmailForm, 'email', error);
|
||||||
return { updateEmailForm }
|
return { updateEmailForm }
|
||||||
},
|
},
|
||||||
verifyEmail: async ({ request, locals }) => {
|
verifyEmail: async ({ request, locals }) => {
|
||||||
const verifyEmailForm = await superValidate(request, zod(verifyEmailDto));
|
const verifyEmailForm = await superValidate(request, zod(verifyEmailFormSchema));
|
||||||
console.log(verifyEmailForm)
|
console.log(verifyEmailForm)
|
||||||
if (!verifyEmailForm.valid) return fail(StatusCodes.BAD_REQUEST, { verifyEmailForm })
|
if (!verifyEmailForm.valid) return fail(StatusCodes.BAD_REQUEST, { verifyEmailForm })
|
||||||
const { error } = await locals.api.iam.email.verification.$post({ json: verifyEmailForm.data }).then(locals.parseApiResponse);
|
const { error } = await locals.api.iam.email.verification.$post({ json: verifyEmailForm.data }).then(locals.parseApiResponse);
|
||||||
|
|
|
||||||
9
src/routes/(app)/settings/account/schemas.ts
Normal file
9
src/routes/(app)/settings/account/schemas.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const verifyEmailFormSchema = z.object({
|
||||||
|
token: z.string()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const updateEmailFormSchema = z.object({
|
||||||
|
email: z.string().email()
|
||||||
|
});
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
<script context="module" lang="ts">
|
<script context="module" lang="ts">
|
||||||
import type { SuperValidated, Infer } from 'sveltekit-superforms';
|
import type { SuperValidated, Infer } from 'sveltekit-superforms';
|
||||||
import type { updateEmailDto } from '$lib/dtos/update-email.dto';
|
|
||||||
import type { verifyEmailDto } from '$lib/dtos/verify-email.dto';
|
|
||||||
|
|
||||||
interface UpdateEmailCardProps {
|
interface UpdateEmailCardProps {
|
||||||
updateEmailForm: SuperValidated<Infer<typeof updateEmailDto>>;
|
updateEmailForm: SuperValidated<Infer<typeof updateEmailDto>>;
|
||||||
|
|
@ -16,6 +14,8 @@
|
||||||
import { superForm } from 'sveltekit-superforms';
|
import { superForm } from 'sveltekit-superforms';
|
||||||
import * as Dialog from '$lib/components/ui/dialog';
|
import * as Dialog from '$lib/components/ui/dialog';
|
||||||
import PinInput from '$lib/components/pin-input.svelte';
|
import PinInput from '$lib/components/pin-input.svelte';
|
||||||
|
import type { updateEmailDto } from '$lib/server/api/dtos/update-email.dto';
|
||||||
|
import type { verifyEmailDto } from '$lib/server/api/dtos/verify-email.dto';
|
||||||
|
|
||||||
/* ---------------------------------- props --------------------------------- */
|
/* ---------------------------------- props --------------------------------- */
|
||||||
let { updateEmailForm, verifyEmailForm }: UpdateEmailCardProps = $props();
|
let { updateEmailForm, verifyEmailForm }: UpdateEmailCardProps = $props();
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,26 @@
|
||||||
import { fail, redirect } from '@sveltejs/kit';
|
import { fail, redirect } from '@sveltejs/kit';
|
||||||
import { zod } from 'sveltekit-superforms/adapters';
|
import { zod } from 'sveltekit-superforms/adapters';
|
||||||
import { StatusCodes } from '$lib/constants/status-codes';
|
import { StatusCodes } from '$lib/constants/status-codes';
|
||||||
import { registerEmailDto } from '$lib/dtos/register-email.dto';
|
|
||||||
import { signInEmailDto } from '$lib/dtos/signin-email.dto';
|
|
||||||
import { setError, superValidate } from 'sveltekit-superforms';
|
import { setError, superValidate } from 'sveltekit-superforms';
|
||||||
|
import { registerFormSchema, signInFormSchema } from './schemas';
|
||||||
|
|
||||||
export const load = async () => {
|
export const load = async () => {
|
||||||
return {
|
return {
|
||||||
emailRegisterForm: await superValidate(zod(registerEmailDto)),
|
emailRegisterForm: await superValidate(zod(registerFormSchema)),
|
||||||
emailSigninForm: await superValidate(zod(signInEmailDto))
|
emailSigninForm: await superValidate(zod(signInFormSchema))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
register: async ({ locals, request }) => {
|
register: async ({ locals, request }) => {
|
||||||
const emailRegisterForm = await superValidate(request, zod(registerEmailDto));
|
const emailRegisterForm = await superValidate(request, zod(registerFormSchema));
|
||||||
if (!emailRegisterForm.valid) return fail(StatusCodes.BAD_REQUEST, { emailRegisterForm });
|
if (!emailRegisterForm.valid) return fail(StatusCodes.BAD_REQUEST, { emailRegisterForm });
|
||||||
const { error } = await locals.api.iam.login.request.$post({ json: emailRegisterForm.data }).then(locals.parseApiResponse);
|
const { error } = await locals.api.iam.login.request.$post({ json: emailRegisterForm.data }).then(locals.parseApiResponse);
|
||||||
if (error) return setError(emailRegisterForm, 'email', error);
|
if (error) return setError(emailRegisterForm, 'email', error);
|
||||||
return { emailRegisterForm };
|
return { emailRegisterForm };
|
||||||
},
|
},
|
||||||
signin: async ({ locals, request }) => {
|
signin: async ({ locals, request }) => {
|
||||||
const emailSignInForm = await superValidate(request, zod(signInEmailDto));
|
const emailSignInForm = await superValidate(request, zod(signInFormSchema));
|
||||||
if (!emailSignInForm.valid) return fail(StatusCodes.BAD_REQUEST, { emailSignInForm });
|
if (!emailSignInForm.valid) return fail(StatusCodes.BAD_REQUEST, { emailSignInForm });
|
||||||
const { error } = await locals.api.iam.login.verify.$post({ json: emailSignInForm.data }).then(locals.parseApiResponse)
|
const { error } = await locals.api.iam.login.verify.$post({ json: emailSignInForm.data }).then(locals.parseApiResponse)
|
||||||
if (error) return setError(emailSignInForm, 'token', error);
|
if (error) return setError(emailSignInForm, 'token', error);
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,15 @@
|
||||||
import { superForm } from 'sveltekit-superforms';
|
import { superForm } from 'sveltekit-superforms';
|
||||||
import * as Form from '$lib/components/ui/form';
|
import * as Form from '$lib/components/ui/form';
|
||||||
import { zodClient } from 'sveltekit-superforms/adapters';
|
import { zodClient } from 'sveltekit-superforms/adapters';
|
||||||
import { registerEmailDto } from '$lib/dtos/register-email.dto.js';
|
|
||||||
import { signInEmailDto } from '$lib/dtos/signin-email.dto.js';
|
|
||||||
import PinInput from '$lib/components/pin-input.svelte';
|
import PinInput from '$lib/components/pin-input.svelte';
|
||||||
|
import { registerFormSchema, signInFormSchema } from './schemas.js';
|
||||||
|
|
||||||
const { data } = $props();
|
const { data } = $props();
|
||||||
|
|
||||||
let showTokenVerification = $state(false);
|
let showTokenVerification = $state(false);
|
||||||
|
|
||||||
const emailRegisterForm = superForm(data.emailRegisterForm, {
|
const emailRegisterForm = superForm(data.emailRegisterForm, {
|
||||||
validators: zodClient(registerEmailDto),
|
validators: zodClient(registerFormSchema),
|
||||||
resetForm: false,
|
resetForm: false,
|
||||||
onUpdated: ({ form }) => {
|
onUpdated: ({ form }) => {
|
||||||
if (form.valid) {
|
if (form.valid) {
|
||||||
|
|
@ -25,7 +24,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const emailSigninForm = superForm(data.emailSigninForm, {
|
const emailSigninForm = superForm(data.emailSigninForm, {
|
||||||
validators: zodClient(signInEmailDto),
|
validators: zodClient(signInFormSchema),
|
||||||
resetForm: false
|
resetForm: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
12
src/routes/(auth)/register/schemas.ts
Normal file
12
src/routes/(auth)/register/schemas.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const registerFormSchema = z.object({
|
||||||
|
email: z.string().email()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const signInFormSchema = z.object({
|
||||||
|
email: z.string().email(),
|
||||||
|
token: z.string()
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue