Skip to content

Commit bdfc372

Browse files
authored
feat: telegram core service (#168)
* feat: telegram core service * fix: css
1 parent 30dc33b commit bdfc372

39 files changed

Lines changed: 1053 additions & 18 deletions

.github/workflows/docker-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Set matrix
2727
id: set-matrix
2828
run: |
29-
APPS=("web-app" "web-storefront" "web-parser" "atrium-telegram" "storefront-telegram")
29+
APPS=("web-app" "web-storefront" "web-parser" "atrium-telegram" "storefront-telegram" "core-telegram")
3030
CHANGED=()
3131
3232
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then

.github/workflows/docker-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set package in env
3434
id: set-package
3535
run: |
36-
APPS=("web-app" "web-storefront" "web-parser" "atrium-telegram" "storefront-telegram")
36+
APPS=("web-app" "web-storefront" "web-parser" "atrium-telegram" "storefront-telegram" "core-telegram")
3737
MATCH="${{ steps.regex-match.outputs.match }}"
3838
3939
if [ -z "$MATCH" ]; then

apps/core-telegram/.env.example

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Main database
2+
DATABASE_URL=
3+
4+
# Queue
5+
QUEUE_URL=
6+
7+
# S3 file storage
8+
NUXT_S3_ACCESS_KEY_ID=
9+
NUXT_S3_BUCKET=
10+
NUXT_S3_ENDPOINT=
11+
NUXT_S3_REGION=
12+
NUXT_S3_SECRET_ACCESS_KEY=
13+
14+
# URL to media server (probably s3 bucket with static URL)
15+
NUXT_PUBLIC_MEDIA_URL=
16+
17+
# Telegram
18+
NUXT_TELEGRAM_LOCAL_BOT_API_SERVER_URL=
19+
NUXT_TELEGRAM_ADMIN_ID=
20+
NUXT_TELEGRAM_WASABI_BOT_ID=
21+
NUXT_TELEGRAM_ATRIUM_BOT_ID=
22+
NUXT_TELEGRAM_ORDER_BOT_ID=
23+
NUXT_TELEGRAM_TEAM_GROUP_ID=
24+
NUXT_TELEGRAM_FILES_GROUP_ID=
25+
26+
# App version
27+
VERSION=

apps/core-telegram/nuxt.config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default defineNuxtConfig({
2+
devtools: {
3+
componentInspector: false,
4+
},
5+
runtimeConfig: {
6+
s3: {
7+
bucket: '',
8+
region: '',
9+
endpoint: '',
10+
accessKeyId: '',
11+
secretAccessKey: '',
12+
},
13+
telegram: {
14+
localBotApiServerUrl: '',
15+
wasabiBotId: '',
16+
atriumBotId: '',
17+
orderBotId: '',
18+
adminId: '',
19+
teamGroupId: '',
20+
filesGroupId: '',
21+
},
22+
public: {
23+
mediaUrl: '',
24+
},
25+
},
26+
compatibilityDate: '2025-02-20',
27+
})

apps/core-telegram/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@roll-stack/core-telegram",
3+
"type": "module",
4+
"version": "0.0.0",
5+
"private": true,
6+
"scripts": {
7+
"build": "nuxt build",
8+
"dev": "nuxt dev --port 3502",
9+
"preview": "PORT=3502 nuxt preview",
10+
"clean": "rm -rf .output",
11+
"clean:modules": "rm -rf .nuxt node_modules",
12+
"typecheck": "nuxt typecheck",
13+
"postinstall": "nuxt prepare"
14+
},
15+
"dependencies": {
16+
"@roll-stack/database": "workspace:*",
17+
"@roll-stack/queue": "workspace:*",
18+
"@roll-stack/ui": "workspace:*",
19+
"arktype": "catalog:",
20+
"aws4fetch": "catalog:",
21+
"date-fns": "catalog:",
22+
"grammy": "catalog:",
23+
"libphonenumber-js": "catalog:",
24+
"sharp": "catalog:"
25+
},
26+
"devDependencies": {
27+
"@types/node": "catalog:",
28+
"nuxt": "catalog:"
29+
}
30+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { repository } from '@roll-stack/database'
2+
3+
export default defineEventHandler(async () => {
4+
try {
5+
await repository.checkHealth()
6+
7+
return { ok: true }
8+
} catch (error) {
9+
throw errorResolver(error)
10+
}
11+
})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { User } from '@roll-stack/database'
2+
import type { H3Event } from 'h3'
3+
import { repository } from '@roll-stack/database'
4+
5+
const logger = useLogger('middleware:auth')
6+
7+
const routesWithoutAuth = [
8+
'/api/health',
9+
]
10+
11+
/**
12+
* Cover all requests (except the ones without auth)
13+
*/
14+
export default defineEventHandler(async (event) => {
15+
// Skip if preflight
16+
if (event.method === 'OPTIONS') {
17+
return
18+
}
19+
20+
// Skip routes without auth
21+
if (!event.path.startsWith('/api') || routesWithoutAuth.includes(event.path)) {
22+
return
23+
}
24+
25+
const user = await getUserFromToken(event)
26+
27+
// No auth?
28+
if (!user) {
29+
throw createError({
30+
statusCode: 401,
31+
message: 'Unauthorized',
32+
})
33+
}
34+
35+
event.context.user = user
36+
})
37+
38+
async function getUserFromToken(event: H3Event): Promise<User | null> {
39+
try {
40+
const authToken = getHeader(event, 'Authorization') ?? getHeader(event, 'authorization')
41+
if (!authToken) {
42+
return null
43+
}
44+
45+
const [_, token] = authToken.split(' ')
46+
if (!token) {
47+
return null
48+
}
49+
50+
const user = await repository.user.find(token)
51+
if (!user?.id) {
52+
return null
53+
}
54+
55+
return user
56+
} catch (e) {
57+
logger.error(e)
58+
}
59+
60+
return null
61+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import process from 'node:process'
2+
import { useCreateDatabase } from '@roll-stack/database'
3+
4+
/**
5+
* DB init
6+
*/
7+
export default defineNitroPlugin(async () => {
8+
if (!process.env.DATABASE_URL) {
9+
throw new Error('DATABASE_URL is not defined')
10+
}
11+
12+
useCreateDatabase(process.env.DATABASE_URL)
13+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import process from 'node:process'
2+
import { useCreateConnection } from '@roll-stack/queue'
3+
import { setupConsumers } from '../services/queue'
4+
5+
/**
6+
* Queue init
7+
*/
8+
export default defineNitroPlugin(async () => {
9+
if (!process.env.QUEUE_URL) {
10+
throw new Error('QUEUE_URL is not defined')
11+
}
12+
13+
await useCreateConnection(process.env.QUEUE_URL)
14+
15+
await setupConsumers()
16+
})
File renamed without changes.

0 commit comments

Comments
 (0)