Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamelane committed Dec 9, 2024
1 parent b76ddea commit dedaf0a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
10 changes: 1 addition & 9 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import { Elysia } from 'elysia'
import { compression } from 'elysia-compression'
import { helmet } from 'elysia-helmet'

import { BOT_TOKEN, TIMEZONE } from '@config'
import { TIMEZONE } from '@config'
import { sequelize } from '@db'

import { getTimezone } from './config/getTimeZone'
import { routes } from './routes'

import './models/relations'
import staticPlugin from '@elysiajs/static'
import { syncDatabaseForDecorations } from './helpers/syncDatabaseForDecorations'
import {crutchesInit} from "./helpers/crutches";

Expand Down Expand Up @@ -43,13 +42,6 @@ const app = new Elysia()
origin: true
})
)
.use(
staticPlugin({
assets: 'src/uploads',
prefix: 'uploads',
staticLimit: 1_000_000
})
)
// сжатие...
.use(
compression({
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LessonsController } from './lessons'
import {BuyAvatar, MarketAvatars, UserAvatars, UserInfo, UserSaveAvatar} from './market'
import { OrganizationController } from './organization'
import { PerformanceCurrentController } from './performance.current'
import {StaticController} from "./static";

export const routes = new Elysia()
.use(HomeController)
Expand All @@ -26,6 +27,7 @@ export const routes = new Elysia()
.use(BuyAvatar)
.use(UserAvatars)
.use(UserSaveAvatar)
.use(StaticController)
/** Обработка любых ошибок в кажом роуте **/
.onError(({ set, code, path, error }) => {
if (Number(code)) {
Expand Down
10 changes: 10 additions & 0 deletions apps/api/src/routes/static/handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = import.meta.filename.split('src')[0] + 'src/uploads/avatars/'

export const getStaticFile = async (filename: string): Promise<any> => {
const file = Bun.file(path + filename)

if (!await file.exists())
return 'NOT_FOUND'

return file
}
20 changes: 20 additions & 0 deletions apps/api/src/routes/static/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Elysia, t } from 'elysia'
import {getStaticFile} from './handler'

export const StaticController = new Elysia()
.get(
'/uploads/avatars/:filename',
({
params: {
filename
}
}) => getStaticFile(filename),
{
detail: {
tags: ['Current Performance']
},
params: t.Object({
filename: t.String()
})
}
)

0 comments on commit dedaf0a

Please sign in to comment.