Compare commits
314 Commits
v1.1.2
...
dd75c54b32
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd75c54b32 | ||
|
|
f6f9163c3f | ||
|
|
4c166a8d33 | ||
| 284be82e1e | |||
| 41b5cb6fae | |||
| c4664edd7e | |||
| 69eddf47db | |||
| 71f3f353ab | |||
| 0d1dcf21c1 | |||
| 35493a09b5 | |||
| 390d97e6d5 | |||
| eca5cba858 | |||
| 6c190b80fb | |||
| a6065dd95c | |||
| 99127c42e2 | |||
| 599ccd1582 | |||
| 2b5e5564c8 | |||
| 7937be469b | |||
| 9f72d5885e | |||
| f65fd175ca | |||
|
|
d049c29f93 | ||
|
|
351ea75072 | ||
|
|
34163788f3 | ||
|
|
4ef4dd3c1b | ||
|
|
80498a0ff0 | ||
|
|
00386cc135 | ||
|
|
f5faae7907 | ||
|
|
659f9fd684 | ||
|
|
256de78e64 | ||
|
|
1500486cd8 | ||
|
|
63a825f153 | ||
|
|
1383e360a1 | ||
|
|
ca01d1c538 | ||
|
|
a315c8d4ef | ||
|
|
5ac9559b8f | ||
|
|
7b9e7d0a99 | ||
|
|
63b25928ff | ||
|
|
7d3b563759 | ||
|
|
baba20c028 | ||
|
|
87a9b8b02d | ||
|
|
cc41fa73cd | ||
|
|
ba923b9f91 | ||
|
|
cede47157e | ||
|
|
279c4fc86d | ||
|
|
c2f8d6ecee | ||
|
|
b4858efa73 | ||
|
|
6154932d9e | ||
|
|
d4cc85f644 | ||
|
|
82e8b785c4 | ||
|
|
5785e50cc5 | ||
|
|
de101348fc | ||
|
|
f442544912 | ||
|
|
d09dbcb697 | ||
|
|
f25bae1a08 | ||
|
|
800b60fb6d | ||
|
|
36558dfb85 | ||
|
|
c11bcd5d26 | ||
|
|
8450cc2d4d | ||
|
|
b1a9ee1403 | ||
|
|
80b9d9c8c8 | ||
|
|
db6665736a | ||
|
|
81980fa011 | ||
|
|
ac5f3eee96 | ||
|
|
9d87f7479c | ||
|
|
3639524fc7 | ||
|
|
f66114b22f | ||
|
|
8090de8031 | ||
|
|
081d663711 | ||
|
|
4fe16e5aa8 | ||
|
|
1fd5495570 | ||
|
|
9d68ee735a | ||
|
|
076e51c53a | ||
|
|
409a315a25 | ||
|
|
7a3264d43d | ||
|
|
effa320fa8 | ||
|
|
cc2a66367d | ||
|
|
989b5b010e | ||
|
|
f0e7ba94d2 | ||
|
|
3739fc8449 | ||
|
|
a74d191b30 | ||
|
|
a391cc88c9 | ||
|
|
12f8e63390 | ||
|
|
37238a1385 | ||
|
|
48cd044131 | ||
|
|
5665c4bf1e | ||
|
|
ad35d47ff5 | ||
|
|
f13cdd82df | ||
|
|
d6ebe10421 | ||
|
|
6e59e801b0 | ||
|
|
5dafd60299 | ||
|
|
825d7f1dd2 | ||
|
|
a3ea53c2f0 | ||
|
|
f37f34d803 | ||
|
|
bd0b11dc4a | ||
|
|
b36106cc8c | ||
|
|
07d35c4516 | ||
|
|
471cbacb66 | ||
|
|
229b181972 | ||
|
|
72615c7b98 | ||
|
|
45cafbee91 | ||
|
|
580651094f | ||
|
|
0ee92e98b2 | ||
|
|
3d8d9ee171 | ||
|
|
bde67dc7c3 | ||
|
|
a7be793608 | ||
|
|
ca81e19d14 | ||
|
|
7bd82fedce | ||
|
|
1aeb62d490 | ||
|
|
5886270e29 | ||
|
|
8f544d5c99 | ||
|
|
8dd8ec8930 | ||
|
|
3af82f7478 | ||
|
|
39a62818e9 | ||
|
|
24ff712306 | ||
|
|
ec6b30e220 | ||
|
|
548dbfcc9d | ||
|
|
09174abaa4 | ||
|
|
7ecb73ac6e | ||
|
|
8ade320440 | ||
|
|
bffa3fa2a3 | ||
|
|
4cf29c97b9 | ||
|
|
9377771531 | ||
|
|
0a96a87f94 | ||
|
|
5c14212429 | ||
|
|
e49d38657d | ||
|
|
1c7d1fc1ae | ||
|
|
7503d076e8 | ||
|
|
04f70aaa45 | ||
|
|
7b2b7b477f | ||
|
|
da7e25d339 | ||
|
|
b9f6e4d7aa | ||
|
|
396633932b | ||
|
|
46ad6ea9f3 | ||
|
|
1fa09ecac3 | ||
|
|
18b33ae10a | ||
|
|
e4e00184a5 | ||
|
|
9177765e8c | ||
|
|
0c0c62fe1b | ||
|
|
a0c9c5bab1 | ||
|
|
01b6e4ae72 | ||
|
|
2e36ee6e8b | ||
|
|
18cfa427d2 | ||
|
|
904a227adb | ||
|
|
23e532b770 | ||
|
|
f658e1f828 | ||
|
|
0500497fc1 | ||
|
|
ea691536ac | ||
|
|
c251a640b6 | ||
|
|
8031938b2f | ||
|
|
ca4bfdade4 | ||
|
|
b5f6f6d30f | ||
|
|
36107afbc2 | ||
|
|
539b1d2277 | ||
|
|
a9490da5a6 | ||
|
|
845e57d688 | ||
|
|
6835c84cc4 | ||
|
|
337e3ee2bf | ||
|
|
72d298ef2f | ||
|
|
d410164941 | ||
|
|
6b5ae7bce1 | ||
|
|
d80c4efb49 | ||
|
|
ddcf27b022 | ||
|
|
26c53e7455 | ||
|
|
0fbbe33e8a | ||
|
|
687508d26f | ||
|
|
f89729dbeb | ||
|
|
d90fee82d5 | ||
|
|
bde6ab4c7a | ||
|
|
2d0b97be44 | ||
|
|
3c22354130 | ||
|
|
ab555cd70e | ||
|
|
95bcaf3c5e | ||
|
|
48167530fd | ||
|
|
f909d90b6f | ||
|
|
e7d114a9d9 | ||
|
|
b83e0d603c | ||
|
|
7f57b2a4d3 | ||
|
|
c8f7e47181 | ||
|
|
e5d6b7cecd | ||
|
|
8a1868482c | ||
|
|
1bf68cea08 | ||
|
|
110e8300a1 | ||
| f3566361fb | |||
| a63a229b64 | |||
| 8944508308 | |||
| 775f24cffa | |||
|
|
78b72b0edc | ||
|
|
333fe79c8b | ||
|
|
9d10c8501a | ||
|
|
d64ece382a | ||
|
|
f91f821f86 | ||
|
|
b5301f948a | ||
|
|
dd589790c2 | ||
|
|
1fcc5ed70d | ||
|
|
41dbe81001 | ||
|
|
7b685ad99e | ||
| 2f1e1dc040 | |||
|
|
70e8a6877c | ||
|
|
87fd3121f9 | ||
|
|
4f9434163e | ||
|
|
350d452a7b | ||
| 9a0669df13 | |||
|
|
c0883fc2bc | ||
| 566bce4663 | |||
| c828718498 | |||
|
|
69c280b266 | ||
| 6794b01ac8 | |||
| 1cb586f55a | |||
|
|
df21879c0d | ||
|
|
30c9c86c93 | ||
|
|
2925d0f17b | ||
|
|
752dabd015 | ||
|
|
815f11d5bc | ||
| 02eb0e60b7 | |||
| a64ac93935 | |||
| 66a48d1c7e | |||
| 26c66f16b4 | |||
| 02e50bb2f9 | |||
| fadc62c8f0 | |||
| 4759f6f7ee | |||
| 14f2164a82 | |||
| 14ef1f9bad | |||
| dc99318ff0 | |||
| d2fc5f4d5c | |||
| 938bd48fff | |||
| 96f819dc91 | |||
| 25eee8adf5 | |||
| d2b2a29d3d | |||
| 1cf71261d1 | |||
| 88552eb04f | |||
| ab92c99321 | |||
| 02963de893 | |||
| 48550416d9 | |||
| 878c5ffd68 | |||
|
|
6e37fe93f7 | ||
|
|
72a2667549 | ||
|
|
39db7b4d26 | ||
| ff25c0ecb9 | |||
|
|
f1a93bffb5 | ||
| aa231d4f43 | |||
|
|
f254d57db4 | ||
| 106f835934 | |||
| f9b30a4cfd | |||
| 5e4a99529d | |||
| 4d585002d7 | |||
| b073fe3fdf | |||
| 312cc229d8 | |||
| 11b1d670d0 | |||
|
|
522ea36bb9 | ||
|
|
8be391c8e1 | ||
|
|
ea80304c21 | ||
| 771f75ef08 | |||
|
|
edf9b2c82b | ||
|
|
8c3bf8a8ed | ||
| a88d3657bf | |||
|
|
1656ce8690 | ||
|
|
7cdbec53ee | ||
| eee00f0797 | |||
|
|
33845b743d | ||
|
|
059139e213 | ||
|
|
005e7a0ac9 | ||
| 9ee59256a9 | |||
| c2784dcf45 | |||
| 64ed9b8eda | |||
| e9814f36bf | |||
| 0bd883df59 | |||
| 1657b0c5e9 | |||
| a9673b260f | |||
|
|
8ee5ca5528 | ||
| e1e335098e | |||
| 619975d1e0 | |||
| f29bc83d56 | |||
| 61347d1aee | |||
| ac7a99ef15 | |||
| eb3f1f7e3f | |||
| 3e02ea5843 | |||
| d06aeeb246 | |||
| e331f69885 | |||
| 23f1277edb | |||
|
|
801f9ac1e3 | ||
| 16bffcafa6 | |||
| 922909397d | |||
| 233192ba01 | |||
|
|
f72d5220de | ||
|
|
30af0fb1dd | ||
| 854e249100 | |||
| eddad1cc3f | |||
| c96e435344 | |||
| 7358faef1d | |||
|
|
68de877b06 | ||
| c000106ec8 | |||
|
|
da84344a63 | ||
|
|
daf5bf7970 | ||
|
|
4ef941d62f | ||
|
|
16fda2e7ed | ||
| ff15a48414 | |||
| 367c0de6fb | |||
| 3c89d8b9a8 | |||
| bdc8d9a8e0 | |||
|
|
cbbb376fd6 | ||
|
|
faaec7c718 | ||
| 8814c2a64b | |||
| 298a82e0ae | |||
| a86eb0d4ef | |||
| 335179ad26 | |||
| a1d331b5b4 | |||
| 4b77958a92 | |||
| b36ee36e3a | |||
| 48ffee1a78 | |||
| 6e0934e585 | |||
| 846db377ef | |||
|
|
3e8a8997b9 | ||
|
|
04bce4b90f | ||
|
|
3d935af6f1 |
9
.env.example
Normal file
9
.env.example
Normal file
@@ -0,0 +1,9 @@
|
||||
# Application settings
|
||||
TZ=Europe/Moscow
|
||||
APP_PORT=8044
|
||||
|
||||
MONGO_INITDB_ROOT_USERNAME=qqq
|
||||
MONGO_INITDB_ROOT_PASSWORD=qqq
|
||||
|
||||
# MongoDB connection string
|
||||
MONGO_ADDR=mongodb://qqq:qqq@127.0.0.1:27018
|
||||
34
Dockerfile
34
Dockerfile
@@ -1,16 +1,38 @@
|
||||
FROM node:20
|
||||
FROM node:22 AS builder
|
||||
|
||||
WORKDIR /usr/src/app/
|
||||
|
||||
# Сначала копируем только файлы, необходимые для установки зависимостей
|
||||
COPY ./package.json /usr/src/app/package.json
|
||||
COPY ./package-lock.json /usr/src/app/package-lock.json
|
||||
|
||||
# Устанавливаем все зависимости
|
||||
RUN npm ci
|
||||
|
||||
# Затем копируем исходный код проекта и файлы конфигурации
|
||||
COPY ./tsconfig.json /usr/src/app/tsconfig.json
|
||||
COPY ./server /usr/src/app/server
|
||||
|
||||
# Сборка проекта
|
||||
RUN npm run build
|
||||
|
||||
# Вторая стадия - рабочий образ
|
||||
FROM node:22
|
||||
|
||||
RUN mkdir -p /usr/src/app/server/log/
|
||||
WORKDIR /usr/src/app/
|
||||
|
||||
COPY ./server /usr/src/app/server
|
||||
# Копирование только package.json/package-lock.json для продакшн зависимостей
|
||||
COPY ./package.json /usr/src/app/package.json
|
||||
COPY ./package-lock.json /usr/src/app/package-lock.json
|
||||
COPY ./.serverrc.js /usr/src/app/.serverrc.js
|
||||
# COPY ./.env /usr/src/app/.env
|
||||
|
||||
# RUN npm i --omit=dev
|
||||
RUN npm ci
|
||||
# Установка только продакшн зависимостей
|
||||
RUN npm ci --production
|
||||
|
||||
# Копирование собранного приложения из билдера
|
||||
COPY --from=builder /usr/src/app/dist /usr/src/app/dist
|
||||
COPY --from=builder /usr/src/app/server /usr/src/app/server
|
||||
|
||||
EXPOSE 8044
|
||||
|
||||
CMD ["npm", "run", "up:prod"]
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
docker stop ms-mongo
|
||||
docker volume remove ms_volume
|
||||
docker volume create ms_volume
|
||||
docker run --rm -v ms_volume:/data/db --name ms-mongo -p 27017:27017 -d mongo:8.0.3
|
||||
docker volume remove ms_volume8
|
||||
docker volume create ms_volume8
|
||||
docker run --rm \
|
||||
-v ms_volume8:/data/db \
|
||||
--name ms-mongo \
|
||||
-p 27018:27017 \
|
||||
-e MONGO_INITDB_ROOT_USERNAME=qqq \
|
||||
-e MONGO_INITDB_ROOT_PASSWORD=qqq \
|
||||
-d mongo:8.0.3
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
volumes:
|
||||
ms_volume8:
|
||||
ms_logs:
|
||||
|
||||
services:
|
||||
mongoDb:
|
||||
image: mongo:8.0.3
|
||||
volumes:
|
||||
- ms_volume8:/data/db
|
||||
restart: always
|
||||
# ports:
|
||||
# - 27017:27017
|
||||
multy-stubs:
|
||||
# build: .
|
||||
image: bro.js/ms/bh:$TAG
|
||||
restart: always
|
||||
volumes:
|
||||
- ms_logs:/usr/src/app/server/log
|
||||
ports:
|
||||
- 8044:8044
|
||||
environment:
|
||||
- TZ=Europe/Moscow
|
||||
- MONGO_ADDR=mongodb
|
||||
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
version: "3"
|
||||
|
||||
volumes:
|
||||
ms_volume8:
|
||||
ms_logs:
|
||||
|
||||
services:
|
||||
multy-stubs:
|
||||
image: bro.js/ms/bh:$TAG
|
||||
restart: always
|
||||
volumes:
|
||||
- ms_logs:/usr/src/app/server/log
|
||||
ports:
|
||||
- 8044:8044
|
||||
environment:
|
||||
- TZ=Europe/Moscow
|
||||
- MONGO_ADDR=${MONGO_ADDR}
|
||||
# depends_on:
|
||||
# mongoDb:
|
||||
# condition: service_started
|
||||
# mongoDb:
|
||||
# image: mongo:8.0.3
|
||||
# volumes:
|
||||
# - ms_volume8:/data/db
|
||||
# restart: always
|
||||
# environment:
|
||||
# - MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
|
||||
# ports:
|
||||
# - 27018:27017
|
||||
@@ -4,7 +4,7 @@ import pluginJs from "@eslint/js";
|
||||
|
||||
export default [
|
||||
{ ignores: ['server/routers/old/*'] },
|
||||
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
|
||||
{ files: ["**/*.js"], languageOptions: { } },
|
||||
{ languageOptions: { globals: globals.node } },
|
||||
pluginJs.configs.recommended,
|
||||
{
|
||||
|
||||
4841
package-lock.json
generated
4841
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@@ -1,15 +1,13 @@
|
||||
{
|
||||
"name": "multi-stub",
|
||||
"version": "1.1.2",
|
||||
"version": "2.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "server/index.ts",
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
"start": "cross-env PORT=8033 npx nodemon ./server",
|
||||
"up:prod": "cross-env NODE_ENV=\"production\" node ./server",
|
||||
"deploy:d:stop": "docker compose down",
|
||||
"deploy:d:build": "docker compose build",
|
||||
"deploy:d:up": "docker compose up -d",
|
||||
"redeploy": "npm run deploy:d:stop && npm run deploy:d:build && npm run deploy:d:up",
|
||||
"start": "cross-env NODE_ENV=\"development\" ts-node-dev .",
|
||||
"build": "tsc",
|
||||
"up:prod": "node dist/server/index.js",
|
||||
"eslint": "npx eslint ./server",
|
||||
"eslint:fix": "npx eslint ./server --fix",
|
||||
"test": "jest"
|
||||
@@ -23,25 +21,36 @@
|
||||
"license": "MIT",
|
||||
"homepage": "https://bitbucket.org/online-mentor/multi-stub#readme",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"bcrypt": "^5.1.1",
|
||||
"body-parser": "^1.20.3",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"@langchain/community": "^0.3.56",
|
||||
"@langchain/core": "^0.3.77",
|
||||
"@langchain/langgraph": "^0.4.9",
|
||||
"ai": "^4.1.13",
|
||||
"axios": "^1.7.7",
|
||||
"bcrypt": "^5.1.0",
|
||||
"bcryptjs": "^3.0.3",
|
||||
"body-parser": "^1.19.0",
|
||||
"cookie-parser": "^1.4.5",
|
||||
"cors": "^2.8.5",
|
||||
"cross-env": "^7.0.3",
|
||||
"crypto-js": "^4.2.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"express": "5.0.1",
|
||||
"express-jwt": "^8.5.1",
|
||||
"express-session": "^1.18.1",
|
||||
"gigachat": "^0.0.16",
|
||||
"jsdom": "^25.0.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"mongodb": "^6.12.0",
|
||||
"mongoose": "^8.9.2",
|
||||
"morgan": "^1.10.0",
|
||||
"langchain": "^0.3.34",
|
||||
"langchain-gigachat": "^0.0.14",
|
||||
"mongodb": "^6.20.0",
|
||||
"mongoose": "^8.18.2",
|
||||
"mongoose-sequence": "^6.0.1",
|
||||
"morgan": "^1.10.1",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"pbkdf2-password": "^1.2.1",
|
||||
"rotating-file-stream": "^3.2.5",
|
||||
"socket.io": "^4.8.1",
|
||||
"uuid": "^11.0.3"
|
||||
"zod": "^3.24.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.17.0",
|
||||
@@ -51,6 +60,8 @@
|
||||
"jest": "^29.7.0",
|
||||
"mockingoose": "^2.16.2",
|
||||
"nodemon": "3.1.9",
|
||||
"supertest": "^7.0.0"
|
||||
"supertest": "^7.0.0",
|
||||
"ts-node-dev": "2.0.0",
|
||||
"typescript": "5.7.3"
|
||||
}
|
||||
}
|
||||
|
||||
87
rules.md
Normal file
87
rules.md
Normal file
@@ -0,0 +1,87 @@
|
||||
## Правила оформления студенческих бэкендов в `multi-stub`
|
||||
|
||||
Этот документ описывает, как подключать новый студенческий бэкенд к общему серверу и как работать с JSON‑заглушками. Правила написаны так, чтобы их мог автоматически выполнять помощник Cursor.
|
||||
|
||||
### 1. Общая структура проекта студента
|
||||
|
||||
- **Размещение проекта**
|
||||
- Каждый студенческий бэкенд живёт в своей подпапке в `server/routers/<project-name>`.
|
||||
- В корне подпапки должен быть основной файл роутера `index.js` (или `index.ts`), который экспортирует `express.Router()`.
|
||||
- Подключение к общему серверу выполняется в `server/index.ts` через импорт и `app.use(<mountPath>, <router>)`.
|
||||
|
||||
- **Использование JSON‑заглушек**
|
||||
- Если проект переносится из фронтенд‑репозитория и должен только отдавать данные, то в подпапке проекта должна быть папка `json/` со всеми нужными `.json` файлами.
|
||||
- HTTP‑обработчики в роутере могут просто читать и возвращать содержимое этих файлов (например, через `require('./json/...')` или `import data from './json/...json'` с включённым `resolveJsonModule` / соответствующей конфигурацией bundler'а).
|
||||
|
||||
### 2. Правила для Cursor при указании директории заглушек
|
||||
|
||||
Когда пользователь явно указывает директорию с заглушками (например: `server/routers/<project-name>/json`), помощник Cursor должен последовательно выполнить следующие шаги.
|
||||
|
||||
- **2.1. Проверка валидности импортов JSON‑файлов**
|
||||
- Найти все `.js` / `.ts` файлы внутри подпапки проекта.
|
||||
- В каждом таком файле найти импорты/require, которые ссылаются на `.json` файлы (относительные пути вроде `'./json/.../file.json'`).
|
||||
- Для каждого такого импорта:
|
||||
- **Проверить, что файл реально существует** по указанному пути относительно файла-импортёра.
|
||||
- **Проверить расширение**: путь должен заканчиваться на `.json` (без опечаток).
|
||||
- **Проверить регистр и точное совпадение имени файла** (важно для кросс‑платформенности, даже если локально используется Windows).
|
||||
- Если найдены ошибки (файл не существует, опечатка в имени, неправильный относительный путь и т.п.):
|
||||
- Сформировать понятный список проблем: в каком файле, какая строка/импорт и что именно не так.
|
||||
- Предложить автоматически исправить пути (если по контексту можно однозначно угадать нужный `*.json` файл).
|
||||
|
||||
- **2.2. Проверка подключения основного роутера проекта**
|
||||
- Определить основной файл роутера проекта:
|
||||
- По умолчанию это `server/routers/<project-name>/index.js` (или `index.ts`).
|
||||
- Открыть `server/index.ts` и убедиться, что:
|
||||
- Есть импорт роутера из соответствующей подпапки, например:
|
||||
- `import <SomeUniqueName>Router from './routers/<project-name>'`
|
||||
- или `const <SomeUniqueName>Router = require('./routers/<project-name>')`
|
||||
- Имя переменной роутера **уникально** среди всех импортов роутеров (нет другого импорта с таким же именем).
|
||||
- Есть вызов `app.use('<mount-path>', <SomeUniqueName>Router)`:
|
||||
- `<mount-path>` должен быть осмысленным, совпадать с названием проекта или оговариваться пользователем.
|
||||
- Если импорт или `app.use` отсутствуют:
|
||||
- Сформировать предложение по добавлению корректного импорта и `app.use(...)`.
|
||||
- Убедиться, что используемое имя роутера не конфликтует с уже существующими.
|
||||
- Если обнаружен конфликт имён:
|
||||
- Предложить переименовать новый роутер в уникальное имя и обновить соответствующие места в `server/index.ts`.
|
||||
|
||||
### 3. Предложение «оживить» JSON‑заглушки
|
||||
|
||||
После того как проверка импортов и подключения роутера завершена, помощник Cursor должен **задать пользователю вопрос**, не хочет ли он превратить заглушки в полноценный бэкенд.
|
||||
|
||||
- **3.1. Формулировка предложения**
|
||||
- Спросить у пользователя примерно так:
|
||||
- «Обнаружены JSON‑заглушки в директории `<указанная-папка>`. Хотите, чтобы я попытался автоматически:
|
||||
1) построить модели данных (mongoose‑схемы) на основе структуры JSON;
|
||||
2) создать CRUD‑эндпоинты и/или более сложные маршруты, опираясь на существующие данные;
|
||||
3) заменить прямую отдачу `*.json` файлов на работу через базу данных?»
|
||||
|
||||
- **3.2. Поведение при согласии пользователя**
|
||||
- Проанализировать структуру JSON‑файлов:
|
||||
- Определить основные сущности и поля.
|
||||
- Выделить типы полей (строки, числа, даты, массивы, вложенные объекты и т.п.).
|
||||
- На основе анализа предложить:
|
||||
- Набор `mongoose`‑схем (`models`) с аккуратной сериализацией (виртуальное поле `id`, скрытие `_id` и `__v`).
|
||||
- Набор маршрутов `express` для работы с этими моделями (минимум: чтение списков и элементов; по возможности — создание/обновление/удаление).
|
||||
- Перед внесением изменений:
|
||||
- Показать пользователю краткий план того, какие файлы будут созданы/изменены.
|
||||
- Выполнить изменения только после явного подтверждения пользователя.
|
||||
|
||||
### 4. Минимальные требования к новому студенческому бэкенду
|
||||
|
||||
- **Обязательные элементы**
|
||||
- Подпапка в `server/routers/<project-name>`.
|
||||
- Основной роутер `index.js` / `index.ts`, экспортирующий `express.Router()`.
|
||||
- Подключение к общему серверу в `server/index.ts` (импорт + `app.use()` с уникальным именем роутера).
|
||||
|
||||
- **Если используются JSON‑заглушки**
|
||||
- Папка `json/` внутри проекта.
|
||||
- Все пути в импортирующих файлах должны указывать на реально существующие `*.json` файлы.
|
||||
- Не должно быть «магических» абсолютных путей; только относительные пути от файла до нужного JSON.
|
||||
|
||||
- **Если проект «оживлён»**
|
||||
- Папка `model/` с моделью(ями) данных (например, через `mongoose`).
|
||||
- Роуты, которые вместо прямой отдачи файлов работают с моделями и, при необходимости, с внешними сервисами.
|
||||
|
||||
Следуя этим правилам, можно подключать новые студенческие проекты в единый бэкенд, минимизировать типичные ошибки с путями к JSON и упростить автоматическое развитие заглушек до полноценного API.
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
const noToken = 'No authorization token was found'
|
||||
|
||||
module.exports = (err, req, res, next) => {
|
||||
if (err.message === noToken) {
|
||||
res.status(400).send({
|
||||
success: false, error: 'Токен авторизации не найден',
|
||||
})
|
||||
}
|
||||
|
||||
res.status(400).send({
|
||||
success: false, error: err.message || 'Что-то пошло не так',
|
||||
})
|
||||
}
|
||||
28
server/error.ts
Normal file
28
server/error.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { ErrorLog } from './models/ErrorLog'
|
||||
|
||||
const noToken = 'No authorization token was found'
|
||||
|
||||
export const errorHandler = (err, req, res, next) => {
|
||||
// Сохраняем ошибку в базу данных
|
||||
const errorLog = new ErrorLog({
|
||||
message: err.message || 'Неизвестная ошибка',
|
||||
stack: err.stack,
|
||||
path: req.path,
|
||||
method: req.method,
|
||||
query: req.query,
|
||||
body: req.body
|
||||
})
|
||||
|
||||
errorLog.save()
|
||||
.catch(saveErr => console.error('Ошибка при сохранении лога ошибки:', saveErr))
|
||||
|
||||
if (err.message === noToken) {
|
||||
res.status(400).send({
|
||||
success: false, error: 'Токен авторизации не найден',
|
||||
})
|
||||
}
|
||||
|
||||
res.status(400).send({
|
||||
success: false, error: err.message || 'Что-то пошло не так',
|
||||
})
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
const express = require("express")
|
||||
const bodyParser = require("body-parser")
|
||||
const cookieParser = require("cookie-parser")
|
||||
const session = require("express-session")
|
||||
const morgan = require("morgan")
|
||||
const path = require("path")
|
||||
const rfs = require("rotating-file-stream")
|
||||
|
||||
const app = express()
|
||||
require("dotenv").config()
|
||||
exports.app = app
|
||||
|
||||
const accessLogStream = rfs.createStream("access.log", {
|
||||
size: "10M",
|
||||
interval: "1d",
|
||||
compress: "gzip",
|
||||
path: path.join(__dirname, "log"),
|
||||
})
|
||||
|
||||
const errorLogStream = rfs.createStream("error.log", {
|
||||
size: "10M",
|
||||
interval: "1d",
|
||||
compress: "gzip",
|
||||
path: path.join(__dirname, "log"),
|
||||
})
|
||||
|
||||
const config = require("../.serverrc")
|
||||
const { setIo } = require("./io")
|
||||
|
||||
app.use(cookieParser())
|
||||
app.use(
|
||||
morgan("combined", {
|
||||
stream: accessLogStream,
|
||||
skip: function (req, res) {
|
||||
return res.statusCode >= 400
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
// log all requests to access.log
|
||||
app.use(
|
||||
morgan("combined", {
|
||||
stream: errorLogStream,
|
||||
skip: function (req, res) {
|
||||
console.log('statusCode', res.statusCode, res.statusCode <= 400)
|
||||
return res.statusCode < 400
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const server = setIo(app)
|
||||
|
||||
const sess = {
|
||||
secret: "super-secret-key",
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
cookie: {},
|
||||
}
|
||||
if (app.get("env") === "production") {
|
||||
app.set("trust proxy", 1)
|
||||
sess.cookie.secure = true
|
||||
}
|
||||
app.use(session(sess))
|
||||
|
||||
app.use(
|
||||
bodyParser.json({
|
||||
limit: "50mb",
|
||||
})
|
||||
)
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
limit: "50mb",
|
||||
extended: true,
|
||||
})
|
||||
)
|
||||
app.use(require("./root"))
|
||||
|
||||
/**
|
||||
* Добавляйте сюда свои routers.
|
||||
*/
|
||||
app.use("/kfu-m-24-1", require("./routers/kfu-m-24-1"))
|
||||
app.use("/epja-2024-1", require("./routers/epja-2024-1"))
|
||||
app.use("/v1/todo", require("./routers/todo"))
|
||||
app.use("/dogsitters-finder", require("./routers/dogsitters-finder"))
|
||||
app.use("/kazan-explore", require("./routers/kazan-explore"))
|
||||
app.use("/edateam", require("./routers/edateam-legacy"))
|
||||
app.use("/dry-wash", require("./routers/dry-wash"))
|
||||
app.use("/freetracker", require("./routers/freetracker"))
|
||||
app.use("/dhs-testing", require("./routers/dhs-testing"))
|
||||
app.use("/gamehub", require("./routers/gamehub"))
|
||||
|
||||
|
||||
app.use(require("./error"))
|
||||
|
||||
server.listen(config.port, () =>
|
||||
console.log(`Listening on http://localhost:${config.port}`)
|
||||
)
|
||||
155
server/index.ts
Normal file
155
server/index.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
import express from 'express'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import session from 'express-session'
|
||||
import morgan from 'morgan'
|
||||
import path from 'path'
|
||||
import 'dotenv/config'
|
||||
|
||||
import root from './server'
|
||||
import { errorHandler } from './error'
|
||||
import kfuM241Router from './routers/kfu-m-24-1'
|
||||
import epja20241Router from './routers/epja-2024-1'
|
||||
import todoRouter from './routers/todo'
|
||||
import dogsittersFinderRouter from './routers/dogsitters-finder'
|
||||
import kazanExploreRouter from './routers/kazan-explore'
|
||||
import edateamRouter from './routers/edateam-legacy'
|
||||
import dryWashRouter from './routers/dry-wash'
|
||||
import freetrackerRouter from './routers/freetracker'
|
||||
import dhsTestingRouter from './routers/dhs-testing'
|
||||
import gamehubRouter from './routers/gamehub'
|
||||
import escRouter from './routers/esc'
|
||||
import connectmeRouter from './routers/connectme'
|
||||
import questioneerRouter from './routers/questioneer'
|
||||
import procurementRouter from './routers/procurement'
|
||||
import smokeTrackerRouter from './routers/smoke-tracker'
|
||||
import { setIo } from './io'
|
||||
|
||||
export const app = express()
|
||||
|
||||
// Динамический импорт rotating-file-stream
|
||||
const initServer = async () => {
|
||||
const rfs = await import('rotating-file-stream')
|
||||
const accessLogStream = rfs.createStream("access.log", {
|
||||
size: "10M",
|
||||
interval: "1d",
|
||||
compress: "gzip",
|
||||
path: path.join(__dirname, "log"),
|
||||
})
|
||||
|
||||
const errorLogStream = rfs.createStream("error.log", {
|
||||
size: "10M",
|
||||
interval: "1d",
|
||||
compress: "gzip",
|
||||
path: path.join(__dirname, "log"),
|
||||
})
|
||||
|
||||
app.use(cookieParser())
|
||||
app.use(
|
||||
morgan("combined", {
|
||||
stream: accessLogStream,
|
||||
skip: function (req, res) {
|
||||
return res.statusCode >= 400
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
// log all requests to access.log
|
||||
app.use(
|
||||
morgan("combined", {
|
||||
stream: errorLogStream,
|
||||
skip: function (req, res) {
|
||||
console.log('statusCode', res.statusCode, res.statusCode <= 400)
|
||||
return res.statusCode < 400
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
console.log('warming up 🔥')
|
||||
|
||||
const sess = {
|
||||
secret: "super-secret-key",
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
cookie: {},
|
||||
}
|
||||
if (app.get("env") !== "development") {
|
||||
app.set("trust proxy", 1)
|
||||
}
|
||||
app.use(session(sess))
|
||||
|
||||
app.use(
|
||||
express.json({
|
||||
limit: "50mb",
|
||||
})
|
||||
)
|
||||
app.use(
|
||||
express.urlencoded({
|
||||
limit: "50mb",
|
||||
extended: true,
|
||||
})
|
||||
)
|
||||
app.use(root)
|
||||
|
||||
|
||||
/**
|
||||
* Добавляйте сюда свои routers.
|
||||
*/
|
||||
app.use("/kfu-m-24-1", kfuM241Router)
|
||||
app.use("/epja-2024-1", epja20241Router)
|
||||
app.use("/v1/todo", todoRouter)
|
||||
app.use("/dogsitters-finder", dogsittersFinderRouter)
|
||||
app.use("/kazan-explore", kazanExploreRouter)
|
||||
app.use("/edateam", edateamRouter)
|
||||
app.use("/dry-wash", dryWashRouter)
|
||||
app.use("/freetracker", freetrackerRouter)
|
||||
app.use("/dhs-testing", dhsTestingRouter)
|
||||
app.use("/gamehub", gamehubRouter)
|
||||
app.use("/esc", escRouter)
|
||||
app.use('/connectme', connectmeRouter)
|
||||
app.use('/questioneer', questioneerRouter)
|
||||
app.use('/procurement', procurementRouter)
|
||||
app.use('/smoke-tracker', smokeTrackerRouter)
|
||||
app.use(errorHandler)
|
||||
|
||||
// Создаем обычный HTTP сервер
|
||||
const server = app.listen(process.env.PORT ?? 8044, () => {
|
||||
console.log(`🚀 Сервер запущен на http://localhost:${process.env.PORT ?? 8044}`)
|
||||
})
|
||||
|
||||
// Обработка сигналов завершения процесса
|
||||
process.on('SIGTERM', () => {
|
||||
console.log('🛑 Получен сигнал SIGTERM. Выполняется корректное завершение...')
|
||||
server.close(() => {
|
||||
console.log('✅ Сервер успешно остановлен')
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('🛑 Получен сигнал SIGINT. Выполняется корректное завершение...')
|
||||
server.close(() => {
|
||||
console.log('✅ Сервер успешно остановлен')
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
|
||||
// Обработка необработанных исключений
|
||||
process.on('uncaughtException', (err) => {
|
||||
console.error('❌ Необработанное исключение:', err)
|
||||
server.close(() => {
|
||||
process.exit(1)
|
||||
})
|
||||
})
|
||||
|
||||
// Обработка необработанных отклонений промисов
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('⚠️ Необработанное отклонение промиса:', reason)
|
||||
server.close(() => {
|
||||
process.exit(1)
|
||||
})
|
||||
})
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
initServer().catch(console.error)
|
||||
13
server/io.js
13
server/io.js
@@ -1,13 +0,0 @@
|
||||
const { Server } = require('socket.io')
|
||||
const { createServer } = require('http')
|
||||
|
||||
let io = null
|
||||
|
||||
module.exports.setIo = (app) => {
|
||||
const server = createServer(app)
|
||||
io = new Server(server, {})
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
module.exports.getIo = () => io
|
||||
13
server/io.ts
Normal file
13
server/io.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { createServer } from 'http'
|
||||
|
||||
let io = null
|
||||
|
||||
export const setIo = (app) => {
|
||||
const server = createServer(app)
|
||||
io = new Server(server, {})
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
export const getIo = () => io
|
||||
16
server/models/ErrorLog.ts
Normal file
16
server/models/ErrorLog.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
const ErrorLogSchema = new mongoose.Schema({
|
||||
message: { type: String, required: true },
|
||||
stack: { type: String },
|
||||
path: { type: String },
|
||||
method: { type: String },
|
||||
query: { type: Object },
|
||||
body: { type: Object },
|
||||
createdAt: { type: Date, default: Date.now },
|
||||
})
|
||||
|
||||
// Индекс для быстрого поиска по дате создания
|
||||
ErrorLogSchema.index({ createdAt: 1 })
|
||||
|
||||
export const ErrorLog = mongoose.model('ErrorLog', ErrorLogSchema)
|
||||
55
server/models/questionnaire.ts
Normal file
55
server/models/questionnaire.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
// Типы вопросов
|
||||
export const QUESTION_TYPES = {
|
||||
SINGLE_CHOICE: 'single_choice', // Один вариант
|
||||
MULTIPLE_CHOICE: 'multiple_choice', // Несколько вариантов
|
||||
TEXT: 'text', // Текстовый ответ
|
||||
RATING: 'rating', // Оценка по шкале
|
||||
TAG_CLOUD: 'tag_cloud' // Облако тегов
|
||||
};
|
||||
|
||||
// Типы отображения
|
||||
export const DISPLAY_TYPES = {
|
||||
DEFAULT: 'default',
|
||||
TAG_CLOUD: 'tag_cloud',
|
||||
VOTING: 'voting',
|
||||
POLL: 'poll'
|
||||
};
|
||||
|
||||
// Схема варианта ответа
|
||||
const optionSchema = new mongoose.Schema({
|
||||
text: { type: String, required: true },
|
||||
count: { type: Number, default: 0 } // счетчик голосов
|
||||
});
|
||||
|
||||
// Схема вопроса
|
||||
const questionSchema = new mongoose.Schema({
|
||||
text: { type: String, required: true },
|
||||
type: {
|
||||
type: String,
|
||||
enum: Object.values(QUESTION_TYPES),
|
||||
required: true
|
||||
},
|
||||
options: [optionSchema],
|
||||
required: { type: Boolean, default: false }
|
||||
});
|
||||
|
||||
// Схема опроса
|
||||
const questionnaireSchema = new mongoose.Schema({
|
||||
title: { type: String, required: true },
|
||||
description: { type: String },
|
||||
questions: [questionSchema],
|
||||
displayType: {
|
||||
type: String,
|
||||
enum: Object.values(DISPLAY_TYPES),
|
||||
default: DISPLAY_TYPES.DEFAULT
|
||||
},
|
||||
createdAt: { type: Date, default: Date.now },
|
||||
updatedAt: { type: Date, default: Date.now },
|
||||
adminLink: { type: String, required: true }, // ссылка для редактирования
|
||||
publicLink: { type: String, required: true } // ссылка для голосования
|
||||
});
|
||||
|
||||
export const Questionnaire = mongoose.model('Questionnaire', questionnaireSchema);
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const router = require('express').Router()
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const pkg = require('../package.json')
|
||||
|
||||
require('./utils/mongoose')
|
||||
const folderPath = path.resolve(__dirname, './routers')
|
||||
const folders = fs.readdirSync(folderPath)
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
// throw new Error('check error message')
|
||||
res.send(`
|
||||
<h1>multy stub is working v${pkg.version}</h1>
|
||||
<ul>
|
||||
${folders.map((f) => `<li>${f}</li>`).join('')}
|
||||
</ul>
|
||||
|
||||
<h2>models</h2>
|
||||
<ul>${
|
||||
(await Promise.all(
|
||||
(await mongoose.modelNames()).map(async (name) => {
|
||||
const count = await mongoose.model(name).countDocuments()
|
||||
return `<li>${name} - ${count}</li>`
|
||||
}
|
||||
)
|
||||
)).map(t => t).join(' ')
|
||||
}</ul>
|
||||
`)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
8
server/routers/connectme/index.js
Normal file
8
server/routers/connectme/index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const { Router } = require('express')
|
||||
const router = Router()
|
||||
|
||||
router.get('/cities', (request, response) => {
|
||||
response.send(require('./json/cities.json'))
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
85
server/routers/connectme/json/cities.json
Normal file
85
server/routers/connectme/json/cities.json
Normal file
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Моска"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Санкт-петербург"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Новосибирска"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Екатеринбург"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Казань"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Нижний новгород"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Челябинск"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"title": "Самара"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"title": "Омск"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"title": "Ростов-на-дону"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"title": "Уфа"
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"title": "Красноярск"
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"title": "Пермь"
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"title": "Воронеж"
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"title": "Волгоград"
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"title": "Краснодар"
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"title": "Тюмень"
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"title": "Ижевск"
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"title": "Барнаул"
|
||||
},
|
||||
{
|
||||
"id": 20,
|
||||
"title": "Владивосток"
|
||||
}
|
||||
],
|
||||
"count": 20
|
||||
}
|
||||
2
server/routers/dogsitters-finder/const.js
Normal file
2
server/routers/dogsitters-finder/const.js
Normal file
@@ -0,0 +1,2 @@
|
||||
exports.DSF_AUTH_USER_MODEL_NAME = 'DSF_AUTH_USER'
|
||||
exports.DSF_INTERACTION_MODEL_NAME = 'DSF_INTERACTION'
|
||||
@@ -7,29 +7,29 @@ router.get("/users", (request, response) => {
|
||||
router.post("/auth", (request, response) => {
|
||||
const { phoneNumber, password } = request.body;
|
||||
console.log(phoneNumber, password);
|
||||
if (phoneNumber === "89999999999") {
|
||||
response.send(require("./json/auth/dogsitter.success.json"));
|
||||
} else if (phoneNumber === "89555555555") {
|
||||
response.status(400).send(require("./json/auth/error.json"));
|
||||
if (phoneNumber === "89999999999" || phoneNumber === "89559999999") {
|
||||
response.send(require("./json/auth/success.json"));
|
||||
} else {
|
||||
response.send(require("./json/auth/owner.success.json"));
|
||||
response.status(401).send(require("./json/auth/error.json"));
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/auth/2fa", (request, response) => {
|
||||
const { code } = request.body;
|
||||
if (code === "0000") {
|
||||
response.send(require("./json/2fa/success.json"));
|
||||
const { phoneNumber, code } = request.body;
|
||||
if (code === "0000" && phoneNumber === "89999999999") {
|
||||
response.send(require("./json/2fa/dogsitter.success.json"));
|
||||
} else if (code === "0000" && phoneNumber === "89559999999") {
|
||||
response.send(require("./json/2fa/owner.success.json"));
|
||||
} else {
|
||||
response.status(400).send(require("./json/2fa/error.json"));
|
||||
response.status(401).send(require("./json/2fa/error.json"));
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/register", (request, response) => {
|
||||
const { firstName, secondName, phoneNumber, password, role } = request.body;
|
||||
console.log(phoneNumber, password, role);
|
||||
if (phoneNumber === "89283244141" || phoneNumber === "89872855893") {
|
||||
response.status(400).send(require("./json/register/error.json"));
|
||||
if (phoneNumber === "89999999999" || phoneNumber === "89559999999") {
|
||||
response.status(401).send(require("./json/register/error.json"));
|
||||
} else if (role === "dogsitter") {
|
||||
response.send(require("./json/register/dogsitter.success.json"));
|
||||
} else {
|
||||
@@ -37,4 +37,192 @@ router.post("/register", (request, response) => {
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
router.get("/auth/session", (request, response) => {
|
||||
const authHeader = request.headers.authorization;
|
||||
|
||||
if (!authHeader) {
|
||||
return response.status(401).json({ error: "Authorization header missing" });
|
||||
}
|
||||
|
||||
// Берём сам токен из заголовка
|
||||
const token = authHeader.split(" ")[1];
|
||||
|
||||
if (!token) {
|
||||
return response.status(401).json({ error: "Bearer token missing" });
|
||||
}
|
||||
|
||||
const jwt = require("jsonwebtoken");
|
||||
const secretKey = "secret";
|
||||
|
||||
try {
|
||||
const decoded = jwt.verify(token, secretKey);
|
||||
|
||||
if (decoded.role === "dogsitter") {
|
||||
response.send(require("./json/role/dogsitter.success.json"));
|
||||
} else {
|
||||
response.send(require("./json/role/owner.success.json"));
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("token e:", e);
|
||||
return response.status(403).json({ error: "Invalid token" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Проверка взаимодействия между пользователем и догситтером
|
||||
router.get("/interactions/check", (req, res) => {
|
||||
const { owner_id, dogsitter_id } = req.query;
|
||||
|
||||
const usersFilePath = path.resolve(__dirname, "./json/users/users.json");
|
||||
|
||||
delete require.cache[require.resolve(usersFilePath)];
|
||||
const usersFile = require(usersFilePath);
|
||||
|
||||
const interactions = usersFile.interactions || [];
|
||||
|
||||
const exists = interactions.some(
|
||||
(interaction) =>
|
||||
interaction.owner_id === Number(owner_id) &&
|
||||
interaction.dogsitter_id === Number(dogsitter_id)
|
||||
);
|
||||
|
||||
res.json({ exists });
|
||||
});
|
||||
|
||||
// Добавление нового взаимодействия
|
||||
router.post("/interactions", (req, res) => {
|
||||
const { owner_id, dogsitter_id, interaction_type } = req.body;
|
||||
|
||||
if (!owner_id || !dogsitter_id || !interaction_type) {
|
||||
return res.status(400).json({ error: "Missing required fields" });
|
||||
}
|
||||
|
||||
const usersFilePath = path.resolve(__dirname, "./json/users/users.json");
|
||||
|
||||
delete require.cache[require.resolve(usersFilePath)];
|
||||
const usersFile = require(usersFilePath);
|
||||
|
||||
if (!usersFile.interactions) {
|
||||
usersFile.interactions = [];
|
||||
}
|
||||
|
||||
// Проверяем, существует ли уже такое взаимодействие
|
||||
const exists = usersFile.interactions.some(
|
||||
(interaction) =>
|
||||
interaction.owner_id === Number(owner_id) &&
|
||||
interaction.dogsitter_id === Number(dogsitter_id)
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
usersFile.interactions.push({
|
||||
owner_id: Number(owner_id),
|
||||
dogsitter_id: Number(dogsitter_id),
|
||||
interaction_type,
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
usersFilePath,
|
||||
JSON.stringify(usersFile, null, 2),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
console.log(
|
||||
`Добавлено взаимодействие: owner_id=${owner_id}, dogsitter_id=${dogsitter_id}`
|
||||
);
|
||||
}
|
||||
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
router.get("/dogsitter-viewing", (req, res) => {
|
||||
const { id } = req.query;
|
||||
console.log(`Получен запрос для dogsitter с ID: ${id}`);
|
||||
|
||||
const usersFile = require("./json/users/users.json");
|
||||
const users = usersFile.data; // Извлекаем массив из свойства "data"
|
||||
|
||||
const user = users.find((user) => user.id === Number(id));
|
||||
|
||||
if (user) {
|
||||
res.json(user); // Возвращаем найденного пользователя
|
||||
} else {
|
||||
res.status(404).json({ error: "User not found" }); // Если пользователь не найден
|
||||
}
|
||||
});
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
|
||||
router.post('/dogsitter-viewing/rating/:id', (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { rating } = req.body;
|
||||
|
||||
if (!rating || rating < 1 || rating > 5) {
|
||||
return res.status(400).json({ error: 'Некорректная оценка' });
|
||||
}
|
||||
|
||||
const usersFilePath = path.resolve(__dirname, "./json/users/users.json");
|
||||
|
||||
delete require.cache[require.resolve(usersFilePath)];
|
||||
const usersFile = require(usersFilePath);
|
||||
const users = usersFile.data;
|
||||
|
||||
const userIndex = users.findIndex(user => user.id === Number(id));
|
||||
if (userIndex === -1) {
|
||||
return res.status(404).json({ error: 'Догситтер не найден' });
|
||||
}
|
||||
|
||||
if (!users[userIndex].ratings) {
|
||||
users[userIndex].ratings = [];
|
||||
}
|
||||
users[userIndex].ratings.push(rating);
|
||||
|
||||
if (users[userIndex].ratings.length > 100) {
|
||||
users[userIndex].ratings.shift();
|
||||
}
|
||||
|
||||
const total = users[userIndex].ratings.reduce((sum, r) => sum + r, 0);
|
||||
users[userIndex].rating = parseFloat((total / users[userIndex].ratings.length).toFixed(2));
|
||||
|
||||
fs.writeFileSync(usersFilePath, JSON.stringify({ data: users }, null, 2), 'utf8');
|
||||
|
||||
console.log(`Обновлен рейтинг догситтера ${id}: ${users[userIndex].rating}`);
|
||||
|
||||
res.json({ rating: users[userIndex].rating, ratings: users[userIndex].ratings });
|
||||
});
|
||||
|
||||
|
||||
router.patch('/users/:id', (req, res) => {
|
||||
const { id } = req.params;
|
||||
const updateData = req.body;
|
||||
|
||||
console.log('Полученные данные для обновления:', updateData);
|
||||
|
||||
|
||||
const usersFilePath = path.resolve(__dirname, "./json/users/users.json");
|
||||
|
||||
delete require.cache[require.resolve(usersFilePath)];
|
||||
const usersFile = require(usersFilePath);
|
||||
const users = usersFile.data;
|
||||
|
||||
const userIndex = users.findIndex((user) => user.id === Number(id));
|
||||
if (userIndex === -1) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
|
||||
users[userIndex] = { ...users[userIndex], ...updateData };
|
||||
|
||||
fs.writeFileSync(
|
||||
usersFilePath,
|
||||
JSON.stringify({ data: users }, null, 2),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
console.log('Обновлённые данные пользователя:', users[userIndex]);
|
||||
|
||||
res.json(users[userIndex]);
|
||||
});
|
||||
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwicm9sZSI6ImRvZ3NpdHRlciIsImlhdCI6MTUxNjIzOTAyMn0.7q66wTNyLZp3TGFYF_JdU-yhlWViJulTxP_PCQzO4OI"
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"status": "error",
|
||||
"message": "Invalid code."
|
||||
"message": "Invalid code",
|
||||
"statusCode": 401
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Mywicm9sZSI6Im93bmVyIiwiaWF0IjoxNTE2MjM5MDIyfQ.sI9839YXveTpEWhdpr5QbCYllt6hHYO7NsrQDcrXZIQ"
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Two-factor authentication passed."
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"data": {
|
||||
"id": 1,
|
||||
"phoneNumber": 89283244141,
|
||||
"firstName": "Вася",
|
||||
"secondName": "Пупкин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Пушкина, 12",
|
||||
"price": 1500,
|
||||
"aboutMe": "Я люблю собак"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
{
|
||||
"error": "Пользователь не найден"
|
||||
"message": "Неверный логин или пароль",
|
||||
"error": "Unauthorized",
|
||||
"statusCode": 401
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"data": {
|
||||
"id": 3,
|
||||
"phoneNumber": 89872855893,
|
||||
"firstName": "Гадий",
|
||||
"secondName": "Петрович",
|
||||
"role": "owner"
|
||||
}
|
||||
}
|
||||
5
server/routers/dogsitters-finder/json/auth/success.json
Normal file
5
server/routers/dogsitters-finder/json/auth/success.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"status": "success",
|
||||
"message": "Первый фактор аутентификации пройден",
|
||||
"statusCode": 200
|
||||
}
|
||||
@@ -1,12 +1,3 @@
|
||||
{
|
||||
"data": {
|
||||
"id": 5,
|
||||
"phoneNumber": 89555555555,
|
||||
"firstName": "Масяня",
|
||||
"secondName": "Карлова",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Пушкина, 12",
|
||||
"price": 100,
|
||||
"aboutMe": "Все на свете - собаки"
|
||||
}
|
||||
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwicm9sZSI6ImRvZ3NpdHRlciIsImlhdCI6MTUxNjIzOTAyMn0.T9V3-f3rD1deA5a2J-tYNw0cACEpzKHbhMPkc7gh8c0"
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
{
|
||||
"error": "Пользователь с таким номером телефона уже существует"
|
||||
"message": "Такой пользователь уже был зарегистрирован",
|
||||
"error": "Unauthorized",
|
||||
"statusCode": 401
|
||||
}
|
||||
@@ -1,9 +1,3 @@
|
||||
{
|
||||
"data": {
|
||||
"id": 6,
|
||||
"phoneNumber": 89888888888,
|
||||
"firstName": "Генадий",
|
||||
"secondName": "Паровозов",
|
||||
"role": "owner"
|
||||
}
|
||||
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Niwicm9sZSI6Im93bmVyIiwiaWF0IjoxNTE2MjM5MDIyfQ.qgOhk9tNcaMRbarRWISTgvGx5Eq_X8fcA5lhdVs2tQI"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"id": 1,
|
||||
"role": "dogsitter"
|
||||
}
|
||||
5
server/routers/dogsitters-finder/json/role/error.json
Normal file
5
server/routers/dogsitters-finder/json/role/error.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"message": "Неверный jwt token",
|
||||
"error": "Forbidden",
|
||||
"statusCode": 403
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"id": 3,
|
||||
"role": "owner"
|
||||
}
|
||||
@@ -1,39 +1,69 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"phone_number": 89283244141,
|
||||
"first_name": "Вася",
|
||||
"second_name": "Пупкин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Пушкина, 12",
|
||||
"price": 1500,
|
||||
"about_me": "Я люблю собак"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"phone_number": 89272844541,
|
||||
"first_name": "Ваня",
|
||||
"second_name": "Пуськин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Абсалямова, 19",
|
||||
"price": 1000000,
|
||||
"about_me": "Я не люблю собак. И вообще я котоман."
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"phone_number": 89872855893,
|
||||
"first_name": "Гадий",
|
||||
"second_name": "Петрович",
|
||||
"role": "owner"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"phone_number": 89872844591,
|
||||
"first_name": "Галкин",
|
||||
"second_name": "Максим",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, проспект Ямашева, 83",
|
||||
"price": 1000000,
|
||||
"about_me": "Миллион алых роз"
|
||||
}
|
||||
]
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"phone_number": "89999999999",
|
||||
"first_name": "Вася",
|
||||
"second_name": "Пупкин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, Пушкина, 12",
|
||||
"price": "1500",
|
||||
"about_me": "Я люблю собак!",
|
||||
"rating": 5,
|
||||
"ratings": [
|
||||
5,
|
||||
5
|
||||
],
|
||||
"tg": "jullllllie"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"phone_number": 89272844541,
|
||||
"first_name": "Ваня",
|
||||
"second_name": "Пуськин",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, улица Абсалямова, 19",
|
||||
"price": 2000,
|
||||
"about_me": "Я не люблю собак. И вообще я котоман.",
|
||||
"rating": 4,
|
||||
"ratings": [
|
||||
4,
|
||||
4
|
||||
],
|
||||
"tg": "vanya006"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"phone_number": 89559999999,
|
||||
"first_name": "Гадий",
|
||||
"second_name": "Петрович",
|
||||
"role": "owner"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"phone_number": 89872844591,
|
||||
"first_name": "Галкин",
|
||||
"second_name": "Максим",
|
||||
"role": "dogsitter",
|
||||
"location": "Россия, республика Татарстан, Казань, проспект Ямашева, 83",
|
||||
"price": 1750,
|
||||
"about_me": "Миллион алых роз",
|
||||
"rating": 4.5,
|
||||
"ratings": [
|
||||
4,
|
||||
5
|
||||
],
|
||||
"tg": "maks100500"
|
||||
}
|
||||
],
|
||||
"interactions": [
|
||||
{
|
||||
"owner_id": 3,
|
||||
"dogsitter_id": 4
|
||||
},
|
||||
{
|
||||
"owner_id": 1,
|
||||
"dogsitter_id": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
24
server/routers/dogsitters-finder/model/interaction.js
Normal file
24
server/routers/dogsitters-finder/model/interaction.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const { Schema, model } = require("mongoose");
|
||||
|
||||
const { DSF_AUTH_USER_MODEL_NAME, DSF_INTERACTION_MODEL_NAME } = require("../../const");
|
||||
|
||||
const interactionSchema = new Schema({
|
||||
owner_id: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: DSF_AUTH_USER_MODEL_NAME,
|
||||
required: true
|
||||
},
|
||||
dogsitter_id: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: DSF_AUTH_USER_MODEL_NAME,
|
||||
required: true
|
||||
},
|
||||
timestamp: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
interactionSchema.index({ owner_id: 1, dogsitter_id: 1 });
|
||||
|
||||
module.exports.Interaction = model(DSF_INTERACTION_MODEL_NAME, interactionSchema);
|
||||
83
server/routers/dogsitters-finder/model/user.js
Normal file
83
server/routers/dogsitters-finder/model/user.js
Normal file
@@ -0,0 +1,83 @@
|
||||
const { Schema, model } = require("mongoose");
|
||||
|
||||
const { DSF_AUTH_USER_MODEL_NAME } = require("../../const");
|
||||
|
||||
const userSchema = new Schema({
|
||||
phone_number: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
match: /^\+?\d{10,15}$/
|
||||
},
|
||||
first_name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
second_name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
role: {
|
||||
type: String,
|
||||
enum: ["dogsitter", "owner"],
|
||||
required: true
|
||||
},
|
||||
location: {
|
||||
type: String,
|
||||
required: function() {
|
||||
return this.role === "dogsitter";
|
||||
}
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
required: function() {
|
||||
return this.role === "dogsitter";
|
||||
}
|
||||
},
|
||||
about_me: {
|
||||
type: String,
|
||||
maxlength: 500
|
||||
},
|
||||
rating: {
|
||||
type: Number,
|
||||
min: 0,
|
||||
max: 5,
|
||||
default: 0
|
||||
},
|
||||
ratings: {
|
||||
type: [Number],
|
||||
default: [],
|
||||
validate: {
|
||||
validator: function(arr) {
|
||||
return arr.every(v => v >= 0 && v <= 5);
|
||||
},
|
||||
message: "Рейтинг должен быть в диапазоне от 0 до 5!"
|
||||
}
|
||||
},
|
||||
tg: {
|
||||
type: String,
|
||||
match: /^[a-zA-Z0-9_]{5,32}$/
|
||||
},
|
||||
created: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
userSchema.virtual("id").get(function() {
|
||||
return this._id.toHexString();
|
||||
});
|
||||
|
||||
userSchema.set("toJSON", {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
transform: function(doc, ret) {
|
||||
delete ret._id;
|
||||
delete ret.__v;
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.User = model(DSF_AUTH_USER_MODEL_NAME, userSchema);
|
||||
149
server/routers/dogsitters-finder/routes.js
Normal file
149
server/routers/dogsitters-finder/routes.js
Normal file
@@ -0,0 +1,149 @@
|
||||
const { Router } = require('express')
|
||||
const { expressjwt } = require('express-jwt')
|
||||
|
||||
const { getAnswer } = require('../../utils/common')
|
||||
const { User, Interaction } = require('./model')
|
||||
const { TOKEN_KEY } = require('./const')
|
||||
const { requiredValidate } = require('./utils')
|
||||
|
||||
const router = Router()
|
||||
|
||||
// Получение списка пользователей
|
||||
router.get('/users', async (req, res) => {
|
||||
|
||||
const users = await User.find()
|
||||
.select('-__v -ratings -phone_number')
|
||||
.lean()
|
||||
|
||||
console.log('get users successfull')
|
||||
|
||||
res.send(getAnswer(null, users))
|
||||
})
|
||||
|
||||
// Получение конкретного пользователя
|
||||
router.get('/dogsitter-viewing', async (req, res) => {
|
||||
const { userId } = req.params
|
||||
|
||||
const user = await User.findById(userId)
|
||||
.select('-__v -ratings')
|
||||
.lean()
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).send(getAnswer(new Error('Пользователь не найден')))
|
||||
}
|
||||
|
||||
res.send(getAnswer(null, user))
|
||||
})
|
||||
|
||||
router.use(expressjwt({ secret: TOKEN_KEY, algorithms: ['HS256'] }))
|
||||
|
||||
// Добавление оценки пользователю
|
||||
router.post('/dogsitter-viewing/rating', requiredValidate('value'), async (req, res) => {
|
||||
const { userId } = req.params
|
||||
const { value } = req.body
|
||||
const authUserId = req.auth.id
|
||||
|
||||
try {
|
||||
const user = await User.findById(userId)
|
||||
if (!user) throw new Error('Пользователь не найден')
|
||||
if (user.role !== 'dogsitter') throw new Error('Нельзя оценивать этого пользователя')
|
||||
if (user.id === authUserId) throw new Error('Нельзя оценивать самого себя')
|
||||
|
||||
user.ratings.push(Number(value))
|
||||
user.rating = user.ratings.reduce((a, b) => a + b, 0) / user.ratings.length
|
||||
|
||||
const updatedUser = await user.save()
|
||||
|
||||
res.send(getAnswer(null, {
|
||||
id: updatedUser.id,
|
||||
rating: updatedUser.rating.toFixed(1),
|
||||
totalRatings: updatedUser.ratings.length
|
||||
}))
|
||||
|
||||
} catch (error) {
|
||||
res.status(400).send(getAnswer(error))
|
||||
}
|
||||
})
|
||||
|
||||
// Обновление информации пользователя
|
||||
router.patch('/users', async (req, res) => {
|
||||
const { userId } = req.params
|
||||
const updates = req.body
|
||||
|
||||
try {
|
||||
const user = await User.findByIdAndUpdate(userId, updates, { new: true })
|
||||
.select('-__v -ratings')
|
||||
|
||||
if (!user) throw new Error('Пользователь не найден')
|
||||
res.send(getAnswer(null, user))
|
||||
|
||||
} catch (error) {
|
||||
res.status(400).send(getAnswer(error))
|
||||
}
|
||||
})
|
||||
|
||||
// Создание объекта взаимодействия
|
||||
router.post('/interactions',
|
||||
expressjwt({ secret: TOKEN_KEY, algorithms: ['HS256'] }),
|
||||
requiredValidate('dogsitter_id'),
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { dogsitter_id } = req.body
|
||||
const owner_id = req.auth.id // ID из JWT токена
|
||||
|
||||
// Проверка существования пользователей
|
||||
const [owner, dogsitter] = await Promise.all([
|
||||
User.findById(owner_id),
|
||||
User.findById(dogsitter_id)
|
||||
])
|
||||
|
||||
if (!owner || owner.role !== 'owner') {
|
||||
throw new Error('Владелец не найден или имеет неверную роль')
|
||||
}
|
||||
|
||||
if (!dogsitter || dogsitter.role !== 'dogsitter') {
|
||||
throw new Error('Догситтер не найден или имеет неверную роль')
|
||||
}
|
||||
|
||||
// Создание взаимодействия
|
||||
const interaction = await Interaction.create({
|
||||
owner_id,
|
||||
dogsitter_id
|
||||
})
|
||||
|
||||
res.send(getAnswer(null, {
|
||||
id: interaction.id,
|
||||
timestamp: interaction.timestamp
|
||||
}))
|
||||
|
||||
} catch (error) {
|
||||
res.status(400).send(getAnswer(error))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
router.get('/interactions/check', async (req, res) => {
|
||||
const { owner_id, dogsitter_id } = req.query;
|
||||
|
||||
if (!owner_id || !dogsitter_id) {
|
||||
return res.status(400).send(getAnswer('Missing owner_id or dogsitter_id'));
|
||||
}
|
||||
|
||||
try {
|
||||
// Поиск взаимодействий по owner_id и dogsitter_id
|
||||
const interactions = await Interaction.find({ owner_id, dogsitter_id })
|
||||
.select('-__v') // Выбираем только нужные поля
|
||||
.lean();
|
||||
|
||||
if (interactions.length === 0) {
|
||||
return res.status(404).send(getAnswer('No interactions found'));
|
||||
}
|
||||
|
||||
res.send(getAnswer(null, interactions));
|
||||
} catch (error) {
|
||||
console.error('Error checking interactions:', error);
|
||||
res.status(500).send(getAnswer('Internal Server Error'));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router
|
||||
@@ -1,87 +1,117 @@
|
||||
const router = require('express').Router()
|
||||
const {MasterModel} = require('./model/master')
|
||||
const mongoose = require("mongoose")
|
||||
const router = require("express").Router();
|
||||
const { MasterModel } = require("./model/master");
|
||||
const mongoose = require("mongoose");
|
||||
const { OrderModel } = require("./model/order");
|
||||
|
||||
router.post("/masters/list", async (req, res, next) => {
|
||||
try {
|
||||
const { startDate, endDate } = req.body;
|
||||
|
||||
router.get('/masters', async (req, res,next) => {
|
||||
try {
|
||||
const master = await MasterModel.find({})
|
||||
res.status(200).send({success: true, body: master})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
|
||||
router.delete('/masters/:id', async (req, res,next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)){
|
||||
throw new Error('ID is required')
|
||||
if (!startDate || !endDate) {
|
||||
throw new Error("Missing startDate or endDate");
|
||||
}
|
||||
|
||||
try {
|
||||
const master = await MasterModel.findByIdAndDelete(id, {
|
||||
new: true,
|
||||
});
|
||||
if (!master) {
|
||||
throw new Error('master not found')
|
||||
}
|
||||
res.status(200).send({success: true, body: master})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
const start = new Date(startDate);
|
||||
const end = new Date(endDate);
|
||||
const masters = await MasterModel.find({});
|
||||
|
||||
const orders = await OrderModel.find({
|
||||
$or: [
|
||||
{ startWashTime: { $lt: end }, endWashTime: { $gt: start } }
|
||||
]
|
||||
});
|
||||
|
||||
router.post('/masters', async (req, res,next) => {
|
||||
|
||||
const {name, phone} = req.body
|
||||
|
||||
if (!name || !phone ){
|
||||
throw new Error('Enter name and phone')
|
||||
}
|
||||
try {
|
||||
const master = await MasterModel.create({name, phone})
|
||||
res.status(200).send({success: true, body: master})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
router.patch('/masters/:id', async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
throw new Error('ID is required')
|
||||
}
|
||||
|
||||
const { name, phone } = req.body;
|
||||
|
||||
if (!name && !phone) {
|
||||
throw new Error('Enter name and phone')
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const updateData = {};
|
||||
if (name) updateData.name = name;
|
||||
if (phone) updateData.phone = phone;
|
||||
|
||||
const master = await MasterModel.findByIdAndUpdate(
|
||||
id,
|
||||
updateData,
|
||||
{ new: true }
|
||||
const mastersWithOrders = masters.map((master) => {
|
||||
const masterOrders = orders.filter((order) => {
|
||||
return (
|
||||
order?.master && order.master.toString() === master._id.toString()
|
||||
);
|
||||
});
|
||||
|
||||
if (!master) {
|
||||
throw new Error('master not found')
|
||||
}
|
||||
const schedule = masterOrders.map((order) => ({
|
||||
id: order._id,
|
||||
startWashTime: order.startWashTime,
|
||||
endWashTime: order.endWashTime,
|
||||
}));
|
||||
|
||||
res.status(200).send({ success: true, body: master });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
return {
|
||||
id: master._id,
|
||||
name: master.name,
|
||||
schedule: schedule,
|
||||
phone: master.phone,
|
||||
};
|
||||
});
|
||||
|
||||
res.status(200).send({ success: true, body: mastersWithOrders });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router
|
||||
router.delete("/masters/:id", async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
throw new Error("ID is required");
|
||||
}
|
||||
|
||||
try {
|
||||
const master = await MasterModel.findByIdAndDelete(id, {
|
||||
new: true,
|
||||
});
|
||||
if (!master) {
|
||||
throw new Error("master not found");
|
||||
}
|
||||
res.status(200).send({ success: true, body: master });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/masters", async (req, res, next) => {
|
||||
const { name, phone } = req.body;
|
||||
|
||||
if (!name || !phone) {
|
||||
throw new Error("Enter name and phone");
|
||||
}
|
||||
try {
|
||||
const master = await MasterModel.create({ name, phone });
|
||||
res.status(200).send({ success: true, body: master });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.patch("/masters/:id", async (req, res, next) => {
|
||||
const { id } = req.params;
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
throw new Error("ID is required");
|
||||
}
|
||||
|
||||
const { name, phone } = req.body;
|
||||
|
||||
if (!name && !phone) {
|
||||
throw new Error("Enter name and phone");
|
||||
}
|
||||
|
||||
try {
|
||||
const updateData = {};
|
||||
if (name) updateData.name = name;
|
||||
if (phone) updateData.phone = phone;
|
||||
|
||||
const master = await MasterModel.findByIdAndUpdate(id, updateData, {
|
||||
new: true,
|
||||
});
|
||||
|
||||
if (!master) {
|
||||
throw new Error("master not found");
|
||||
}
|
||||
|
||||
res.status(200).send({ success: true, body: master });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
23
server/routers/dry-wash/get-token.js
Normal file
23
server/routers/dry-wash/get-token.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const getGigaToken = async () => {
|
||||
const response = await fetch('https://admin.bro-js.ru/api/config/v1/dev')
|
||||
const data = await response.json()
|
||||
return data.features['dry-wash-bh'].GIGA_TOKEN.value
|
||||
}
|
||||
|
||||
const getSystemPrompt = async () => {
|
||||
const response = await fetch('https://admin.bro-js.ru/api/config/v1/dev')
|
||||
const data = await response.json()
|
||||
return data.features['dry-wash-bh'].SYSTEM_PROMPT.value
|
||||
}
|
||||
|
||||
const getGigaChatModel = async () => {
|
||||
const response = await fetch('https://admin.bro-js.ru/api/config/v1/dev')
|
||||
const data = await response.json()
|
||||
return data.features['dry-wash-bh'].GIGA_CHAT_MODEL.value
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getGigaToken,
|
||||
getSystemPrompt,
|
||||
getGigaChatModel
|
||||
}
|
||||
29
server/routers/dry-wash/model/order.car-img.js
Normal file
29
server/routers/dry-wash/model/order.car-img.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
|
||||
const schema = new Schema({
|
||||
image: String,
|
||||
imageRating: String,
|
||||
imageDescription: String,
|
||||
orderId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'dry-wash-order'
|
||||
},
|
||||
created: {
|
||||
type: Date,
|
||||
default: () => new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
transform(_doc, ret) {
|
||||
delete ret._id
|
||||
}
|
||||
})
|
||||
|
||||
schema.virtual('id').get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
|
||||
exports.OrderCarImgModel = model('dry-wash-order-car-image', schema)
|
||||
@@ -1,5 +1,6 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
const { orderStatus } = require('./const')
|
||||
const { OrderNumberModel } = require('./order.number')
|
||||
|
||||
const schema = new Schema({
|
||||
phone: {
|
||||
@@ -14,7 +15,7 @@ const schema = new Schema({
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
carColor: String,
|
||||
carColor: Schema.Types.Mixed,
|
||||
startWashTime: {
|
||||
type: Date,
|
||||
required: true
|
||||
@@ -27,6 +28,10 @@ const schema = new Schema({
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
orderNumber: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -47,6 +52,18 @@ const schema = new Schema({
|
||||
},
|
||||
})
|
||||
|
||||
schema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const counter = await OrderNumberModel.findOneAndUpdate(
|
||||
{ _id: 'orderNumber' },
|
||||
{ $inc: { sequenceValue: 1 } },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
this.orderNumber = counter.sequenceValue.toString()
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
|
||||
14
server/routers/dry-wash/model/order.number.js
Normal file
14
server/routers/dry-wash/model/order.number.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
|
||||
const schema = new Schema({
|
||||
_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
sequenceValue: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
})
|
||||
|
||||
exports.OrderNumberModel = model('dry-wash-order-number', schema)
|
||||
@@ -1,13 +1,23 @@
|
||||
const mongoose = require("mongoose")
|
||||
const router = require('express').Router()
|
||||
const multer = require('multer')
|
||||
const { MasterModel } = require('./model/master')
|
||||
const { OrderModel } = require('./model/order')
|
||||
const { OrderCarImgModel } = require('./model/order.car-img')
|
||||
const { orderStatus } = require('./model/const')
|
||||
const { getGigaToken, getSystemPrompt, getGigaChatModel } = require('./get-token')
|
||||
|
||||
const isValidPhoneNumber = (value) => /^(\+)?\d{9,15}/.test(value)
|
||||
const isValidCarNumber = (value) => /^[авекмнорстух][0-9]{3}[авекмнорстух]{2}[0-9]{2,3}$/i.test(value)
|
||||
const isValidCarBodyType = (value) => typeof value === 'number' && value > 0 && value < 100
|
||||
const isValidCarColor = (value) => value.length < 50 && /^[#a-z0-9а-я-\s,.()]+$/i.test(value)
|
||||
const isValidCarColor = (value) => {
|
||||
if (typeof value === 'number') {
|
||||
return value >= 0 && value <= 7
|
||||
} else if (typeof value === 'string') {
|
||||
return /^[#a-z0-9а-я-\s,.()]+$/i.test(value)
|
||||
}
|
||||
return false
|
||||
}
|
||||
const isValidISODate = (value) => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:.\d{1,3})?Z$/.test(value)
|
||||
|
||||
const latitudeRe = /^(-?[1-8]?\d(?:\.\d{1,18})?|90(?:\.0{1,18})?)$/
|
||||
@@ -26,6 +36,9 @@ const isValidLocation = (value) => {
|
||||
const isValidOrderStatus = (value) => Object.values(orderStatus).includes(value)
|
||||
const isValidOrderNotes = (value) => value.length < 500
|
||||
|
||||
const allowedMimeTypes = ['image/jpeg', 'image/png']
|
||||
const sizeLimitInMegaBytes = 15
|
||||
|
||||
const VALIDATION_MESSAGES = {
|
||||
order: {
|
||||
notFound: 'Order not found'
|
||||
@@ -60,6 +73,13 @@ const VALIDATION_MESSAGES = {
|
||||
carColor: {
|
||||
invalid: 'Invalid car color'
|
||||
},
|
||||
carImg: {
|
||||
required: 'Car image file is required',
|
||||
invalid: {
|
||||
type: `Invalid car image file type. Allowed types: ${allowedMimeTypes}`,
|
||||
size: `Invalid car image file size. Limit is ${sizeLimitInMegaBytes}MB`
|
||||
}
|
||||
},
|
||||
washingBegin: {
|
||||
required: 'Begin time of washing is required',
|
||||
invalid: 'Invalid begin time of washing'
|
||||
@@ -143,17 +163,21 @@ router.post('/create', async (req, res, next) => {
|
||||
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
const { id } = req.params
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await OrderModel.findById(id)
|
||||
|
||||
if (!order) {
|
||||
throw new Error(VALIDATION_MESSAGES.order.notFound)
|
||||
}
|
||||
|
||||
res.status(200).send({ success: true, body: order })
|
||||
const imgProps = await OrderCarImgModel.findOne({ orderId: order.id })
|
||||
|
||||
res.status(200).send({ success: true, body: { ...order.toObject(), ...imgProps?.toObject() } })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
@@ -248,4 +272,191 @@ router.delete('/:id', async (req, res, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
const storage = multer.memoryStorage()
|
||||
const upload = multer({
|
||||
storage: storage,
|
||||
limits: { fileSize: sizeLimitInMegaBytes * 1024 * 1024 },
|
||||
fileFilter: (req, file, cb) => {
|
||||
if (allowedMimeTypes.includes(file.mimetype)) {
|
||||
cb(null, true)
|
||||
} else {
|
||||
cb(new Error(VALIDATION_MESSAGES.carImg.invalid.type), false)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const { v4: uuidv4 } = require("uuid")
|
||||
const axios = require('axios')
|
||||
|
||||
const GIGA_CHAT_OAUTH = 'https://ngw.devices.sberbank.ru:9443/api/v2/oauth'
|
||||
const GIGA_CHAT_API = 'https://gigachat.devices.sberbank.ru/api/v1'
|
||||
|
||||
const getToken = async (req, res) => {
|
||||
const gigaToken = await getGigaToken()
|
||||
|
||||
const rqUID = uuidv4()
|
||||
const body = new URLSearchParams({
|
||||
scope: "GIGACHAT_API_PERS",
|
||||
})
|
||||
|
||||
const response = await fetch(GIGA_CHAT_OAUTH, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Basic ${gigaToken}`,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "application/json",
|
||||
RqUID: rqUID,
|
||||
},
|
||||
body,
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json()
|
||||
console.error("Ошибка запроса: ", errorData)
|
||||
return res.status(response.status).json(errorData)
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
const uploadImage = async (file, accessToken) => {
|
||||
const formData = new FormData()
|
||||
const blob = new Blob([file.buffer], { type: file.mimetype })
|
||||
formData.append('file', blob, file.originalname)
|
||||
formData.append('purpose', 'general')
|
||||
|
||||
const config = {
|
||||
maxBodyLength: Infinity,
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${GIGA_CHAT_API}/files`, formData, config)
|
||||
return response.data.id
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
const COLORS_MAP = ['white', 'black', 'silver', 'gray', 'beige-brown', 'red', 'blue', 'green']
|
||||
|
||||
const getColorName = (colorKey) => {
|
||||
if (typeof colorKey === 'number' && COLORS_MAP[colorKey]) {
|
||||
return COLORS_MAP[colorKey]
|
||||
}
|
||||
return colorKey
|
||||
}
|
||||
|
||||
const analyzeImage = async (fileId, token, imgProps) => {
|
||||
const response = await fetch(`${GIGA_CHAT_API}/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: (await getGigaChatModel()) ?? "GigaChat-Max",
|
||||
stream: false,
|
||||
update_interval: 0,
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: (await getSystemPrompt()) ?? `Ты эксперт по оценке степени загрязнения автомобилей. Твоя задача — анализировать фотографии машин и определять степень их загрязнения.
|
||||
Тебе предоставляют фотографию, где явно выделяется одна машина (например, она расположена в центре и имеет больший размер в кадре по сравнению с остальными).
|
||||
ВАЖНО: Твой ответ ДОЛЖЕН быть СТРОГО в формате JSON и содержать ТОЛЬКО следующие поля:
|
||||
{
|
||||
"value": число от 0 до 10 (целое или с одним знаком после запятой),
|
||||
"description": "текстовое описание на русском языке"
|
||||
}.
|
||||
Правила:
|
||||
1. Поле "value":
|
||||
- Должно быть числом от 0 до 10 (0 = машина абсолютно чистая, 10 = машина максимально грязная) ИЛИ undefined (если не удалось оценить);
|
||||
2. Поле "description":
|
||||
- Должно содержать 2-3 предложения на русском языке;
|
||||
- Обязательно указать конкретные признаки загрязнения;
|
||||
- Объяснить, почему выставлен именно такой балл.
|
||||
- Должно быть связано только с автомобилем.
|
||||
НЕ ДОБАВЛЯЙ никаких дополнительных полей или комментариев вне JSON структуры. НЕ ИСПОЛЬЗУЙ markdown форматирование. ОТВЕТ ДОЛЖЕН БЫТЬ ВАЛИДНЫМ JSON. Если на фотографии нельзя явно выделить одну машину, то ОЦЕНКА ДОЛЖНА ИМЕТЬ ЗНАЧЕНИЕ undefined и в описании должно быть указано, что по фотографии не удалось оценить степень загрязнения автомобиля, при этом НЕ ОПИСЫВАЙ НИЧЕГО ДРУГОГО КРОМЕ АВТОМОБИЛЯ`,
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: `Дай оценку для приложенного файла изображения согласно структуре, ответ должен быть на русском языке. Учти, что владелец указал, что исходный цвет машины: ${getColorName(imgProps.color)}`,
|
||||
attachments: [fileId],
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
console.log(data)
|
||||
|
||||
try {
|
||||
return JSON.parse(data.choices[0].message.content)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return { description: data.choices[0].message.content }
|
||||
}
|
||||
}
|
||||
|
||||
const convertFileToBase64 = (file) => {
|
||||
const base64Image = file.buffer.toString('base64')
|
||||
return `data:${file.mimetype};base64,${base64Image}`
|
||||
}
|
||||
|
||||
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"
|
||||
|
||||
router.post('/:id/upload-car-img', upload.single('file'), async (req, res) => {
|
||||
const { id: orderId } = req.params
|
||||
if (!mongoose.Types.ObjectId.isValid(orderId)) {
|
||||
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
||||
}
|
||||
const order = await OrderModel.findById(orderId)
|
||||
if (!order) {
|
||||
throw new Error(VALIDATION_MESSAGES.order.notFound)
|
||||
}
|
||||
|
||||
if (!req.file) {
|
||||
throw new Error(VALIDATION_MESSAGES.carImg.required)
|
||||
}
|
||||
|
||||
try {
|
||||
await OrderCarImgModel.deleteMany({ orderId })
|
||||
|
||||
const { access_token } = await getToken(req, res)
|
||||
|
||||
const fileId = await uploadImage(req.file, access_token)
|
||||
const { value, description } = await analyzeImage(fileId, access_token, { carColor: order.carColor }) ?? {}
|
||||
|
||||
const orderCarImg = await OrderCarImgModel.create({
|
||||
image: convertFileToBase64(req.file),
|
||||
imageRating: value,
|
||||
imageDescription: description,
|
||||
orderId: order.id,
|
||||
created: new Date().toISOString(),
|
||||
})
|
||||
|
||||
res.status(200).send({ success: true, body: orderCarImg })
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
|
||||
router.use((err, req, res, next) => {
|
||||
if (err instanceof multer.MulterError) {
|
||||
switch (err.message) {
|
||||
case 'File too large':
|
||||
return res.status(400).json({ success: false, error: VALIDATION_MESSAGES.carImg.invalid.size })
|
||||
default:
|
||||
return res.status(400).json({ success: false, error: err.message })
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(err.message)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,15 +0,0 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
router.get('/recipe-data', (request, response) => {
|
||||
response.send(require('./json/recipe-data/success.json'))
|
||||
})
|
||||
|
||||
router.get('/userpage-data', (req, res)=>{
|
||||
res.send(require('./json/userpage-data/success.json'))
|
||||
})
|
||||
|
||||
router.get('/homepage-data', (req, res)=>{
|
||||
res.send(require('./json/homepage-data/success.json'))
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
21
server/routers/edateam-legacy/index.ts
Normal file
21
server/routers/edateam-legacy/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Router } from 'express';
|
||||
|
||||
import recipeData from './json/recipe-data/success.json';
|
||||
import userpageData from './json/userpage-data/success.json';
|
||||
import homepageData from './json/homepage-data/success.json';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/recipe-data', (request, response) => {
|
||||
response.send(recipeData)
|
||||
})
|
||||
|
||||
router.get('/userpage-data', (req, res)=>{
|
||||
res.send(userpageData)
|
||||
})
|
||||
|
||||
router.get('/homepage-data', (req, res)=>{
|
||||
res.send(homepageData)
|
||||
})
|
||||
|
||||
export default router;
|
||||
12
server/routers/esc/index.js
Normal file
12
server/routers/esc/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const router = require("express").Router();
|
||||
|
||||
router.get('/game-links', (request, response) => {
|
||||
response.send(require('./json/game-links/success.json'))
|
||||
})
|
||||
|
||||
router.get('/4u2k-links', (request, response) => {
|
||||
response.send(require('./json/4u2k-links/success.json'))
|
||||
})
|
||||
;
|
||||
|
||||
module.exports = router;
|
||||
31
server/routers/esc/json/4u2k-links/success.json
Normal file
31
server/routers/esc/json/4u2k-links/success.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"data":[
|
||||
{
|
||||
"type": "video",
|
||||
"links": {
|
||||
"l1": "https://www.youtube.com/embed/DsQMLrPdLf8?si=l9X57nHqaSYlxDFf",
|
||||
"l2": "https://www.youtube.com/embed/Dk8AAU_UdVk?si=N8NdYMUCfawdsJGE",
|
||||
"l3": "https://www.youtube.com/embed/HKfDfWrCwEA?si=qPugjiKR8V9eZ-yG",
|
||||
"l4": "https://www.youtube.com/embed/tD-6xHAHrQ4?si=ZFe41gSK8d5gqahW"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "podcast",
|
||||
"links": {
|
||||
"l1": "https://www.youtube.com/embed/RtVs87Nd1MQ?si=i4giUCtbp4Ouqv2W",
|
||||
"l2": "https://www.youtube.com/embed/DfTU5LA_kw8?si=m7fI5Ie9yIGDFCrU",
|
||||
"l3": "https://www.youtube.com/embed/Sp-1fX1Q15I?si=xyealVly9IBMW7Xi",
|
||||
"l4": "https://www.youtube.com/embed/rLYFJYfluRs?si=MjW1beQ-Q9-TAehF"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "entertainment",
|
||||
"links": {
|
||||
"l1": "https://www.youtube.com/embed/DiuuglRCchQ?si=8wTVXKbV-mbHuSjW",
|
||||
"l2": "https://www.youtube.com/embed/zmZcIX5PEyo?si=Hbrv32kl0fqcmtV9",
|
||||
"l3": "https://www.youtube.com/embed/Te-TZUjmzFQ?si=fNG16eruoFEY2KNq",
|
||||
"l4": "https://www.youtube.com/embed/si-MQ5qg3zE?si=67mfO6gV80n1ULqo"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
20
server/routers/esc/json/game-links/success.json
Normal file
20
server/routers/esc/json/game-links/success.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"data":[
|
||||
{
|
||||
"title": "ABC",
|
||||
"description": "Мой брат Колян сбацал про меня байку на англицком и несколько фишек кинул для шухера. Англицкий ты вроде знаешь, впряжешься за меня, а?",
|
||||
"link": "https://www.oxfordonlineenglish.com/english-level-test/reading"
|
||||
},
|
||||
{
|
||||
"title": "Алё, меня слышно?",
|
||||
"description": "Мой кент на мобилу текст записал с иностранкой. Понимаешь, о чём тут говорят?",
|
||||
"link": "https://test-english.com/listening/"
|
||||
},
|
||||
{
|
||||
"title": "Анонимное тестирование",
|
||||
"description": "Ты язык-то нормально знаешь? Проверься, никто угарать не будет",
|
||||
"link": "https://www.ego4u.com/en/cram-up/tests"
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -8,22 +8,44 @@ router.get("/update-like", (request, response) => {
|
||||
response.send(require("./json/gamepage/success.json"));
|
||||
});
|
||||
|
||||
router.get("/categories", (request, response) => {
|
||||
response.send(require("./json/categories/success.json"));
|
||||
router.get("/add-to-cart", (request, response) => {
|
||||
response.send(require("./json/home-page-data/games-in-cart.json"));
|
||||
});
|
||||
|
||||
router.get("/categories", (request, response) => {
|
||||
response.send(require("./json/home-page-data/all-games.json"));
|
||||
});
|
||||
|
||||
router.get("/favourites", (request, response) => {
|
||||
response.send(require("./json/home-page-data/all-games.json"));
|
||||
});
|
||||
|
||||
// router.get("/shopping-cart", (request, response) => {
|
||||
// response.send(require("./json/shopping-cart/success.json"));
|
||||
// });
|
||||
|
||||
router.get("/shopping-cart", (request, response) => {
|
||||
response.send(require("./json/shopping-cart/success.json"));
|
||||
response.send(require("./json/home-page-data/games-in-cart.json"));
|
||||
});
|
||||
|
||||
router.get("/home", (request, response) => {
|
||||
response.send(require("./json/home-page-data/success.json"));
|
||||
// Добавляем поддержку разных ответов для /home
|
||||
router.get("/home", (req, res) => {
|
||||
if (stubs.home === "success") {
|
||||
res.send(require("./json/home-page-data/success.json"));
|
||||
} else if (stubs.home === "empty") {
|
||||
res.send({ data: [] }); // Отправляем пустой массив
|
||||
} else {
|
||||
res.status(500).json({ success: false, message: "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/all-games", (request, response) => {
|
||||
response.send(require("./json/home-page-data/all-games.json"));
|
||||
});
|
||||
|
||||
const stubs = {
|
||||
home: "success",
|
||||
};
|
||||
|
||||
// // Маршрут для обновления лайков
|
||||
// router.post("/update-like", (request, response) => {
|
||||
@@ -38,7 +60,6 @@ router.get("/all-games", (request, response) => {
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
|
||||
@@ -49,7 +70,7 @@ const commentsFilePath = path.join(__dirname, "./json/gamepage/success.json");
|
||||
async function readComments() {
|
||||
const data = await fs.readFile(commentsFilePath, "utf-8");
|
||||
const parsedData = JSON.parse(data);
|
||||
console.log("Прочитанные данные:", parsedData); // Логируем полученные данные
|
||||
console.log("Прочитанные данные:", parsedData); // Логируем полученные данные
|
||||
return parsedData;
|
||||
}
|
||||
// Write to JSON file
|
||||
@@ -88,5 +109,149 @@ router.post("/update-like", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Путь к JSON-файлу с корзиной
|
||||
const cartFilePath = path.join(
|
||||
__dirname,
|
||||
"./json/home-page-data/games-in-cart.json"
|
||||
);
|
||||
|
||||
// Функция для чтения JSON-файла
|
||||
async function readCart() {
|
||||
const data = await fs.readFile(cartFilePath, "utf-8");
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
// Функция для записи в JSON-файл
|
||||
async function writeCart(data) {
|
||||
await fs.writeFile(cartFilePath, JSON.stringify(data, null, 2), "utf-8");
|
||||
}
|
||||
|
||||
// Маршрут для добавления/удаления товара в корзине
|
||||
router.post("/add-to-cart", async (req, res) => {
|
||||
const { id, action } = req.body;
|
||||
|
||||
// Проверка наличия id и action
|
||||
if (id === undefined || action === undefined) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ success: false, message: "Invalid id or action" });
|
||||
}
|
||||
|
||||
try {
|
||||
const cartData = await readCart();
|
||||
let ids = cartData.data.ids;
|
||||
|
||||
if (action === "add") {
|
||||
// Если action "add", добавляем товар, если его нет в корзине
|
||||
if (!ids?.includes(id)) {
|
||||
ids.push(id);
|
||||
}
|
||||
} else if (action === "remove") {
|
||||
// Если action "remove", удаляем товар, если он есть в корзине
|
||||
if (ids?.includes(id)) {
|
||||
ids = ids.filter((item) => item !== id);
|
||||
}
|
||||
} else {
|
||||
// Если action невалиден
|
||||
return res
|
||||
.status(400)
|
||||
.json({ success: false, message: "Invalid action" });
|
||||
}
|
||||
|
||||
// Записываем обновленные данные обратно в файл
|
||||
cartData.data.ids = ids;
|
||||
await writeCart(cartData);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Cart updated successfully",
|
||||
data: cartData.data, // Возвращаем обновленные данные
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error updating cart:", error);
|
||||
res.status(500).json({ success: false, message: "Server error" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
const createElement = (key, value, buttonTitle, basePath) => `
|
||||
<label>
|
||||
<input name="${key}" type="radio" ${
|
||||
stubs[key] === value ? "checked" : ""
|
||||
} onclick="fetch('${basePath}/admin/set/${key}/${value}')"/>
|
||||
${buttonTitle || value}
|
||||
</label>
|
||||
`;
|
||||
|
||||
router.get("/admin/home", (request, response) => {
|
||||
const basePath = request.baseUrl; // Получаем базовый путь маршрутизатора
|
||||
response.send(`
|
||||
<div>
|
||||
<fieldset>
|
||||
<legend>Настройка данных для /home</legend>
|
||||
${createElement("home", "success", "Отдать успешный ответ", basePath)}
|
||||
${createElement("home", "empty", "Отдать пустой массив", basePath)}
|
||||
${createElement("home", "error", "Отдать ошибку", basePath)}
|
||||
</fieldset>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
router.get("/admin/game-page", (request, response) => {
|
||||
response.send(`
|
||||
<div>
|
||||
<fieldset>
|
||||
<legend>Настройка данных для /game-page</legend>
|
||||
${createElement(
|
||||
"game-page",
|
||||
"success",
|
||||
"Отдать успешный ответ"
|
||||
)}
|
||||
${createElement("game-page", "empty", "Отдать пустой массив")}
|
||||
${createElement("game-page", "error", "Отдать ошибку")}
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
router.get("/admin/categories", (request, response) => {
|
||||
response.send(`
|
||||
<div>
|
||||
<fieldset>
|
||||
<legend>Настройка данных для /categories</legend>
|
||||
${createElement(
|
||||
"categories",
|
||||
"success",
|
||||
"Отдать успешный ответ"
|
||||
)}
|
||||
${createElement("categories", "empty", "Отдать пустой массив")}
|
||||
${createElement("categories", "error", "Отдать ошибку")}
|
||||
</fieldset>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
router.get("/admin/favourites", (request, response) => {
|
||||
response.send(`
|
||||
<div>
|
||||
<fieldset>
|
||||
<legend>Настройка данных для /favourites</legend>
|
||||
${createElement(
|
||||
"favourites",
|
||||
"success",
|
||||
"Отдать успешный ответ"
|
||||
)}
|
||||
${createElement("favourites", "empty", "Отдать пустой массив")}
|
||||
${createElement("favourites", "error", "Отдать ошибку")}
|
||||
</fieldset>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
router.get("/admin/set/:key/:value", (request, response) => {
|
||||
const { key, value } = request.params;
|
||||
stubs[key] = value;
|
||||
response.send("Настройки обновлены!");
|
||||
});
|
||||
@@ -1,186 +0,0 @@
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"games1": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "How to Survive",
|
||||
"price": 259,
|
||||
"old_price": 500,
|
||||
"image": "sales_game1",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Red Solstice 2 Survivors",
|
||||
"price": 561,
|
||||
"image": "sales_game2",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Sons Of The Forests",
|
||||
"price": 820,
|
||||
"old_price": 1100,
|
||||
"image": "new_game2",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "The Witcher 3: Wild Hunt",
|
||||
"price": 990,
|
||||
"old_price": 1200,
|
||||
"image": "leaders_game4",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Atomic Heart",
|
||||
"price": 1200,
|
||||
"old_price": 2500,
|
||||
"image": "leaders_game5",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Crab Game",
|
||||
"price": 600,
|
||||
"old_price": 890,
|
||||
"image": "leaders_game6",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
}
|
||||
],
|
||||
"games2": [
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Alpha League",
|
||||
"price": 299,
|
||||
"image": "new_game1",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"title": "Sons Of The Forests",
|
||||
"price": 820,
|
||||
"old_price": 1100,
|
||||
"image": "new_game2",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"title": "Pacific Drives",
|
||||
"price": 1799,
|
||||
"image": "new_game3",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "The Witcher 3: Wild Hunt",
|
||||
"price": 990,
|
||||
"old_price": 1200,
|
||||
"image": "leaders_game4",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Atomic Heart",
|
||||
"price": 1200,
|
||||
"old_price": 2500,
|
||||
"image": "leaders_game5",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Crab Game",
|
||||
"price": 600,
|
||||
"old_price": 890,
|
||||
"image": "leaders_game6",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
}
|
||||
],
|
||||
"games3": [
|
||||
{
|
||||
"id": 10,
|
||||
"title": "Elden Ring",
|
||||
"price": 3295,
|
||||
"old_price": 3599,
|
||||
"image": "leaders_game2",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"title": "Counter-Strike 2",
|
||||
"price": 479,
|
||||
"image": "leaders_game1",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"title": "PUBG: BATTLEGROUNDS",
|
||||
"price": 199,
|
||||
"image": "leaders_game3",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "The Witcher 3: Wild Hunt",
|
||||
"price": 990,
|
||||
"old_price": 1200,
|
||||
"image": "leaders_game4",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Atomic Heart",
|
||||
"price": 1200,
|
||||
"old_price": 2500,
|
||||
"image": "leaders_game5",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Crab Game",
|
||||
"price": 600,
|
||||
"old_price": 890,
|
||||
"image": "leaders_game6",
|
||||
"os": "windows",
|
||||
"fav1": "star1",
|
||||
"fav2": "star2"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -5,28 +5,28 @@
|
||||
{
|
||||
"username": "Пользователь1",
|
||||
"text": "Текст комментария 1",
|
||||
"likes": 9,
|
||||
"likes": 13,
|
||||
"rating": 8,
|
||||
"date": "2025-03-01T10:00:00Z"
|
||||
},
|
||||
{
|
||||
"username": "Пользователь2",
|
||||
"text": "Текст комментария 2",
|
||||
"likes": 7,
|
||||
"likes": 10,
|
||||
"rating": 7,
|
||||
"date": "2025-01-01T10:00:00Z"
|
||||
},
|
||||
{
|
||||
"username": "Пользователь3",
|
||||
"text": "Текст комментария 3",
|
||||
"likes": 5,
|
||||
"likes": 4,
|
||||
"rating": 3,
|
||||
"date": "2025-02-01T10:00:00Z"
|
||||
},
|
||||
{
|
||||
"username": "Пользователь4",
|
||||
"text": "Текст комментария 4",
|
||||
"likes": 15,
|
||||
"likes": 18,
|
||||
"rating": 2,
|
||||
"date": "2025-12-01T10:00:00Z"
|
||||
}
|
||||
|
||||
@@ -3,144 +3,183 @@
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "The Witcher 3: Wild Hunt",
|
||||
"image": "game1",
|
||||
"text": "$10",
|
||||
"imgPath": "img_top_1",
|
||||
"description": "Эпическая RPG с открытым миром, в которой Геральт из Ривии охотится на монстров и раскрывает политические заговоры.",
|
||||
"title": "Elden Ring",
|
||||
"image": "game17",
|
||||
"price": 3295,
|
||||
"old_price": 3599,
|
||||
"imgPath": "img_top_17",
|
||||
"description": "Крупномасштабная RPG, действие которой происходит в обширном открытом мире c богатой мифологией и множеством опасных врагов.",
|
||||
"category": "RPG"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Red Dead Redemption 2",
|
||||
"title": "The Witcher 3: Wild Hunt",
|
||||
"image": "game1",
|
||||
"price": 990,
|
||||
"old_price": 1200,
|
||||
"imgPath": "img_top_1",
|
||||
"description": "Эпическая RPG с открытым миром, в которой Геральт из Ривии охотится на монстров и раскрывает политические заговоры.",
|
||||
"category": "RPG"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"title": "Red Dead Redemption 2",
|
||||
"image": "game2",
|
||||
"text": "$10",
|
||||
"price": 980,
|
||||
"old_price": 3800,
|
||||
"imgPath": "img_top_2",
|
||||
"description": "Приключенческая игра с открытым миром на Диком Западе, рассказывающая историю Артура Моргана.",
|
||||
"category": "Adventures"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Forza Horizon 5",
|
||||
"title": "Forza Horizon 5",
|
||||
"image": "game3",
|
||||
"text": "$10",
|
||||
"price": 1900,
|
||||
"imgPath": "img_top_3",
|
||||
"description": "Гоночная игра с огромным открытым миром, действие которой происходит в Мексике.",
|
||||
"category": "Race"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "Atomic Heart",
|
||||
"title": "Atomic Heart",
|
||||
"image": "game4",
|
||||
"text": "$10",
|
||||
"price": 1200,
|
||||
"old_price": 2500,
|
||||
|
||||
"imgPath": "img_top_4",
|
||||
"description": "Экшен-шутер с элементами RPG, разворачивающийся в альтернативной Советской России.",
|
||||
"category": "Shooters"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "Counter-Strike 2",
|
||||
"title": "Counter-Strike 2",
|
||||
"image": "game5",
|
||||
"text": "$10",
|
||||
"price": 479,
|
||||
|
||||
"imgPath": "img_top_5",
|
||||
"description": "Популярный онлайн-шутер с соревновательным геймплеем и тактическими элементами.",
|
||||
"category": "Shooters"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"name": "Grand Theft Auto V",
|
||||
"title": "Grand Theft Auto V",
|
||||
"image": "game6",
|
||||
"text": "$10",
|
||||
"price": 700,
|
||||
|
||||
"imgPath": "img_top_6",
|
||||
"description": "Игра с открытым миром, где можно погрузиться в криминальный мир Лос-Сантоса.",
|
||||
"category": "Adventures"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"name": "Assassin’s Creed IV: Black Flag",
|
||||
"title": "Assassin’s Creed IV: Black Flag",
|
||||
"image": "game7",
|
||||
"text": "$10",
|
||||
"price": 1100,
|
||||
|
||||
"imgPath": "img_top_7",
|
||||
"description": "Приключенческая игра о пиратах и морских сражениях в эпоху золотого века пиратства.",
|
||||
"category": "Adventures"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"name": "Spider-Man",
|
||||
"title": "Spider-Man",
|
||||
"image": "game8",
|
||||
"text": "$10",
|
||||
"price": 3800,
|
||||
|
||||
"imgPath": "img_top_8",
|
||||
"description": "Игра о супергерое Человеке-пауке с захватывающими битвами и паркуром по Нью-Йорку.",
|
||||
"category": "Action"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"name": "Assassin’s Creed Mirage",
|
||||
"title": "Assassin’s Creed Mirage",
|
||||
"image": "game9",
|
||||
"text": "$10",
|
||||
"price": 1600,
|
||||
|
||||
"imgPath": "img_top_9",
|
||||
"description": "Приключенческая игра с упором на скрытность, вдохновленная классическими частями серии.",
|
||||
"category": "Action"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"name": "Assassin’s Creed Valhalla",
|
||||
"title": "Assassin’s Creed Valhalla",
|
||||
"image": "game10",
|
||||
"text": "$10",
|
||||
"price": 800,
|
||||
"old_price": 2200,
|
||||
|
||||
"imgPath": "img_top_10",
|
||||
"description": "RPG с открытым миром о викингах, включающая битвы, исследования и строительство поселений.",
|
||||
"category": "RPG"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"name": "ARK: Survival Evolved",
|
||||
"title": "ARK: Survival Evolved",
|
||||
"image": "game11",
|
||||
"text": "$10",
|
||||
"price": 790,
|
||||
|
||||
"imgPath": "img_top_11",
|
||||
"description": "Выживание в открытом мире с динозаврами, строительством и многопользовательскими элементами.",
|
||||
"category": "Simulators"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"name": "FIFA 23",
|
||||
"title": "FIFA 23",
|
||||
"image": "game12",
|
||||
"text": "$10",
|
||||
"price": 3900,
|
||||
|
||||
"imgPath": "img_top_12",
|
||||
"description": "Популярный футбольный симулятор с улучшенной графикой и реалистичным геймплеем.",
|
||||
"category": "Sports"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"name": "Dirt 5",
|
||||
"title": "Dirt 5",
|
||||
"image": "game13",
|
||||
"text": "$10",
|
||||
"price": 2300,
|
||||
|
||||
"imgPath": "img_top_13",
|
||||
"description": "Аркадная гоночная игра с фокусом на ралли и внедорожных соревнованиях.",
|
||||
"category": "Race"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"name": "Cyberpunk 2077",
|
||||
"title": "Cyberpunk 2077",
|
||||
"image": "game14",
|
||||
"text": "$10",
|
||||
"price": 3400,
|
||||
|
||||
"imgPath": "img_top_14",
|
||||
"description": "RPG в киберпанк-сеттинге с нелинейным сюжетом и детализированным открытым миром.",
|
||||
"category": "RPG"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"name": "Age of Empires IV",
|
||||
"title": "Age of Empires IV",
|
||||
"image": "game15",
|
||||
"text": "$10",
|
||||
"price": 3200,
|
||||
|
||||
"imgPath": "img_top_15",
|
||||
"description": "Классическая стратегия в реальном времени с историческими кампаниями.",
|
||||
"category": "Strategies"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"name": "Civilization VI",
|
||||
"title": "Civilization VI",
|
||||
"image": "game16",
|
||||
"text": "$10",
|
||||
"price": 4200,
|
||||
"imgPath": "img_top_16",
|
||||
"description": "Глобальная пошаговая стратегия, в которой игроки строят и развивают цивилизации.",
|
||||
"category": "Strategies"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"ids": [
|
||||
3,
|
||||
13,
|
||||
1,
|
||||
10,
|
||||
4,
|
||||
9,
|
||||
15,
|
||||
6,
|
||||
7
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -3,43 +3,51 @@
|
||||
"data": {
|
||||
"topSail": [
|
||||
{
|
||||
"id": 1,
|
||||
"image": "game1",
|
||||
"text": "$10",
|
||||
"price": 1500,
|
||||
"imgPath": "img_top_1"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"image": "game2",
|
||||
"text": "$10",
|
||||
"price": 980,
|
||||
"imgPath": "img_top_2"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"image": "game3",
|
||||
"text": "$10",
|
||||
"price": 1900,
|
||||
"imgPath": "img_top_3"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"image": "game4",
|
||||
"text": "$10",
|
||||
"price": 1200,
|
||||
"imgPath": "img_top_4"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"image": "game5",
|
||||
"text": "$10",
|
||||
"price": 479,
|
||||
"imgPath": "img_top_5"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"image": "game6",
|
||||
"text": "$10",
|
||||
"price": 700,
|
||||
"imgPath": "img_top_6"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"image": "game7",
|
||||
"text": "$10",
|
||||
"price": 1100,
|
||||
"imgPath": "img_top_7"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"image": "game8",
|
||||
"text": "$10",
|
||||
"price": 3800,
|
||||
"imgPath": "img_top_8"
|
||||
}
|
||||
],
|
||||
@@ -97,22 +105,26 @@
|
||||
{
|
||||
"image": "news1",
|
||||
"text": "Разработчики Delta Force: Hawk Ops представили крупномасштабный режим Havoc Warfare",
|
||||
"imgPath": "img_news_1"
|
||||
"imgPath": "img_news_1",
|
||||
"link": "https://gamemag.ru/news/185583/delta-force-hawk-ops-gameplay-showcase-havoc-warfare"
|
||||
},
|
||||
{
|
||||
"image": "news2",
|
||||
"text": "Первый трейлер Assassin’s Creed Shadows — с темнокожим самураем в феодальной Японии",
|
||||
"imgPath": "img_news_2"
|
||||
"imgPath": "img_news_2",
|
||||
"link": "https://stopgame.ru/newsdata/62686/pervyy_trailer_assassin_s_creed_shadows_s_temnokozhim_samuraem_v_feodalnoy_yaponii"
|
||||
},
|
||||
{
|
||||
"image": "news3",
|
||||
"text": "Призрак Цусимы» вышел на ПК — и уже ставит рекорды для Sony",
|
||||
"imgPath": "img_news_3"
|
||||
"imgPath": "img_news_3",
|
||||
"link": "https://stopgame.ru/newsdata/62706/prizrak_cusimy_vyshel_na_pk_i_uzhe_stavit_rekordy_dlya_sony"
|
||||
},
|
||||
{
|
||||
"image": "news4",
|
||||
"text": "Авторы Skull and Bones расширяют планы на второй сезо",
|
||||
"imgPath": "img_news_4"
|
||||
"text": "Авторы Skull and Bones расширяют планы на второй сезон",
|
||||
"imgPath": "img_news_4",
|
||||
"link": "https://stopgame.ru/newsdata/62711/avtory_skull_and_bones_rasshiryayut_plany_na_vtoroy_sezon"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
3
server/routers/kazan-explore/const.js
Normal file
3
server/routers/kazan-explore/const.js
Normal file
@@ -0,0 +1,3 @@
|
||||
exports.KAZAN_EXPLORE_RESULTS_MODEL_NAME = 'KAZAN_EXPLORE_RESULTS'
|
||||
|
||||
exports.TOKEN_KEY = "kazan-explore_top_secret_key_hbfhqf9jq9prg"
|
||||
@@ -1,18 +1,32 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
const { expressjwt } = require('express-jwt')
|
||||
const axios = require('axios');
|
||||
const jwt = require('jsonwebtoken')
|
||||
const { ResultsModel } = require('./model/results')
|
||||
const { TOKEN_KEY } = require('./const')
|
||||
|
||||
// First page
|
||||
router.get('/getInfoAboutKazan', (request, response) => {
|
||||
const lang = request.query.lang || 'ru'; // Получаем язык из параметров запроса
|
||||
const lang = request.query.lang || 'ru';
|
||||
try {
|
||||
const data = require('./json/first/info-about-kazan/success.json'); // Загружаем весь JSON
|
||||
const translatedData = data[lang] || data['ru']; // Выбираем перевод по языку или дефолтный
|
||||
response.send(translatedData); // Отправляем перевод клиенту
|
||||
const data = require('./json/first/info-about-kazan/success.json');
|
||||
const translatedData = data[lang] || data['ru'];
|
||||
response.send(translatedData);
|
||||
} catch (error) {
|
||||
response.status(500).send({ message: 'Internal server error' }); // Ошибка в случае проблем с JSON
|
||||
response.status(500).send({ message: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/getServices', (request, response) => {
|
||||
const lang = request.query.lang || 'ru';
|
||||
try {
|
||||
const data = require(`./json/first/services/${lang}/success.json`);
|
||||
response.send(data);
|
||||
} catch (error) {
|
||||
response.status(404).send({ message: 'Language not found' });
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/getNews', (request, response) => {
|
||||
const lang = request.query.lang || 'ru';
|
||||
try {
|
||||
@@ -25,13 +39,13 @@ router.get('/getNews', (request, response) => {
|
||||
|
||||
// Sport page
|
||||
router.get('/getFirstText', (request, response) => {
|
||||
const lang = request.query.lang || 'ru'; // Получаем язык из параметров
|
||||
const lang = request.query.lang || 'ru';
|
||||
try {
|
||||
const data = require('./json/sport/first-text/success.json'); // Загружаем JSON
|
||||
const translatedData = data[lang] || data['ru']; // Берём перевод или дефолтный
|
||||
const data = require('./json/sport/first-text/success.json');
|
||||
const translatedData = data[lang] || data['ru'];
|
||||
response.send(translatedData);
|
||||
} catch (error) {
|
||||
response.status(404).send({ message: 'Language not found' }); // Обработка ошибки
|
||||
response.status(404).send({ message: 'Language not found' });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -208,4 +222,89 @@ router.post('/registration', async (request, response) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/signin', async (req, res) => {
|
||||
const { user } = req.body
|
||||
|
||||
if (!user || !user.token) {
|
||||
return res.status(404).json({error : "No user found"});
|
||||
}
|
||||
|
||||
const valRes = await axios.get('https://antd-table-v2-backend.onrender.com/api/auth/check',
|
||||
{
|
||||
headers: {
|
||||
'authorization': `Bearer ${user.token}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (valRes.status !== 200) {
|
||||
return res.status(401).json({error : "User authorization error"});
|
||||
}
|
||||
|
||||
const accessToken = jwt.sign({
|
||||
...JSON.parse(JSON.stringify(user._id)),
|
||||
}, TOKEN_KEY, {
|
||||
expiresIn: '12h'
|
||||
})
|
||||
user.token = accessToken;
|
||||
res.json(user)
|
||||
})
|
||||
|
||||
router.use(
|
||||
expressjwt({
|
||||
secret: TOKEN_KEY,
|
||||
algorithms: ['HS256'],
|
||||
getToken: function fromHeaderOrQuerystring(req) {
|
||||
if (req.headers.authorization && req.headers.authorization.split(" ")[0] === "Bearer")
|
||||
return req.headers.authorization.split(" ")[1];
|
||||
else if (req.query && req.query.token)
|
||||
return req.query.token;
|
||||
|
||||
return null;
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
router.get('/getQuizResults/:userId', async (request, response) => {
|
||||
const { userId } = request.params;
|
||||
|
||||
try {
|
||||
const results = await ResultsModel.findOne({ userId: userId }).exec();
|
||||
|
||||
if (!results)
|
||||
return response.status(404).send({ message: 'Quiz results not found' });
|
||||
|
||||
response.send(results.items);
|
||||
} catch (error) {
|
||||
response.status(500).send({ message: 'An error occurred while fetching quiz results' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/addQuizResult', async (request, response) => {
|
||||
const { userId, quizId, result } = request.body;
|
||||
|
||||
if (!userId || !quizId || !result)
|
||||
return response.status(400).send({ message: 'Invalid input data' });
|
||||
|
||||
try {
|
||||
let userResults = await ResultsModel.findOne({ userId: userId }).exec();
|
||||
if (!userResults) {
|
||||
userResults = new ResultsModel({ userId, items: [] });
|
||||
}
|
||||
const itemToOverride = userResults.items.find(item => item.quizId === quizId)
|
||||
if (!itemToOverride) {
|
||||
userResults.items.push({ quizId, result });
|
||||
}
|
||||
else {
|
||||
itemToOverride.result = result;
|
||||
}
|
||||
|
||||
await userResults.save();
|
||||
|
||||
response.status(200).send({ message: 'Quiz result added successfully' });
|
||||
} catch (error) {
|
||||
response.status(500).send({ message: 'An error occurred while adding quiz result' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
102
server/routers/kazan-explore/json/first/services/en/success.json
Normal file
102
server/routers/kazan-explore/json/first/services/en/success.json
Normal file
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"banks": [
|
||||
{
|
||||
"name": "Sberbank of Russia",
|
||||
"description": "One of the largest and most popular banks in Russia. There are many branches and ATMs in Kazan. Sberbank offers a wide range of services, including loans, deposits, insurance, business services, and online banking."
|
||||
},
|
||||
{
|
||||
"name": "VTB",
|
||||
"description": "The second largest bank in Russia, with many offices and ATMs in Kazan. VTB offers various financial products for individuals and businesses, including loans, deposits, investment solutions, and cards."
|
||||
},
|
||||
{
|
||||
"name": "Tinkoff Bank",
|
||||
"description": "Although Tinkoff does not have traditional offices in Kazan, its products and services are available in the city through online banking and remote services. Tinkoff offers favorable terms for credit cards, deposits, and services for small and medium-sized businesses."
|
||||
},
|
||||
{
|
||||
"name": "Alfa-Bank",
|
||||
"description": "One of the largest private banks in Russia, with offices in Kazan. Alfa-Bank offers standard banking services such as loans, deposits, cards, as well as investment and insurance products."
|
||||
},
|
||||
{
|
||||
"name": "Rosselkhozbank",
|
||||
"description": "Rosselkhozbank is also present in Kazan, specializing in servicing the agro-industrial complex, but also provides services for individuals and businesses, including loans, deposits, and cards."
|
||||
},
|
||||
{
|
||||
"name": "RBC Bank",
|
||||
"description": "A Russian bank with several offices and ATMs in Kazan. It offers loans, cards, deposits, and business services."
|
||||
},
|
||||
{
|
||||
"name": "Bank Saint Petersburg",
|
||||
"description": "A local bank that also provides services in Kazan. It offers a wide range of banking products for individuals and businesses."
|
||||
}
|
||||
],
|
||||
"hospitals": [
|
||||
{
|
||||
"name": "Kazan City Clinical Hospital No. 1",
|
||||
"description": "One of the largest multidisciplinary hospitals in Kazan, offering services in surgery, traumatology, neurology, cardiology, and other medical fields. Modern technologies and highly qualified staff."
|
||||
},
|
||||
{
|
||||
"name": "Republican Clinical Hospital",
|
||||
"description": "The main medical organization of the Republic of Tatarstan, providing a wide range of services for adults and children, including emergency care, high-tech surgeries, and diagnostics."
|
||||
},
|
||||
{
|
||||
"name": "City Hospital No. 7",
|
||||
"description": "A hospital specializing in providing medical care in therapeutic, surgical, and resuscitation medicine. The hospital employs experienced specialists and uses modern treatment methods."
|
||||
},
|
||||
{
|
||||
"name": "Kazan Children's Clinical Hospital",
|
||||
"description": "A specialized medical facility for children, providing services for the treatment of diseases related to pediatrics, surgery, cardiology, and other fields for children of all ages."
|
||||
},
|
||||
{
|
||||
"name": "Kazan Oncology Dispensary",
|
||||
"description": "A medical institution specializing in the treatment of oncological diseases. It uses the latest methods of cancer diagnosis and treatment, including chemotherapy, radiotherapy, and surgical interventions."
|
||||
},
|
||||
{
|
||||
"name": "City Hospital No. 18",
|
||||
"description": "A multidisciplinary medical institution offering treatment in various medical fields, including traumatology, neurology, and cardiology. The hospital has a rehabilitation department for patients recovering from serious diseases."
|
||||
},
|
||||
{
|
||||
"name": "Republican Hospital for War Veterans",
|
||||
"description": "A medical institution providing specialized care for World War II veterans, disabled individuals, and elderly people. It also offers a wide range of services for citizens with chronic diseases."
|
||||
}
|
||||
],
|
||||
"pharmacies": [
|
||||
{
|
||||
"name": "Apteka 36.6",
|
||||
"description": "A pharmacy chain with a wide range of medications, vitamins, cosmetics, and health products. Loyalty programs and online orders for customer convenience."
|
||||
},
|
||||
{
|
||||
"name": "Rigla",
|
||||
"description": "One of the largest pharmacy chains in Russia. It offers a wide range of medicines, medical products, and cosmetics. It also provides the option to order online."
|
||||
},
|
||||
{
|
||||
"name": "Zdorovaya Semya",
|
||||
"description": "A pharmacy chain focused on the sale of medicines and health products, including medical equipment. Often runs promotions and discounts on popular items."
|
||||
},
|
||||
{
|
||||
"name": "A5 Pharmacy Chain",
|
||||
"description": "Pharmacies offering a wide range of products, including medicines, vitamins, cosmetics, and children's products. Convenient delivery and online order services."
|
||||
},
|
||||
{
|
||||
"name": "Samson-Pharma Pharmacy",
|
||||
"description": "A pharmacy chain offering customers all necessary medicines and health products. Pharmacies offer various discount and bonus programs for regular customers."
|
||||
},
|
||||
{
|
||||
"name": "Tsvetnoy Pharmacy Chain",
|
||||
"description": "Pharmacies known for their convenient locations and high-quality service. They sell medicines, vitamins, self-care products, and medical equipment."
|
||||
},
|
||||
{
|
||||
"name": "Doctor Stoletev Pharmacy",
|
||||
"description": "A pharmacy chain focused on selling pharmaceutical products, medical goods, and cosmetics. Convenient service and promotions for customers."
|
||||
}
|
||||
],
|
||||
"airports": [
|
||||
{
|
||||
"name": "Kazan International Airport",
|
||||
"description": "The main airport of the city of Kazan, serving international and domestic flights. The airport is equipped with modern terminals, comfortable waiting areas, shops, and restaurants. It is one of the largest in the Volga region and an important transport hub for Tatarstan."
|
||||
},
|
||||
{
|
||||
"name": "Kazan-2 (when it was operational)",
|
||||
"description": "Previously used for domestic flights and military needs. It is no longer fully operational as all passenger flights have been redirected to Kazan International Airport. The airport building is closed for commercial air traffic."
|
||||
}
|
||||
]
|
||||
}
|
||||
102
server/routers/kazan-explore/json/first/services/ru/success.json
Normal file
102
server/routers/kazan-explore/json/first/services/ru/success.json
Normal file
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"banks": [
|
||||
{
|
||||
"name": "Сбербанк России",
|
||||
"description": "Один из крупнейших и самых популярных банков в России. В Казани есть множество отделений и банкоматов. Сбербанк предлагает широкий спектр услуг, включая кредиты, депозиты, страхование, обслуживание бизнеса и онлайн-банкинг."
|
||||
},
|
||||
{
|
||||
"name": "ВТБ",
|
||||
"description": "Второй по величине банк в России, с большим количеством офисов и банкоматов в Казани. ВТБ предлагает различные финансовые продукты для физических и юридических лиц, включая кредиты, вклады, инвестиционные решения и карты."
|
||||
},
|
||||
{
|
||||
"name": "Тинькофф Банк",
|
||||
"description": "Несмотря на то что у Тинькофф нет традиционных офисов в Казани, его продукты и услуги доступны в городе через онлайн-банкинг и удаленное обслуживание. Тинькофф предлагает выгодные условия по кредитным картам, вклады, а также услуги для малого и среднего бизнеса."
|
||||
},
|
||||
{
|
||||
"name": "Альфа-Банк",
|
||||
"description": "Один из крупных частных банков в России, с офисами в Казани. Альфа-Банк предлагает стандартные банковские услуги, такие как кредиты, депозиты, карты, а также инвестиционные и страховые продукты."
|
||||
},
|
||||
{
|
||||
"name": "Россельхозбанк",
|
||||
"description": "В Казани также присутствует Россельхозбанк, специализирующийся на обслуживании агропромышленного комплекса, но также предоставляет услуги для физических и юридических лиц, включая кредиты, депозиты и карты."
|
||||
},
|
||||
{
|
||||
"name": "РБК Банк",
|
||||
"description": "Российский банк с рядом офисов и банкоматов в Казани. Предлагает кредиты, карты, депозиты, а также обслуживание для бизнеса."
|
||||
},
|
||||
{
|
||||
"name": "Банк Санкт-Петербург",
|
||||
"description": "Местный банк, который также предоставляет услуги в Казани. Предлагает широкий выбор банковских продуктов для частных лиц и бизнеса."
|
||||
}
|
||||
],
|
||||
"hospitals": [
|
||||
{
|
||||
"name": "Казанская городская клиническая больница №1",
|
||||
"description": "Одна из крупнейших многопрофильных больниц Казани, предлагающая услуги в области хирургии, травматологии, неврологии, кардиологии и других медицинских направлений. Современные технологии и высококвалифицированный персонал."
|
||||
},
|
||||
{
|
||||
"name": "Республиканская клиническая больница",
|
||||
"description": "Основная медицинская организация Республики Татарстан, предоставляющая широкий спектр услуг для взрослых и детей, включая экстренную помощь, высокотехнологичные операции и диагностику."
|
||||
},
|
||||
{
|
||||
"name": "Городская больница №7",
|
||||
"description": "Больница, специализирующаяся на оказании медицинской помощи в области терапевтической, хирургической и реанимационной медицины. В больнице работают опытные специалисты, используемые современные методы лечения."
|
||||
},
|
||||
{
|
||||
"name": "Казанская детская клиническая больница",
|
||||
"description": "Профильное медицинское учреждение для детей, которое предоставляет услуги по лечению заболеваний, связанных с педиатрией, хирургией, кардиологией и другими направлениями для детей всех возрастов."
|
||||
},
|
||||
{
|
||||
"name": "Казанский онкологический диспансер",
|
||||
"description": "Медицинское учреждение, специализирующееся на лечении онкологических заболеваний. Использует новейшие методы диагностики и лечения рака, включая химиотерапию, радиотерапию и операционные вмешательства."
|
||||
},
|
||||
{
|
||||
"name": "Городская больница №18",
|
||||
"description": "Многопрофильное медицинское учреждение, предлагающее лечение в различных областях медицины, включая травматологию, неврологию и кардиологию. В больнице есть отделение для реабилитации пациентов после тяжелых заболеваний."
|
||||
},
|
||||
{
|
||||
"name": "Республиканская больница для ветеранов войн",
|
||||
"description": "Медицинское учреждение, оказывающее специализированную помощь ветеранам Великой Отечественной войны, инвалидам и пожилым людям. Также предлагает широкий спектр услуг для граждан с хроническими заболеваниями."
|
||||
}
|
||||
],
|
||||
"pharmacies": [
|
||||
{
|
||||
"name": "Аптека 36,6",
|
||||
"description": "Сеть аптек с большим ассортиментом лекарственных средств, витаминов, косметики и товаров для здоровья. Программы лояльности и онлайн-заказы для удобства клиентов."
|
||||
},
|
||||
{
|
||||
"name": "Ригла",
|
||||
"description": "Одна из крупнейших аптечных сетей в России. Предлагает широкий выбор лекарств, медицинских товаров и косметики. Также предоставляет возможность заказа через интернет."
|
||||
},
|
||||
{
|
||||
"name": "Здоровая семья",
|
||||
"description": "Аптечная сеть, ориентированная на продажу лекарств и товаров для здоровья, включая медицинскую технику. Часто проводятся акции и скидки на популярные товары."
|
||||
},
|
||||
{
|
||||
"name": "Аптечная сеть 'А5'",
|
||||
"description": "Аптеки, предлагающие широкий ассортимент товаров, включая лекарства, витамины, косметику и товары для детей. Удобные услуги доставки и онлайн-заказов."
|
||||
},
|
||||
{
|
||||
"name": "Аптека 'Самсон-Фарма'",
|
||||
"description": "Сеть аптек, предоставляющая клиентам все необходимые лекарства и товары для здоровья. Аптеки предлагают различные программы скидок и бонусов для постоянных клиентов."
|
||||
},
|
||||
{
|
||||
"name": "Аптечная сеть 'Цветной'",
|
||||
"description": "Аптеки, известные своими удобными местоположениями и качественным обслуживанием. В продаже лекарства, витамины, товары для ухода за собой и медтехника."
|
||||
},
|
||||
{
|
||||
"name": "Аптека 'Доктор Столетов'",
|
||||
"description": "Сеть аптек, ориентированная на продажу фармацевтической продукции, медицинских товаров и косметики. Удобный сервис и акции для клиентов."
|
||||
}
|
||||
],
|
||||
"airports": [
|
||||
{
|
||||
"name": "Международный аэропорт Казань",
|
||||
"description": "Главный аэропорт города Казани, обслуживающий международные и внутренние рейсы. Аэропорт оснащен современными терминалами, удобными зонами ожидания, магазинами и ресторанами. Он является одним из крупнейших в Поволжье и важным транспортным узлом для Татарстана."
|
||||
},
|
||||
{
|
||||
"name": "Казань-2 (когда был действующим)",
|
||||
"description": "Ранее используемый аэропорт для внутренних рейсов и военных нужд. В настоящее время не функционирует в полном объеме, поскольку все пассажирские рейсы перенаправлены в Международный аэропорт Казань. Здание аэропорта закрыто для коммерческих авиаперевозок."
|
||||
}
|
||||
]
|
||||
}
|
||||
102
server/routers/kazan-explore/json/first/services/tt/success.json
Normal file
102
server/routers/kazan-explore/json/first/services/tt/success.json
Normal file
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"banks": [
|
||||
{
|
||||
"name": "Россия Сбербанкы",
|
||||
"description": "Россиядәге иң зур һәм популяр банкларның берсе. Казан шәһәрендә күпсанлы бүлекләр һәм банкоматлар бар. Сбербанк киң спектрлы хезмәтләр тәкъдим итә, шул исәптән кредитлар, депозиты, иминиятләштерү, бизнеска хезмәт күрсәтү һәм онлайн-банкчылык."
|
||||
},
|
||||
{
|
||||
"name": "ВТБ",
|
||||
"description": "Россиядә икенче зурлыктагы банк, Казан шәһәрендә күп санлы офислар һәм банкоматлар белән. ВТБ физик һәм юридик затлар өчен төрле финанс продуктларын тәкъдим итә, шул исәптән кредитлар, депозитлар, инвестицион чишелешләр һәм карталар."
|
||||
},
|
||||
{
|
||||
"name": "Тинькофф Банк",
|
||||
"description": "Тинькофф Казан шәһәрендә традицион офисларга ия булмаса да, аның продуктлары һәм хезмәтләре шәһәрдә онлайн-банкчылык һәм ерак хезмәт күрсәтү аша тәкъдим ителә. Тинькофф кредит карталары, депозитлар, шулай ук кечкенә һәм урта бизнес өчен хезмәтләр тәкъдим итә."
|
||||
},
|
||||
{
|
||||
"name": "Альфа-Банк",
|
||||
"description": "Россиядәге зур шәхси банкларның берсе, Казанда офислары белән. Альфа-Банк стандарт банк хезмәтләрен тәкъдим итә, шул исәптән кредитлар, депозитлар, карталар, шулай ук инвестицион һәм иминият продуктлары."
|
||||
},
|
||||
{
|
||||
"name": "Россельхозбанк",
|
||||
"description": "Казан шәһәрендә Россельхозбанк та бар, ул агропромышленность өлкәсендә хезмәт күрсәтүгә махсуслашкан, ләкин шулай ук физик һәм юридик затлар өчен хезмәтләр тәкъдим итә, шул исәптән кредитлар, депозитлар һәм карталар."
|
||||
},
|
||||
{
|
||||
"name": "РБК Банк",
|
||||
"description": "Казан шәһәрендә офислары һәм банкоматлары булган Россия банкы. Кредитлар, карталар, депозитлар һәм бизнеска хезмәт күрсәтү тәкъдим итә."
|
||||
},
|
||||
{
|
||||
"name": "Санкт-Петербург Банкы",
|
||||
"description": "Казан шәһәрендә дә хезмәт күрсәткән җирле банк. Ул шәхси затлар һәм бизнес өчен киң банк продуктлары сайлау тәкъдим итә."
|
||||
}
|
||||
],
|
||||
"hospitals": [
|
||||
{
|
||||
"name": "Казан шәһәр клиник хастаханәсе №1",
|
||||
"description": "Казанның иң зур күппрофильле хастаханәләренең берсе, хирургия, травматология, неврология, кардиология һәм башка медицина юнәлешләре буенча хезмәтләр тәкъдим итә. Замана технологияләре һәм югары квалификацияле персонал."
|
||||
},
|
||||
{
|
||||
"name": "Республиканың клиник хастаханәсе",
|
||||
"description": "Татарстан Республикасы өчен төп медицина оешмасы, зур спектрдагы хезмәтләрне тәкъдим итә, шул исәптән ашыгыч ярдәм, югары технологияле операцияләр һәм диагностика."
|
||||
},
|
||||
{
|
||||
"name": "Шәһәр хастаханәсе №7",
|
||||
"description": "Терапевтик, хирургик һәм реанимация медицинасы өлкәсендә медицина ярдәме күрсәтүгә махсуслашкан хастаханә. Хастаханәдә тәҗрибәле белгечләр эшли, заманча дәвалау ысуллары кулланыла."
|
||||
},
|
||||
{
|
||||
"name": "Казан балалар клиник хастаханәсе",
|
||||
"description": "Балалар өчен профильле медицина учреждениесе, педиатрия, хирургия, кардиология һәм башка юнәлешләр буенча хезмәтләр тәкъдим итә."
|
||||
},
|
||||
{
|
||||
"name": "Казан онкология диспансеры",
|
||||
"description": "Онкологик авыруларны дәвалауга махсуслашкан медицина учреждениесе. Рак диагнозын һәм дәвалауны үткәрүдә заманча ысуллар кулланыла, шул исәптән химиотерапия, радиотерапия һәм операцияләр."
|
||||
},
|
||||
{
|
||||
"name": "Шәһәр хастаханәсе №18",
|
||||
"description": "Күппрофильле медицина учреждениесе, төрле медицина өлкәләрендә дәвалау тәкъдим итә, шул исәптән травматология, неврология һәм кардиология. Хастаханәдә авыр авырулардан соң реабилитация бүлекләре бар."
|
||||
},
|
||||
{
|
||||
"name": "Ветераннар өчен республика хастаханәсе",
|
||||
"description": "Бөек Ватан сугышы ветераннарына, инвалидларга һәм картларга махсус медицина ярдәме күрсәтүче учреждение. Шулай ук хроник авырулары булган гражданнар өчен хезмәтләр тәкъдим итә."
|
||||
}
|
||||
],
|
||||
"pharmacies": [
|
||||
{
|
||||
"name": "Аптека 36,6",
|
||||
"description": "Дәреслекләр, витаминнар, косметика һәм сәламәтлек товарларының киң ассортименты булган аптека челтәре. Лояльлек программалары һәм онлайн-заказлар клиентлар өчен уңайлы."
|
||||
},
|
||||
{
|
||||
"name": "Ригла",
|
||||
"description": "Россиядәге иң зур аптекалар челтәрләренең берсе. Дәреслекләр, медицина товарлары һәм косметика тәкъдим итә. Шулай ук интернет аша заказ бирү мөмкинлеге бар."
|
||||
},
|
||||
{
|
||||
"name": "Здоровая семья",
|
||||
"description": "Дәреслекләр һәм сәламәтлек товарлары, шул исәптән медицина техникасы сатуга юнәлдерелгән аптека челтәре. Популяр товарларга акцияләр һәм ташламалар еш үткәрелә."
|
||||
},
|
||||
{
|
||||
"name": "Аптечная сеть 'А5'",
|
||||
"description": "Дәреслекләр, витаминнар, косметика һәм балалар товарларының киң ассортименты булган аптека челтәре. Уңайлы җибәрү һәм онлайн-заказлар хезмәтләре."
|
||||
},
|
||||
{
|
||||
"name": "Аптека 'Самсон-Фарма'",
|
||||
"description": "Дәреслекләр һәм сәламәтлек товарлары тәкъдим итә торган аптека челтәре. Аптекалар даими клиентлар өчен скидкалар һәм бонуслар тәкъдим итә."
|
||||
},
|
||||
{
|
||||
"name": "Аптечная сеть 'Цветной'",
|
||||
"description": "Уңайлы урнашкан һәм сыйфатлы хезмәт күрсәтү белән танылган аптекалар. Дәреслекләр, витаминнар, үз-үзеңне карау товарлары һәм медицина техникасы сатыла."
|
||||
},
|
||||
{
|
||||
"name": "Аптека 'Доктор Столетов'",
|
||||
"description": "Фармацевтик продукция, медицина товарлары һәм косметика сату белән шөгыльләнгән аптека челтәре. Уңайлы хезмәт һәм клиентлар өчен акцияләр."
|
||||
}
|
||||
],
|
||||
"airports": [
|
||||
{
|
||||
"name": "Казан Халыкара Аэропорты",
|
||||
"description": "Казанның төп аэропорты, халыкара һәм эчке рейсларны башкаручы. Аэропорт заманча терминаллар, уңайлы көтү зоналары, кибетләр һәм рестораннар белән җиһазландырылган. Ул Поволжье төбәгендә иң зур аэропортларның берсе һәм Татарстан өчен мөһим транспорт узелы."
|
||||
},
|
||||
{
|
||||
"name": "Казан-2 (эшләгән вакытта)",
|
||||
"description": "Элекке эчке рейслар һәм хәрби кирәклекләр өчен кулланылган аэропорт. Хәзерге вакытта тулы көченә эшләми, чөнки барлык пассажир рейслары Казан Халыкара Аэропортына күчерелгән. Аэропорт бинасы коммерция авиаперевозкалары өчен ябык."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -788,5 +788,121 @@
|
||||
"image_url": "w_six"
|
||||
}
|
||||
]
|
||||
},
|
||||
"history": {
|
||||
"intro_text": "Let's see how well you know UNICS!",
|
||||
"intro_image": "culture",
|
||||
"questions": [
|
||||
{
|
||||
"question": "When was Kazan founded?",
|
||||
"options": [
|
||||
"1005",
|
||||
"1156",
|
||||
"1230",
|
||||
"1323"
|
||||
],
|
||||
"correct_answer": "1005",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "What is the main river flowing through Kazan?",
|
||||
"options": [
|
||||
"Volga",
|
||||
"Kazanka",
|
||||
"Kama",
|
||||
"Izh"
|
||||
],
|
||||
"correct_answer": "Kazanka",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Who was the first khan of Kazan?",
|
||||
"options": [
|
||||
"Ulugh Muhammad",
|
||||
"Akhmat",
|
||||
"Shah Ali",
|
||||
"Mamuka"
|
||||
],
|
||||
"correct_answer": "Ulugh Muhammad",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "What is the name of Kazan's main sports complex where the 2013 Universiade was held?",
|
||||
"options": [
|
||||
"Kazan Arena",
|
||||
"Tatneft Arena",
|
||||
"Bugulma Arena",
|
||||
"Ak Bars Sports Palace"
|
||||
],
|
||||
"correct_answer": "Kazan Arena",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Which mosque in Kazan is considered one of the largest in Russia?",
|
||||
"options": [
|
||||
"Kul Sharif Mosque",
|
||||
"Mari El Mosque",
|
||||
"Aisha Mosque",
|
||||
"Imam Muhammad Mosque"
|
||||
],
|
||||
"correct_answer": "Kul Sharif Mosque",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "What is the name of the square where the Kazan Kremlin and Kul Sharif Mosque are located?",
|
||||
"options": [
|
||||
"Vakhitov Square",
|
||||
"Freedom Square",
|
||||
"Kremlin Square",
|
||||
"Revolution Square"
|
||||
],
|
||||
"correct_answer": "Kremlin Square",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "What symbol of Kazan is depicted on the city's coat of arms?",
|
||||
"options": [
|
||||
"Dragon",
|
||||
"Tiger",
|
||||
"Lion",
|
||||
"Eagle"
|
||||
],
|
||||
"correct_answer": "Dragon",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Who was the architect of the Kazan Kremlin?",
|
||||
"options": [
|
||||
"Ivan Zarudny",
|
||||
"Fyodor Benjamin",
|
||||
"Andrey Ushakov",
|
||||
"Yury Dashevsky"
|
||||
],
|
||||
"correct_answer": "Andrey Ushakov",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Which of these universities is located in Kazan?",
|
||||
"options": [
|
||||
"Moscow State University",
|
||||
"Kazan Federal University",
|
||||
"St. Petersburg Polytechnic University",
|
||||
"Novosibirsk State University"
|
||||
],
|
||||
"correct_answer": "Kazan Federal University",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "What is the name of the largest street in Kazan, which is also the center of the city's nightlife?",
|
||||
"options": [
|
||||
"Kremlin Street",
|
||||
"Bauman Street",
|
||||
"Pushkin Street",
|
||||
"Kayum Nasyri Street"
|
||||
],
|
||||
"correct_answer": "Bauman Street",
|
||||
"image_url": "culture"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -788,5 +788,121 @@
|
||||
"image_url": "w_six"
|
||||
}
|
||||
]
|
||||
},
|
||||
"history": {
|
||||
"intro_text": "Давайте узнаем, насколько вы хорошо знаете историю Казани!",
|
||||
"intro_image": "culture",
|
||||
"questions": [
|
||||
{
|
||||
"question": "Когда Казань была основана?",
|
||||
"options": [
|
||||
"1000 год",
|
||||
"1156 год",
|
||||
"1230 год",
|
||||
"1323 год"
|
||||
],
|
||||
"correct_answer": "1000 год",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Как называется главная река, протекающая через Казань?",
|
||||
"options": [
|
||||
"Волга",
|
||||
"Казанка",
|
||||
"Кама",
|
||||
"Иж"
|
||||
],
|
||||
"correct_answer": "Казанка",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Кто был первым казанским ханом?",
|
||||
"options": [
|
||||
"Улу-Мухаммед",
|
||||
"Ахмат",
|
||||
"Шах-Али",
|
||||
"Мамука"
|
||||
],
|
||||
"correct_answer": "Улу-Мухаммед",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Как называется главный спортивный комплекс Казани, где проводились Универсиада 2013 года?",
|
||||
"options": [
|
||||
"Казан Арена",
|
||||
"Татнефть Арена",
|
||||
"Бугульминская арена",
|
||||
"Дворец спорта \"Ак Барс\""
|
||||
],
|
||||
"correct_answer": "Казан Арена",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Какая мечеть в Казани считается одной из самых больших в России?",
|
||||
"options": [
|
||||
"Мечеть Кул Шариф",
|
||||
"Мечеть Марий Эл",
|
||||
"Мечеть Айша",
|
||||
"Мечеть имама Мухаммада"
|
||||
],
|
||||
"correct_answer": "Мечеть Кул Шариф",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Как называется площадь, на которой расположены Казанский Кремль и мечеть Кул Шариф?",
|
||||
"options": [
|
||||
"Площадь Вахитова",
|
||||
"Площадь Свободы",
|
||||
"Площадь Кремля",
|
||||
"Площадь Революции"
|
||||
],
|
||||
"correct_answer": "Площадь Кремля",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Какой символ Казани изображён на гербе города?",
|
||||
"options": [
|
||||
"Дракон",
|
||||
"Тигр",
|
||||
"Лев",
|
||||
"Орел"
|
||||
],
|
||||
"correct_answer": "Дракон",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Какой архитектор спроектировал Казанский Кремль?",
|
||||
"options": [
|
||||
"Иван Зарудный",
|
||||
"Фёдор Бенжамин",
|
||||
"Андрей Ушаков",
|
||||
"Юрий Дашевский"
|
||||
],
|
||||
"correct_answer": "Андрей Ушаков",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Какой из этих вузов находится в Казани?",
|
||||
"options": [
|
||||
"Московский государственный университет",
|
||||
"Казанский федеральный университет",
|
||||
"Санкт-Петербургский политехнический университет",
|
||||
"Новосибирский государственный университет"
|
||||
],
|
||||
"correct_answer": "Казанский федеральный университет",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Как называется крупнейшая в Казани улица, которая также является центром ночной жизни города?",
|
||||
"options": [
|
||||
"Кремлевская улица",
|
||||
"Баумана улица",
|
||||
"Пушкина улица",
|
||||
"Каюма Насыри улица"
|
||||
],
|
||||
"correct_answer": "Баумана улица",
|
||||
"image_url": "culture"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -788,5 +788,121 @@
|
||||
"image_url": "w_six"
|
||||
}
|
||||
]
|
||||
},
|
||||
"history": {
|
||||
"intro_text": "Әйдәгез, Казан тарихын белүегезне ачыклыйк!",
|
||||
"intro_image": "culture",
|
||||
"questions": [
|
||||
{
|
||||
"question": "Казан кайчан нигезләнгән?",
|
||||
"options": [
|
||||
"1000 ел",
|
||||
"1156 ел",
|
||||
"1230 ел",
|
||||
"1323 ел"
|
||||
],
|
||||
"correct_answer": "1000 ел",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Казан аша агучы төп елга ничек атала?",
|
||||
"options": [
|
||||
"Идел",
|
||||
"Казанка",
|
||||
"Кама",
|
||||
"Иж"
|
||||
],
|
||||
"correct_answer": "Казанка",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Казанның беренче ханы кем булган?",
|
||||
"options": [
|
||||
"Олуг Мөхәммәт",
|
||||
"Әхмәт",
|
||||
"Шаһ-Әли",
|
||||
"Мамука"
|
||||
],
|
||||
"correct_answer": "Олуг Мөхәммәт",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "2013 елда Универсиада узган Казанның төп спорт комплексы ничек атала?",
|
||||
"options": [
|
||||
"Казан Арена",
|
||||
"Татнефть Арена",
|
||||
"Бөгелмә Арена",
|
||||
"Ак Барс спорт сарае"
|
||||
],
|
||||
"correct_answer": "Казан Арена",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Казандагы иң зур мәчетләрнең берсе Россиядәге кайсысы?",
|
||||
"options": [
|
||||
"Кол Шәриф мәчете",
|
||||
"Марий Эл мәчете",
|
||||
"Айша мәчете",
|
||||
"Имам Мөхәммәт мәчете"
|
||||
],
|
||||
"correct_answer": "Кол Шәриф мәчете",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Казан Кремле һәм Кол Шәриф мәчете урнашкан мәйдан ничек атала?",
|
||||
"options": [
|
||||
"Вахитов мәйданы",
|
||||
"Ирек мәйданы",
|
||||
"Кремль мәйданы",
|
||||
"Революция мәйданы"
|
||||
],
|
||||
"correct_answer": "Кремль мәйданы",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Казан гербында кайсы символ сурәтләнгән?",
|
||||
"options": [
|
||||
"Аждаһа",
|
||||
"Юлбарыс",
|
||||
"Арслан",
|
||||
"Бүре"
|
||||
],
|
||||
"correct_answer": "Аждаһа",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Казан Кремленең архитекторын атагыз.",
|
||||
"options": [
|
||||
"Иван Зарудный",
|
||||
"Фёдор Бенжамин",
|
||||
"Андрей Ушаков",
|
||||
"Юрий Дашевский"
|
||||
],
|
||||
"correct_answer": "Андрей Ушаков",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Бу югары уку йортларының кайсысы Казанда урнашкан?",
|
||||
"options": [
|
||||
"Мәскәү дәүләт университеты",
|
||||
"Казан федераль университеты",
|
||||
"Санкт-Петербург политехник университеты",
|
||||
"Новосибирск дәүләт университеты"
|
||||
],
|
||||
"correct_answer": "Казан федераль университеты",
|
||||
"image_url": "culture"
|
||||
},
|
||||
{
|
||||
"question": "Казандагы иң зур урам ничек атала? Ул шулай ук шәһәрнең төнге тормыш үзәге булып тора.",
|
||||
"options": [
|
||||
"Кремль урамы",
|
||||
"Бауман урамы",
|
||||
"Пушкин урамы",
|
||||
"Каюм Насыйри урамы"
|
||||
],
|
||||
"correct_answer": "Бауман урамы",
|
||||
"image_url": "culture"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
27
server/routers/kazan-explore/model/results.js
Normal file
27
server/routers/kazan-explore/model/results.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
|
||||
const { KAZAN_EXPLORE_RESULTS_MODEL_NAME } = require('../const')
|
||||
|
||||
const schema = new Schema({
|
||||
userId: { type: String },
|
||||
items: [
|
||||
{
|
||||
quizId: { type: String },
|
||||
result: { type: Number }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
transform: function (doc, ret) {
|
||||
delete ret._id
|
||||
}
|
||||
})
|
||||
|
||||
schema.virtual('id').get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
|
||||
exports.ResultsModel = model(KAZAN_EXPLORE_RESULTS_MODEL_NAME, schema)
|
||||
1
server/routers/kfu-m-24-1/back-new/.env
Normal file
1
server/routers/kfu-m-24-1/back-new/.env
Normal file
@@ -0,0 +1 @@
|
||||
GIGACHAT_API_KEY=NzgzNTkxMjMtNDQ0Ny00ODFhLTkwMjgtODYxZjUzYjI0ZWQxOjA5NDEwMzEwLTM5YjItNDUzOS1hYWYzLWE4ZDA1MDExNmQ4Nw==
|
||||
2
server/routers/kfu-m-24-1/back-new/.gitignore
vendored
Normal file
2
server/routers/kfu-m-24-1/back-new/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
.env
|
||||
21
server/routers/kfu-m-24-1/back-new/README.md
Normal file
21
server/routers/kfu-m-24-1/back-new/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# back-new
|
||||
|
||||
非Python实现的后端(Node.js + Express)
|
||||
|
||||
## 启动方法
|
||||
|
||||
1. 安装依赖:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
2. 启动服务:
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
默认端口:`3002`
|
||||
|
||||
## 支持接口
|
||||
- POST `/api/auth/login` 用户登录
|
||||
- POST `/api/auth/register` 用户注册
|
||||
- GET `/gigachat/prompt?prompt=xxx` 生成图片(返回模拟图片链接)
|
||||
24
server/routers/kfu-m-24-1/back-new/app.js
Normal file
24
server/routers/kfu-m-24-1/back-new/app.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const featuresConfig = require('./features.config');
|
||||
const imageRoutes = require('./features/image/image.routes');
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
if (featuresConfig.auth) {
|
||||
app.use('/api/auth', require('./features/auth/auth.routes'));
|
||||
}
|
||||
if (featuresConfig.user) {
|
||||
app.use('/api/user', require('./features/user/user.routes'));
|
||||
}
|
||||
if (featuresConfig.image) {
|
||||
app.use('/gigachat', imageRoutes);
|
||||
}
|
||||
|
||||
app.get('/api/', (req, res) => {
|
||||
res.json({ message: 'API root' });
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
5
server/routers/kfu-m-24-1/back-new/features.config.js
Normal file
5
server/routers/kfu-m-24-1/back-new/features.config.js
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
auth: true,
|
||||
user: true,
|
||||
image: true, // 关闭为 false
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
const usersDb = require('../../shared/usersDb');
|
||||
const makeLinks = require('../../shared/hateoas');
|
||||
|
||||
exports.login = (req, res) => {
|
||||
const { username, password, email } = req.body;
|
||||
const user = usersDb.findUser(username, email, password);
|
||||
if (user) {
|
||||
res.json({
|
||||
data: {
|
||||
user: {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName
|
||||
},
|
||||
token: 'token-' + user.id,
|
||||
message: 'Login successful'
|
||||
},
|
||||
_links: makeLinks('/api/auth', {
|
||||
self: '/login',
|
||||
profile: '/profile/',
|
||||
logout: '/logout'
|
||||
}),
|
||||
_meta: {}
|
||||
});
|
||||
} else {
|
||||
res.status(401).json({ error: 'Invalid credentials' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.register = (req, res) => {
|
||||
const { username, password, email, firstName, lastName } = req.body;
|
||||
if (usersDb.exists(username, email)) {
|
||||
return res.status(409).json({ error: 'User already exists' });
|
||||
}
|
||||
const newUser = usersDb.addUser({ username, password, email, firstName, lastName });
|
||||
res.json({
|
||||
data: {
|
||||
user: {
|
||||
id: newUser.id,
|
||||
username,
|
||||
email,
|
||||
firstName,
|
||||
lastName
|
||||
},
|
||||
token: 'token-' + newUser.id,
|
||||
message: 'Register successful'
|
||||
},
|
||||
_links: makeLinks('/api/auth', {
|
||||
self: '/register',
|
||||
login: '/login',
|
||||
profile: '/profile/'
|
||||
}),
|
||||
_meta: {}
|
||||
});
|
||||
};
|
||||
|
||||
exports.profile = (req, res) => {
|
||||
const auth = req.headers.authorization;
|
||||
if (!auth || !auth.startsWith('Bearer ')) {
|
||||
return res.status(401).json({ error: 'No token provided' });
|
||||
}
|
||||
const token = auth.replace('Bearer ', '');
|
||||
const id = parseInt(token.replace('token-', ''));
|
||||
const user = usersDb.findById(id);
|
||||
if (!user) {
|
||||
return res.status(401).json({ error: 'Invalid token' });
|
||||
}
|
||||
res.json({
|
||||
data: {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName
|
||||
},
|
||||
_links: makeLinks('/api/auth', {
|
||||
self: '/profile/',
|
||||
logout: '/logout'
|
||||
}),
|
||||
_meta: {}
|
||||
});
|
||||
};
|
||||
|
||||
exports.logout = (req, res) => {
|
||||
res.json({
|
||||
message: 'Logout successful',
|
||||
_links: makeLinks('/api/auth', {
|
||||
self: '/logout',
|
||||
login: '/login'
|
||||
}),
|
||||
_meta: {}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const ctrl = require('./auth.controller');
|
||||
|
||||
router.post('/login', ctrl.login);
|
||||
router.post('/register', ctrl.register);
|
||||
router.get('/profile/', ctrl.profile);
|
||||
router.post('/logout', ctrl.logout);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,81 @@
|
||||
const axios = require('axios');
|
||||
const makeLinks = require('../../shared/hateoas');
|
||||
const path = require('path');
|
||||
const qs = require('qs');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') });
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
|
||||
exports.generate = async (req, res) => {
|
||||
const { prompt } = req.query;
|
||||
if (!prompt) {
|
||||
return res.status(400).json({ error: 'Prompt parameter is required' });
|
||||
}
|
||||
try {
|
||||
const apiKey = process.env.GIGACHAT_API_KEY;
|
||||
const tokenResp = await axios.post(
|
||||
'https://ngw.devices.sberbank.ru:9443/api/v2/oauth',
|
||||
{
|
||||
'scope':' GIGACHAT_API_PERS',
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `Basic ${apiKey}`,
|
||||
'RqUID':'6f0b1291-c7f3-43c6-bb2e-9f3efb2dc98e'
|
||||
},
|
||||
}
|
||||
);
|
||||
const accessToken = tokenResp.data.access_token;
|
||||
const chatResp = await axios.post(
|
||||
'https://gigachat.devices.sberbank.ru/api/v1/chat/completions',
|
||||
{
|
||||
model: "GigaChat",
|
||||
messages: [
|
||||
{ role: "system", content: "Ты — Василий Кандинский" },
|
||||
{ role: "user", content: prompt }
|
||||
],
|
||||
stream: false,
|
||||
function_call: 'auto'
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
'RqUID': uuidv4(),
|
||||
}
|
||||
}
|
||||
);
|
||||
const content = chatResp.data.choices[0].message.content;
|
||||
const match = content.match(/<img src=\"(.*?)\"/);
|
||||
if (!match) {
|
||||
return res.status(500).json({ error: 'No image generated' });
|
||||
}
|
||||
const imageId = match[1];
|
||||
const imageResp = await axios.get(
|
||||
`https://gigachat.devices.sberbank.ru/api/v1/files/${imageId}/content`,
|
||||
{
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`,
|
||||
'RqUID': uuidv4(),
|
||||
},
|
||||
responseType: 'arraybuffer'
|
||||
}
|
||||
);
|
||||
res.set('Content-Type', 'image/jpeg');
|
||||
res.set('X-HATEOAS', JSON.stringify(makeLinks('/gigachat', { self: '/prompt' })));
|
||||
res.send(imageResp.data);
|
||||
} catch (err) {
|
||||
if (err.response) {
|
||||
console.error('AI生成图片出错:');
|
||||
console.error('status:', err.response.status);
|
||||
console.error('headers:', err.response.headers);
|
||||
console.error('data:', err.response.data);
|
||||
console.error('config:', err.config);
|
||||
} else {
|
||||
console.error('AI生成图片出错:', err.message);
|
||||
}
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const ctrl = require('./image.controller');
|
||||
|
||||
router.get('/prompt', ctrl.generate);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,12 @@
|
||||
const usersDb = require('../../shared/usersDb');
|
||||
const makeLinks = require('../../shared/hateoas');
|
||||
|
||||
exports.list = (req, res) => {
|
||||
res.json({
|
||||
data: usersDb.getAll(),
|
||||
_links: makeLinks('/api/user', {
|
||||
self: '/list',
|
||||
}),
|
||||
_meta: {}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const ctrl = require('./user.controller');
|
||||
|
||||
router.get('/list', ctrl.list);
|
||||
|
||||
module.exports = router;
|
||||
5455
server/routers/kfu-m-24-1/back-new/package-lock.json
generated
Normal file
5455
server/routers/kfu-m-24-1/back-new/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
server/routers/kfu-m-24-1/back-new/package.json
Normal file
21
server/routers/kfu-m-24-1/back-new/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "back-new",
|
||||
"version": "1.0.0",
|
||||
"description": "非Python实现的后端,兼容前端接口",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.10.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.0.0",
|
||||
"express": "^4.21.2",
|
||||
"qs": "^6.14.0",
|
||||
"uuid": "^11.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^30.0.3"
|
||||
}
|
||||
}
|
||||
5
server/routers/kfu-m-24-1/back-new/server.js
Normal file
5
server/routers/kfu-m-24-1/back-new/server.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const app = require('./app');
|
||||
const PORT = process.env.PORT || 3002;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Mock backend running on https://dev.bro.js.ru/ms/back-new/${PORT}`);
|
||||
});
|
||||
8
server/routers/kfu-m-24-1/back-new/shared/hateoas.js
Normal file
8
server/routers/kfu-m-24-1/back-new/shared/hateoas.js
Normal file
@@ -0,0 +1,8 @@
|
||||
function makeLinks(base, links) {
|
||||
const result = {};
|
||||
for (const [rel, path] of Object.entries(links)) {
|
||||
result[rel] = { href: base + path };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
module.exports = makeLinks;
|
||||
20
server/routers/kfu-m-24-1/back-new/shared/usersDb.js
Normal file
20
server/routers/kfu-m-24-1/back-new/shared/usersDb.js
Normal file
@@ -0,0 +1,20 @@
|
||||
let users = [
|
||||
{ id: 1, username: 'test', password: '123456', email: 'test@example.com', firstName: 'Test', lastName: 'User' }
|
||||
];
|
||||
let nextId = 2;
|
||||
|
||||
exports.findUser = (username, email, password) =>
|
||||
users.find(u => (u.username === username || u.email === email) && u.password === password);
|
||||
|
||||
exports.findById = (id) => users.find(u => u.id === id);
|
||||
|
||||
exports.addUser = ({ username, password, email, firstName, lastName }) => {
|
||||
const newUser = { id: nextId++, username, password, email, firstName, lastName };
|
||||
users.push(newUser);
|
||||
return newUser;
|
||||
};
|
||||
|
||||
exports.exists = (username, email) =>
|
||||
users.some(u => u.username === username || u.email === email);
|
||||
|
||||
exports.getAll = () => users;
|
||||
@@ -1,17 +0,0 @@
|
||||
[
|
||||
{
|
||||
"id": 0,
|
||||
"description": "10 часто используемых",
|
||||
"imageFilename": "kart1.jpg"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"description": "10 слов в Data Science",
|
||||
"imageFilename": "kart1.jpg"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"description": "IT Basics Dictionary",
|
||||
"imageFilename": "kart1.jpg"
|
||||
}
|
||||
]
|
||||
@@ -6,18 +6,14 @@
|
||||
"id": 0,
|
||||
"word": "Tech",
|
||||
"definition": "short for technical, relating to the knowledge, machines, or methods used in science and industry. Tech is a whole industry, which includes IT",
|
||||
"examples": [
|
||||
"“As a DevOps engineer I have been working in Tech since 2020.”"
|
||||
],
|
||||
"examples": ["“As a DevOps engineer I have been working in Tech since 2020.”"],
|
||||
"synonyms": ["IT"]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"word": "career path",
|
||||
"definition": "the series of jobs or roles that constitute a person's career, especially one in a particular field",
|
||||
"examples": [
|
||||
"“Technology is an evolving field with a variety of available career paths.”"
|
||||
],
|
||||
"examples": ["“Technology is an evolving field with a variety of available career paths.”"],
|
||||
"synonyms": []
|
||||
}
|
||||
]
|
||||
@@ -146,130 +142,5 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"words": [
|
||||
{
|
||||
"id": 0,
|
||||
"word": "software",
|
||||
"translation": "программное обеспечение",
|
||||
"definition": "A collection of computer instructions that perform a specific task, typically for use by humans or machines.",
|
||||
"synonyms": ["код", "приложение", "управление программами"],
|
||||
"examples":
|
||||
[
|
||||
"I need to update the software on my new laptop.",
|
||||
"The company uses Windows as its operating system."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"word": "hardware",
|
||||
"translation": "железо",
|
||||
"definition": "Physical components of a computer that process information, including processors and storage devices.",
|
||||
"synonyms": ["equipment", "приборы", "оборудование"],
|
||||
"examples":
|
||||
[
|
||||
"The keyboard is part of the hardware on this device.",
|
||||
"They upgraded their router to improve internet speed."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"word": "network",
|
||||
"translation": "сети",
|
||||
"definition": "A system of interconnected devices that communicate with each other through data transmission over a networked medium.",
|
||||
"synonyms": ["трансляция", "коммуникации", "диалог"],
|
||||
"examples":
|
||||
[
|
||||
"We use the internet to connect our devices in the same area.",
|
||||
"The company relies on their internal network for data sharing."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"word": "algorithm",
|
||||
"translation": "алгоритм",
|
||||
"definition": "A set of instructions that a computer follows to solve a problem or achieve a specific task.",
|
||||
"synonyms": ["процесс", "схема", "текст"],
|
||||
"examples":
|
||||
[
|
||||
"The algorithm for sorting numbers is easy to follow.",
|
||||
"The new software includes an advanced algorithm."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"word": "encryption",
|
||||
"translation": "криптография",
|
||||
"definition": "A technique that transforms information into a secure form, making it unreadable without the appropriate key.",
|
||||
"synonyms": ["шифрование", "окрышение", "опциональное"],
|
||||
"examples":
|
||||
[
|
||||
"Our data is encrypted to ensure its privacy and security.",
|
||||
"I need to use an encryption program for my important documents."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"word": "debugging",
|
||||
"translation": "поиск и исправление ошибок",
|
||||
"definition": "The process of identifying and correcting errors or defects in a computer program.",
|
||||
"synonyms": ["исправление", "сканирование", "анализ"],
|
||||
"examples":
|
||||
[
|
||||
"I need to debug the code for this new project.",
|
||||
"We use automated tools to find bugs."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"word": "API",
|
||||
"translation": "интерфейс приложения",
|
||||
"definition": "A set of rules and protocols that enables communication between software applications, typically over a network.",
|
||||
"synonyms": ["серверное программирование", "функциональная структура"],
|
||||
"examples":
|
||||
[
|
||||
"We use the API for our mobile app to access data from the backend server.",
|
||||
"I need to write an API for connecting my devices to the internet."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"word": "virtual",
|
||||
"translation": "виртуальный",
|
||||
"definition": "A representation of a thing that does not exist physically but exists in digital form.",
|
||||
"synonyms": ["высокопроизводительный", "представление", "цифровой"],
|
||||
"examples":
|
||||
[
|
||||
"I use virtual reality to experience different environments.",
|
||||
"Our company offers virtual office spaces for remote work."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"word": "infrastructure",
|
||||
"translation": "инфраструктура",
|
||||
"definition": "The underlying systems and equipment of a computer network or organization, including hardware, software, and physical connections.",
|
||||
"synonyms": ["оборудование", "устройство", "системы"],
|
||||
"examples":
|
||||
[
|
||||
"Our IT infrastructure is robust to ensure reliable operations.",
|
||||
"They need to improve their internet infrastructure for better connectivity."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"word": "hacker",
|
||||
"translation": "хакер",
|
||||
"definition": "A skilled individual who uses computer technology to break into and misuse a system or network.",
|
||||
"synonyms": ["дезориентированный", "манипулятор", "прокурор"],
|
||||
"examples":
|
||||
[
|
||||
"I need to avoid getting involved with hackers.",
|
||||
"They were caught hacking into the company's confidential database."
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"description": "10 слов в Data Science",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"description": "Job Interview",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"description": "ReactJS",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"description": "NodeJS",
|
||||
"imageFilename": "kart1.jpg",
|
||||
"words": [33, 34, 35, 36, 37, 38, 39, 40, 41, 42]
|
||||
}
|
||||
]
|
||||
@@ -1,42 +1,99 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const router = require("express").Router();
|
||||
const router = require('express').Router();
|
||||
|
||||
module.exports = router;
|
||||
|
||||
const data = require("./data/dictionaries.json");
|
||||
const wordsData = require("./data/dictionaryWords.json");
|
||||
const dictionaries = require('./dictionaries.json');
|
||||
const words = require('../words/words.json');
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
res.send(data);
|
||||
router.get('/', (req, res) => {
|
||||
res.send(dictionaries);
|
||||
});
|
||||
|
||||
// Put new dictionary to the array of dictionaries
|
||||
router.put('/new', (req, res) => {
|
||||
if (!data || !Array.isArray(data)) {
|
||||
return res.status(400).send('No array of dictionaries found`');
|
||||
router.get('/:id', (req, res) => {
|
||||
const id = parseInt(req.params.id);
|
||||
if (!id || isNaN(id)) {
|
||||
return res.status(400).send('Invalid ID'); // Bad request
|
||||
}
|
||||
|
||||
const updatedData = req.body;
|
||||
|
||||
if (!updatedData) {
|
||||
return res.status(400).send('No data to update'); // Bad request
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
if (!dictionaries) {
|
||||
return res.status(500).send('No data to update'); // Internal server error
|
||||
}
|
||||
|
||||
const indexedUpdatedData = { id: data.length, ...updatedData }; // Add the new dictionary to the array
|
||||
const dictionary = dictionaries.find((dictionary) => dictionary.id === id);
|
||||
|
||||
data.push(indexedUpdatedData); // Add the new dictionary to the array
|
||||
if (!dictionary) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
const dictionaryWords = dictionary.words.map((wordId) => {
|
||||
const word = words.find((word) => word.id === wordId);
|
||||
return { ...word, ...word };
|
||||
});
|
||||
res.send({ ...dictionary, words: dictionaryWords });
|
||||
});
|
||||
|
||||
fs.writeFile(path.join(__dirname, 'data/dictionaries.json'), JSON.stringify(data), (err) => {
|
||||
router.post('/:id', (req, res) => {
|
||||
const id = parseInt(req.params.id);
|
||||
if (!id || isNaN(id)) {
|
||||
return res.status(400).send('Invalid ID'); // Bad request
|
||||
}
|
||||
|
||||
if (!dictionaries) {
|
||||
return res.status(500).send('No data to update'); // Internal server error
|
||||
}
|
||||
|
||||
const dictionary = dictionaries.find((dictionary) => dictionary.id === id);
|
||||
|
||||
if (!dictionary) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
|
||||
const newWord = req.body;
|
||||
if (!newWord) {
|
||||
return res.status(400).send('No data to add'); // Bad request
|
||||
}
|
||||
console.log(newWord);
|
||||
if (isNaN(newWord.id)) {
|
||||
return res.status(400).send('Invalid word ID'); // Bad request
|
||||
}
|
||||
dictionary.words.push(newWord.id);
|
||||
|
||||
fs.writeFile(path.join(__dirname, 'dictionaries.json'), JSON.stringify(dictionaries), (err) => {
|
||||
if (err) {
|
||||
console.error(err); // Log the error
|
||||
return res.status(500).send('Error saving data');
|
||||
}
|
||||
res.status(200).json(data); // Send back the updated data
|
||||
res.status(200).json(dictionary); // Send back the updated data
|
||||
});
|
||||
});
|
||||
|
||||
// Put new dictionary to the array of dictionaries
|
||||
router.put('/', (req, res) => {
|
||||
if (!dictionaries || !Array.isArray(dictionaries)) {
|
||||
return res.status(400).send('No array of dictionaries found`');
|
||||
}
|
||||
|
||||
const newData = req.body;
|
||||
|
||||
if (!newData) {
|
||||
return res.status(400).send('No data to add'); // Bad request
|
||||
}
|
||||
|
||||
if (!dictionaries) {
|
||||
return res.status(500).send('No data to update'); // Internal server error
|
||||
}
|
||||
|
||||
const indexedUpdatedData = { ...newData, id: dictionaries.length + 1 }; // Add the new dictionary to the array
|
||||
|
||||
dictionaries.push(indexedUpdatedData); // Add the new dictionary to the array
|
||||
|
||||
fs.writeFile(path.join(__dirname, 'dictionaries.json'), JSON.stringify(dictionaries), (err) => {
|
||||
if (err) {
|
||||
console.error(err); // Log the error
|
||||
return res.status(500).send('Error saving data');
|
||||
}
|
||||
res.status(200).json(dictionaries); // Send back the updated data
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,15 +104,15 @@ router.delete('/:id', (req, res) => {
|
||||
return res.status(400).send('Invalid ID'); // Bad request
|
||||
}
|
||||
|
||||
const index = data.findIndex((dictionary) => dictionary.id === id);
|
||||
const index = dictionaries.findIndex((dictionary) => dictionary.id === id);
|
||||
|
||||
if (index < 0) {
|
||||
return res.status(404).send('Not found'); // Not found
|
||||
}
|
||||
|
||||
data.splice(index, 1); // Remove the dictionary from the array
|
||||
dictionaries.splice(index, 1); // Remove the dictionary from the array
|
||||
|
||||
fs.writeFile(path.join(__dirname, 'data/dictionaries.json'), JSON.stringify(data), (err) => {
|
||||
fs.writeFile(path.join(__dirname, 'dictionaries.json'), JSON.stringify(dictionaries), (err) => {
|
||||
if (err) {
|
||||
console.error(err); // Log the error
|
||||
return res.status(500).send('Error saving data');
|
||||
@@ -63,14 +120,3 @@ router.delete('/:id', (req, res) => {
|
||||
res.send({ message: `Dictionary with id ${id} deleted` });
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/:id", (req, res) => {
|
||||
const id = parseInt(req.params.id);
|
||||
const words = wordsData.find((word) => word.id === id);
|
||||
|
||||
if (!words) {
|
||||
return res.status(404).send("Not found");
|
||||
}
|
||||
|
||||
res.send(words);
|
||||
});
|
||||
|
||||
6192
server/routers/kfu-m-24-1/eng-it-lean/gigachat/ai.js
Normal file
6192
server/routers/kfu-m-24-1/eng-it-lean/gigachat/ai.js
Normal file
File diff suppressed because it is too large
Load Diff
613
server/routers/kfu-m-24-1/eng-it-lean/gigachat/gigachat.js
Normal file
613
server/routers/kfu-m-24-1/eng-it-lean/gigachat/gigachat.js
Normal file
@@ -0,0 +1,613 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
createGigachat: () => createGigachat,
|
||||
gigachat: () => gigachat
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
|
||||
// src/gigachat-provider.ts
|
||||
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
||||
|
||||
// src/gigachat-chat-language-model.ts
|
||||
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
||||
var import_zod2 = require("zod");
|
||||
|
||||
// src/convert-to-gigachat-chat-messages.ts
|
||||
var import_provider = require("@ai-sdk/provider");
|
||||
function convertToGigachatChatMessages(prompt) {
|
||||
const messages = [];
|
||||
for (let i = 0; i < prompt.length; i++) {
|
||||
const { role, content } = prompt[i];
|
||||
const isLastMessage = i === prompt.length - 1;
|
||||
switch (role) {
|
||||
case "system": {
|
||||
messages.push({ role: "system", content });
|
||||
break;
|
||||
}
|
||||
case "user": {
|
||||
messages.push({
|
||||
role: "user",
|
||||
content: content.map((part) => {
|
||||
switch (part.type) {
|
||||
case "text": {
|
||||
return part.text;
|
||||
}
|
||||
case "image": {
|
||||
throw new import_provider.UnsupportedFunctionalityError({
|
||||
functionality: 'Images should be added in "attachments" object'
|
||||
});
|
||||
}
|
||||
case "file": {
|
||||
throw new import_provider.UnsupportedFunctionalityError({
|
||||
functionality: "File content parts in user messages"
|
||||
});
|
||||
}
|
||||
}
|
||||
}).join("")
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "assistant": {
|
||||
let text = "";
|
||||
let functionCall;
|
||||
for (const part of content) {
|
||||
switch (part.type) {
|
||||
case "text": {
|
||||
text += part.text;
|
||||
break;
|
||||
}
|
||||
case "tool-call": {
|
||||
functionCall = {
|
||||
name: part.toolName,
|
||||
arguments: part.args
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
const _exhaustiveCheck = part;
|
||||
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
messages.push({
|
||||
role: "assistant",
|
||||
content: text,
|
||||
prefix: isLastMessage ? true : void 0,
|
||||
function_call: functionCall
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "tool": {
|
||||
for (const toolResponse of content) {
|
||||
messages.push({
|
||||
role: "function",
|
||||
name: toolResponse.toolName,
|
||||
content: JSON.stringify(toolResponse.result)
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
const _exhaustiveCheck = role;
|
||||
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
// src/map-gigachat-finish-reason.ts
|
||||
function mapGigachatFinishReason(finishReason) {
|
||||
switch (finishReason) {
|
||||
case "stop":
|
||||
return "stop";
|
||||
case "length":
|
||||
case "model_length":
|
||||
return "length";
|
||||
case "function_call":
|
||||
return "tool-calls";
|
||||
case "error":
|
||||
return "error";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
// src/gigachat-error.ts
|
||||
var import_provider_utils = require("@ai-sdk/provider-utils");
|
||||
var import_zod = require("zod");
|
||||
var gigachatErrorDataSchema = import_zod.z.object({
|
||||
object: import_zod.z.literal("error"),
|
||||
message: import_zod.z.string(),
|
||||
type: import_zod.z.string(),
|
||||
param: import_zod.z.string().nullable(),
|
||||
code: import_zod.z.string().nullable()
|
||||
});
|
||||
var gigachatFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
||||
errorSchema: gigachatErrorDataSchema,
|
||||
errorToMessage: (data) => data.message
|
||||
});
|
||||
|
||||
// src/get-response-metadata.ts
|
||||
function getResponseMetadata({
|
||||
model,
|
||||
created
|
||||
}) {
|
||||
return {
|
||||
modelId: model != null ? model : void 0,
|
||||
timestamp: created != null ? new Date(created * 1e3) : void 0
|
||||
};
|
||||
}
|
||||
|
||||
// src/gigachat-prepare-tools.ts
|
||||
var import_provider2 = require("@ai-sdk/provider");
|
||||
function prepareTools(mode) {
|
||||
var _a;
|
||||
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
||||
const toolWarnings = [];
|
||||
if (tools == null) {
|
||||
return { tools: void 0, tool_choice: void 0, toolWarnings };
|
||||
}
|
||||
const gigachatTools = [];
|
||||
for (const tool of tools) {
|
||||
if (tool.type === "provider-defined") {
|
||||
toolWarnings.push({ type: "unsupported-tool", tool });
|
||||
} else {
|
||||
gigachatTools.push({
|
||||
type: "function",
|
||||
function: {
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
parameters: tool.parameters
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
const toolChoice = mode.toolChoice;
|
||||
if (toolChoice == null) {
|
||||
return { tools: gigachatTools, tool_choice: void 0, toolWarnings };
|
||||
}
|
||||
const type = toolChoice.type;
|
||||
switch (type) {
|
||||
case "auto":
|
||||
case "none":
|
||||
return { tools: gigachatTools, tool_choice: type, toolWarnings };
|
||||
case "required":
|
||||
return { tools: gigachatTools, tool_choice: "any", toolWarnings };
|
||||
// gigachat does not support tool mode directly,
|
||||
// so we filter the tools and force the tool choice through 'any'
|
||||
case "tool":
|
||||
return {
|
||||
tools: gigachatTools.filter((tool) => tool.function.name === toolChoice.toolName),
|
||||
tool_choice: "any",
|
||||
toolWarnings
|
||||
};
|
||||
default: {
|
||||
const _exhaustiveCheck = type;
|
||||
throw new import_provider2.UnsupportedFunctionalityError({
|
||||
functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// src/gigachat-chat-language-model.ts
|
||||
var GigachatChatLanguageModel = class {
|
||||
constructor(modelId, settings, config) {
|
||||
this.specificationVersion = "v1";
|
||||
this.defaultObjectGenerationMode = "json";
|
||||
this.supportsImageUrls = false;
|
||||
this.modelId = modelId;
|
||||
this.settings = settings;
|
||||
this.config = config;
|
||||
}
|
||||
get provider() {
|
||||
return this.config.provider;
|
||||
}
|
||||
getArgs({
|
||||
mode,
|
||||
prompt,
|
||||
maxTokens,
|
||||
temperature,
|
||||
topP,
|
||||
topK,
|
||||
frequencyPenalty,
|
||||
presencePenalty,
|
||||
stopSequences,
|
||||
responseFormat,
|
||||
seed
|
||||
}) {
|
||||
const type = mode.type;
|
||||
const warnings = [];
|
||||
if (topK != null) {
|
||||
warnings.push({
|
||||
type: "unsupported-setting",
|
||||
setting: "topK"
|
||||
});
|
||||
}
|
||||
if (frequencyPenalty != null) {
|
||||
warnings.push({
|
||||
type: "unsupported-setting",
|
||||
setting: "frequencyPenalty"
|
||||
});
|
||||
}
|
||||
if (presencePenalty != null) {
|
||||
warnings.push({
|
||||
type: "unsupported-setting",
|
||||
setting: "presencePenalty"
|
||||
});
|
||||
}
|
||||
if (stopSequences != null) {
|
||||
warnings.push({
|
||||
type: "unsupported-setting",
|
||||
setting: "stopSequences"
|
||||
});
|
||||
}
|
||||
if (responseFormat != null && responseFormat.type === "json" && responseFormat.schema != null) {
|
||||
warnings.push({
|
||||
type: "unsupported-setting",
|
||||
setting: "responseFormat",
|
||||
details: "JSON response format schema is not supported"
|
||||
});
|
||||
}
|
||||
const baseArgs = {
|
||||
// model id:
|
||||
model: this.modelId,
|
||||
// model specific settings:
|
||||
stream: this.settings.stream,
|
||||
repetition_penalty: this.settings.repetition_penalty,
|
||||
update_interval: this.settings.update_interval,
|
||||
// standardized settings:
|
||||
max_tokens: maxTokens,
|
||||
temperature,
|
||||
top_p: topP,
|
||||
// response format:
|
||||
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0,
|
||||
// messages:
|
||||
messages: convertToGigachatChatMessages(prompt)
|
||||
};
|
||||
switch (type) {
|
||||
case "regular": {
|
||||
const { tools, tool_choice, toolWarnings } = prepareTools(mode);
|
||||
return {
|
||||
args: { ...baseArgs, tools, tool_choice },
|
||||
warnings: [...warnings, ...toolWarnings]
|
||||
};
|
||||
}
|
||||
case "object-json": {
|
||||
return {
|
||||
args: {
|
||||
...baseArgs,
|
||||
response_format: { type: "json_object" }
|
||||
},
|
||||
warnings
|
||||
};
|
||||
}
|
||||
case "object-tool": {
|
||||
return {
|
||||
args: {
|
||||
...baseArgs,
|
||||
tool_choice: "any",
|
||||
tools: [{ type: "function", function: mode.tool }]
|
||||
},
|
||||
warnings
|
||||
};
|
||||
}
|
||||
default: {
|
||||
const _exhaustiveCheck = type;
|
||||
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
async doGenerate(options) {
|
||||
var _a;
|
||||
const { args, warnings } = this.getArgs(options);
|
||||
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
||||
url: `${this.config.baseURL}/chat/completions`,
|
||||
headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
|
||||
body: args,
|
||||
failedResponseHandler: gigachatFailedResponseHandler,
|
||||
successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(gigachatChatResponseSchema),
|
||||
abortSignal: options.abortSignal,
|
||||
fetch: this.config.fetch
|
||||
});
|
||||
const { messages: rawPrompt, ...rawSettings } = args;
|
||||
const choice = response.choices[0];
|
||||
let text = (_a = choice.message.content) != null ? _a : void 0;
|
||||
const lastMessage = rawPrompt[rawPrompt.length - 1];
|
||||
if (lastMessage.role === "assistant" && (text == null ? void 0 : text.startsWith(lastMessage.content))) {
|
||||
text = text.slice(lastMessage.content.length);
|
||||
}
|
||||
return {
|
||||
text,
|
||||
toolCalls: choice.message.function_call ? [
|
||||
{
|
||||
toolCallType: "function",
|
||||
toolCallId: choice.message.function_call.name,
|
||||
toolName: choice.message.function_call.name,
|
||||
args: JSON.stringify(choice.message.function_call.arguments)
|
||||
}
|
||||
] : [],
|
||||
finishReason: mapGigachatFinishReason(choice.finish_reason),
|
||||
usage: {
|
||||
promptTokens: response.usage.prompt_tokens,
|
||||
completionTokens: response.usage.completion_tokens
|
||||
},
|
||||
rawCall: { rawPrompt, rawSettings },
|
||||
rawResponse: { headers: responseHeaders },
|
||||
request: { body: JSON.stringify(args) },
|
||||
response: getResponseMetadata(response),
|
||||
warnings
|
||||
};
|
||||
}
|
||||
async doStream(options) {
|
||||
const { args, warnings } = this.getArgs(options);
|
||||
const body = { ...args, stream: true };
|
||||
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
||||
url: `${this.config.baseURL}/chat/completions`,
|
||||
headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
|
||||
body,
|
||||
failedResponseHandler: gigachatFailedResponseHandler,
|
||||
successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(gigachatChatChunkSchema),
|
||||
abortSignal: options.abortSignal,
|
||||
fetch: this.config.fetch
|
||||
});
|
||||
const { messages: rawPrompt, ...rawSettings } = args;
|
||||
let finishReason = "unknown";
|
||||
let usage = {
|
||||
promptTokens: Number.NaN,
|
||||
completionTokens: Number.NaN
|
||||
};
|
||||
let chunkNumber = 0;
|
||||
let trimLeadingSpace = false;
|
||||
return {
|
||||
stream: response.pipeThrough(
|
||||
new TransformStream({
|
||||
transform(chunk, controller) {
|
||||
if (!chunk.success) {
|
||||
controller.enqueue({ type: "error", error: chunk.error });
|
||||
return;
|
||||
}
|
||||
chunkNumber++;
|
||||
const value = chunk.value;
|
||||
if (chunkNumber === 1) {
|
||||
controller.enqueue({
|
||||
type: "response-metadata",
|
||||
...getResponseMetadata(value)
|
||||
});
|
||||
}
|
||||
if (value.usage != null) {
|
||||
usage = {
|
||||
promptTokens: value.usage.prompt_tokens,
|
||||
completionTokens: value.usage.completion_tokens
|
||||
};
|
||||
}
|
||||
const choice = value.choices[0];
|
||||
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
||||
finishReason = mapGigachatFinishReason(choice.finish_reason);
|
||||
}
|
||||
if ((choice == null ? void 0 : choice.delta) == null) {
|
||||
return;
|
||||
}
|
||||
const delta = choice.delta;
|
||||
if (chunkNumber <= 2) {
|
||||
const lastMessage = rawPrompt[rawPrompt.length - 1];
|
||||
if (lastMessage.role === "assistant" && delta.content === lastMessage.content.trimEnd()) {
|
||||
if (delta.content.length < lastMessage.content.length) {
|
||||
trimLeadingSpace = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (delta.content != null) {
|
||||
controller.enqueue({
|
||||
type: "text-delta",
|
||||
textDelta: trimLeadingSpace ? delta.content.trimStart() : delta.content
|
||||
});
|
||||
trimLeadingSpace = false;
|
||||
}
|
||||
if (delta.function_call != null) {
|
||||
controller.enqueue({
|
||||
type: "tool-call-delta",
|
||||
toolCallType: "function",
|
||||
toolCallId: delta.function_call.name,
|
||||
toolName: delta.function_call.name,
|
||||
argsTextDelta: JSON.stringify(delta.function_call.arguments)
|
||||
});
|
||||
controller.enqueue({
|
||||
type: "tool-call",
|
||||
toolCallType: "function",
|
||||
toolCallId: delta.function_call.name,
|
||||
toolName: delta.function_call.name,
|
||||
args: JSON.stringify(delta.function_call.arguments)
|
||||
});
|
||||
}
|
||||
},
|
||||
flush(controller) {
|
||||
controller.enqueue({ type: "finish", finishReason, usage });
|
||||
}
|
||||
})
|
||||
),
|
||||
rawCall: { rawPrompt, rawSettings },
|
||||
rawResponse: { headers: responseHeaders },
|
||||
request: { body: JSON.stringify(body) },
|
||||
warnings
|
||||
};
|
||||
}
|
||||
};
|
||||
var gigachatChatResponseSchema = import_zod2.z.object({
|
||||
created: import_zod2.z.number().nullish(),
|
||||
model: import_zod2.z.string().nullish(),
|
||||
choices: import_zod2.z.array(
|
||||
import_zod2.z.object({
|
||||
message: import_zod2.z.object({
|
||||
role: import_zod2.z.literal("assistant"),
|
||||
content: import_zod2.z.string().nullable(),
|
||||
created: import_zod2.z.number().nullish(),
|
||||
name: import_zod2.z.string().nullish(),
|
||||
function_call: import_zod2.z.object({
|
||||
name: import_zod2.z.string(),
|
||||
arguments: import_zod2.z.record(import_zod2.z.any())
|
||||
}).nullish(),
|
||||
data_for_context: import_zod2.z.array(import_zod2.z.object({})).nullish()
|
||||
}),
|
||||
index: import_zod2.z.number(),
|
||||
finish_reason: import_zod2.z.string().nullish()
|
||||
})
|
||||
),
|
||||
object: import_zod2.z.literal("chat.completion"),
|
||||
usage: import_zod2.z.object({
|
||||
prompt_tokens: import_zod2.z.number(),
|
||||
completion_tokens: import_zod2.z.number(),
|
||||
total_tokens: import_zod2.z.number()
|
||||
})
|
||||
});
|
||||
var gigachatChatChunkSchema = import_zod2.z.object({
|
||||
created: import_zod2.z.number().nullish(),
|
||||
model: import_zod2.z.string().nullish(),
|
||||
object: import_zod2.z.literal("chat.completion"),
|
||||
choices: import_zod2.z.array(
|
||||
import_zod2.z.object({
|
||||
delta: import_zod2.z.object({
|
||||
role: import_zod2.z.enum(["assistant"]).optional(),
|
||||
content: import_zod2.z.string().nullish(),
|
||||
functions_state_id: import_zod2.z.string().nullish(),
|
||||
function_call: import_zod2.z.object({
|
||||
name: import_zod2.z.string(),
|
||||
arguments: import_zod2.z.object({})
|
||||
}).nullish()
|
||||
}),
|
||||
finish_reason: import_zod2.z.string().nullish(),
|
||||
index: import_zod2.z.number()
|
||||
})
|
||||
),
|
||||
usage: import_zod2.z.object({
|
||||
prompt_tokens: import_zod2.z.number(),
|
||||
completion_tokens: import_zod2.z.number()
|
||||
}).nullish()
|
||||
});
|
||||
|
||||
// src/gigachat-embedding-model.ts
|
||||
var import_provider3 = require("@ai-sdk/provider");
|
||||
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
||||
var import_zod3 = require("zod");
|
||||
var GigachatEmbeddingModel = class {
|
||||
constructor(modelId, settings, config) {
|
||||
this.specificationVersion = "v1";
|
||||
this.modelId = modelId;
|
||||
this.settings = settings;
|
||||
this.config = config;
|
||||
}
|
||||
get provider() {
|
||||
return this.config.provider;
|
||||
}
|
||||
get maxEmbeddingsPerCall() {
|
||||
var _a;
|
||||
return (_a = this.settings.maxEmbeddingsPerCall) != null ? _a : 32;
|
||||
}
|
||||
get supportsParallelCalls() {
|
||||
var _a;
|
||||
return (_a = this.settings.supportsParallelCalls) != null ? _a : false;
|
||||
}
|
||||
async doEmbed({
|
||||
values,
|
||||
abortSignal,
|
||||
headers
|
||||
}) {
|
||||
if (values.length > this.maxEmbeddingsPerCall) {
|
||||
throw new import_provider3.TooManyEmbeddingValuesForCallError({
|
||||
provider: this.provider,
|
||||
modelId: this.modelId,
|
||||
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
||||
values
|
||||
});
|
||||
}
|
||||
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
||||
url: `${this.config.baseURL}/embeddings`,
|
||||
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), headers),
|
||||
body: {
|
||||
model: this.modelId,
|
||||
input: values,
|
||||
encoding_format: "float"
|
||||
},
|
||||
failedResponseHandler: gigachatFailedResponseHandler,
|
||||
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(GigachatTextEmbeddingResponseSchema),
|
||||
abortSignal,
|
||||
fetch: this.config.fetch
|
||||
});
|
||||
return {
|
||||
embeddings: response.data.map((item) => item.embedding),
|
||||
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
||||
rawResponse: { headers: responseHeaders }
|
||||
};
|
||||
}
|
||||
};
|
||||
var GigachatTextEmbeddingResponseSchema = import_zod3.z.object({
|
||||
data: import_zod3.z.array(import_zod3.z.object({ embedding: import_zod3.z.array(import_zod3.z.number()) })),
|
||||
usage: import_zod3.z.object({ prompt_tokens: import_zod3.z.number() }).nullish()
|
||||
});
|
||||
|
||||
// src/gigachat-provider.ts
|
||||
function createGigachat(options = {}) {
|
||||
var _a;
|
||||
const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://gigachat.devices.sberbank.ru/api/v1";
|
||||
const getAccessToken = () => ({});
|
||||
const getHeaders = () => ({
|
||||
Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
|
||||
apiKey: options.apiKey,
|
||||
environmentVariableName: "GIGACHAT_ACCESS_TOKEN",
|
||||
description: "GigaChat"
|
||||
})}`,
|
||||
...options.headers
|
||||
});
|
||||
const createChatModel = (modelId, settings = {}) => new GigachatChatLanguageModel(modelId, settings, {
|
||||
provider: "gigachat.chat",
|
||||
baseURL,
|
||||
headers: getHeaders,
|
||||
fetch: options.fetch
|
||||
});
|
||||
const createEmbeddingModel = (modelId, settings = {}) => new GigachatEmbeddingModel(modelId, settings, {
|
||||
provider: "gigachat.embedding",
|
||||
baseURL,
|
||||
headers: getHeaders,
|
||||
fetch: options.fetch
|
||||
});
|
||||
const provider = function(modelId, settings) {
|
||||
if (new.target) {
|
||||
throw new Error("Gigachat function cannot be called with the new keyword.");
|
||||
}
|
||||
return createChatModel(modelId, settings);
|
||||
};
|
||||
provider.languageModel = createChatModel;
|
||||
provider.chat = createChatModel;
|
||||
provider.embedding = createEmbeddingModel;
|
||||
provider.textEmbedding = createEmbeddingModel;
|
||||
provider.textEmbeddingModel = createEmbeddingModel;
|
||||
return provider;
|
||||
}
|
||||
var gigachat = createGigachat();
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
module.exports = {
|
||||
createGigachat,
|
||||
gigachat
|
||||
}
|
||||
144
server/routers/kfu-m-24-1/eng-it-lean/gigachat/index.js
Normal file
144
server/routers/kfu-m-24-1/eng-it-lean/gigachat/index.js
Normal file
@@ -0,0 +1,144 @@
|
||||
const axios = require('axios');
|
||||
const https = require('https');
|
||||
const fs = require('fs');
|
||||
const qs = require('querystring');
|
||||
const uuid = require('uuid');
|
||||
|
||||
const router = require('express').Router();
|
||||
|
||||
// vercel/ai package
|
||||
const ai = require('./ai');
|
||||
// gigachat provider for vercel/ai
|
||||
const gigachatProvider = require('./gigachat');
|
||||
|
||||
module.exports = router;
|
||||
|
||||
const path = require('path');
|
||||
//process.env.NODE_EXTRA_CA_CERTS= path.resolve(__dirname, 'certs')
|
||||
//process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||
|
||||
process.env.GIGACHAT_AUTH =
|
||||
'NWVjYTczYjctNWRkYi00NzExLTg0YTEtMjhlOWVmODM2MjI4OjlmMTBkMGVkLWZjZjktNGZhOS1hNDZjLTc5ZWU1YzExOGExMw==';
|
||||
|
||||
const agent = new https.Agent({
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
|
||||
const gigachat = gigachatProvider.createGigachat({
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'text/event-stream'
|
||||
},
|
||||
fetch: (url, options) => {
|
||||
return axios({
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: url,
|
||||
headers: options.headers,
|
||||
httpsAgent: agent,
|
||||
data: options.body
|
||||
}).then((response) => {
|
||||
return new Response(response.data, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: response.headers,
|
||||
body: response.data
|
||||
});
|
||||
}).catch((error) => {
|
||||
return new Response(error.message, {
|
||||
status: error.response.status,
|
||||
statusText: error.response.statusText,
|
||||
headers: error.response.headers,
|
||||
body: error.response.data
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.use(async (req, res, next) => {
|
||||
const hasToken = process.env.GIGACHAT_ACCESS_TOKEN && process.env.GIGACHAT_EXPIRES_AT != null;
|
||||
const hasExpired = new Date(process.env.GIGACHAT_EXPIRES_AT) <= new Date();
|
||||
if (!hasToken || hasExpired) {
|
||||
let auth = process.env.GIGACHAT_AUTH;
|
||||
let rquid = uuid.v4();
|
||||
|
||||
let config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: 'https://ngw.devices.sberbank.ru:9443/api/v2/oauth',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
Accept: 'application/json',
|
||||
RqUID: rquid,
|
||||
Authorization: 'Basic ' + auth
|
||||
},
|
||||
httpsAgent: agent,
|
||||
data: qs.stringify({
|
||||
scope: 'GIGACHAT_API_PERS'
|
||||
})
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios(config);
|
||||
const json = response.data;
|
||||
process.env.GIGACHAT_ACCESS_TOKEN = json.access_token;
|
||||
process.env.GIGACHAT_EXPIRES_AT = json.expires_at;
|
||||
console.log(JSON.stringify(response.data));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
router.post('/chat', async (req, res) => {
|
||||
const { messages } = req.body;
|
||||
|
||||
const result = ai.streamText({
|
||||
model: gigachat('GigaChat'),
|
||||
system: 'You are a helpful assistant.',
|
||||
messages,
|
||||
stream: true,
|
||||
update_interval: 0.2
|
||||
});
|
||||
|
||||
result.pipeDataStreamToResponse(res);
|
||||
});
|
||||
|
||||
router.post('/new-unit', async (req, res) => {
|
||||
const { prompt } = req.body;
|
||||
|
||||
const systemMessage = `
|
||||
Я хочу, чтобы вы выступали в роли помощника для создания продвинутых текстовых уроков английского языка. Я буду указывать тему и уровень сложности (начинающий, средний, продвинутый), а вы будете предоставлять структурированный план урока в формате Markdown. Урок должен включать только текстовые элементы (без видео, картинок, аудио) и содержать следующие разделы:
|
||||
-Цель урока — конкретный навык или знание, которое освоят студенты.
|
||||
-Лексика
|
||||
-Базовые термины: 5-7 слов/фраз с примерами употребления.
|
||||
-Расширенная лексика: 3-5 идиом, фразовых глаголов или сложных выражений (для среднего/продвинутого уровня).
|
||||
-Грамматический фокус
|
||||
-Правило с пояснением и 3-5 примерами.
|
||||
-Типичные ошибки и как их избежать.
|
||||
-Контекстуализация
|
||||
-Короткий текст (диалог, статья, описание) для анализа с использованием лексики и грамматики урока.
|
||||
-Упражнения
|
||||
-Письменное задание: например, составить предложения/эссе по теме.
|
||||
-Устная практика: ролевые диалоги (текстовые сценарии), описание ситуаций.
|
||||
-Аналитическое задание: исправление ошибок в предложениях, перевод сложных конструкций.
|
||||
-Домашнее задание
|
||||
Текстовые задачи: написание текста, грамматические тесты, поиск синонимов/антонимов.
|
||||
Ответ должен быть оформлен в Markdown, лаконичным, без лишних комментариев, если пишешь блок кода, начинай его с новой строки.
|
||||
`;
|
||||
|
||||
try {
|
||||
const result = ai.streamText({
|
||||
model: gigachat('GigaChat'),
|
||||
system: systemMessage,
|
||||
prompt,
|
||||
stream: true,
|
||||
update_interval: 0.3
|
||||
});
|
||||
|
||||
result.pipeTextStreamToResponse(res);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
@@ -1,7 +1,10 @@
|
||||
const router = require("express").Router();
|
||||
const router = require('express').Router();
|
||||
|
||||
const dictionariesRouter = require("./dictionaries");
|
||||
const wordsRouter = require('./words');
|
||||
const dictionariesRouter = require('./dictionaries');
|
||||
const unitsRouter = require('./units');
|
||||
const gigachatRouter = require('./gigachat');
|
||||
const usersRouter = require('./users');
|
||||
module.exports = router;
|
||||
|
||||
const delay =
|
||||
@@ -11,5 +14,8 @@ const delay =
|
||||
};
|
||||
|
||||
router.use(delay());
|
||||
router.use("/dictionaries", dictionariesRouter);
|
||||
router.use('/words', wordsRouter);
|
||||
router.use('/dictionaries', dictionariesRouter);
|
||||
router.use('/units', unitsRouter);
|
||||
router.use('/gigachat', gigachatRouter);
|
||||
router.use('/users', usersRouter);
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
### Цель урока:
|
||||
Изучение ключевых слов и фраз, связанных с процессом трудоустройства, а также освоение базовой структуры диалога на собеседовании.
|
||||
|
||||
### Лексика:
|
||||
**Базовая лексика:**
|
||||
1. **Job interview** – собеседование при приеме на работу
|
||||
2. **Resume / CV** – резюме
|
||||
3. **Cover letter** – сопроводительное письмо
|
||||
4. **Interviewer** – интервьюер
|
||||
5. **Application form** – анкета при приеме на работу
|
||||
6. **Salary** – зарплата
|
||||
7. **Benefits** – льготы
|
||||
|
||||
**Расширенная лексика:**
|
||||
1. **To apply for a job** – подавать заявку на работу
|
||||
2. **To be offered the job** – получить предложение о работе
|
||||
3. **To negotiate salary** – вести переговоры о зарплате
|
||||
4. **To accept the offer** – принять предложение
|
||||
5. **To decline the offer** – отклонить предложение
|
||||
6. **To resign from your current position** – подать заявление об уходе с текущей работы
|
||||
7. **To start working at the company** – начать работать в компании
|
||||
8. **Probation period** – испытательный срок
|
||||
9. **References** – рекомендации
|
||||
10. **Work experience** – опыт работы
|
||||
|
||||
### Грамматический фокус:
|
||||
**Правило:**
|
||||
Структура простого вопроса на английском языке:
|
||||
- Общий вопрос: "Do you have any questions?"
|
||||
- Специальный вопрос: "What are your strengths and weaknesses?"
|
||||
|
||||
**Пример:**
|
||||
Общий вопрос: "How do you feel about this job opportunity?"
|
||||
Специальный вопрос: "Can you tell me about your previous work experience?"
|
||||
|
||||
**Типичные ошибки и как их избежать:**
|
||||
Ошибка: Неправильное использование порядка слов в вопросах.
|
||||
Решение: Практиковать построение вопросов до автоматизма.
|
||||
|
||||
### Контекстуализация:
|
||||
**Текст для анализа:**
|
||||
"I'm applying for the position of a marketing manager at XYZ Company. Here is my resume."
|
||||
"Thank you for considering me. Can you please tell me more about the responsibilities of this role?"
|
||||
"Sure, let me give you an overview."
|
||||
|
||||
### Упражнения:
|
||||
**Письменное задание:**
|
||||
Составьте список из 5 вопросов, которые вы бы задали на собеседовании. Используйте простые вопросы и специальные вопросы.
|
||||
|
||||
**Устная практика:**
|
||||
Ролевая игра: один студент играет роль интервьюера, другой – кандидата на должность. Меняйтесь ролями.
|
||||
|
||||
**Аналитическое задание:**
|
||||
Найдите и исправьте ошибки в следующем письме:
|
||||
"Dear HR Manager,
|
||||
|
||||
My name is John Smith and I am writing to apply for the position of Sales Representative at ABC Inc. I enclose my resume for your review.
|
||||
|
||||
I believe that my skills and experiences make me an ideal candidate for this position. In my current role as a sales representative at XYZ Corp, I have consistently met or exceeded my sales targets. Additionally, I possess strong communication and negotiation skills which will enable me to effectively represent your products and services.
|
||||
|
||||
If you would like to schedule an interview, please contact me at your convenience. Thank you for your time and consideration.
|
||||
|
||||
Best regards,
|
||||
John Smith"
|
||||
|
||||
### Домашнее задание:
|
||||
**Текстовые задачи:**
|
||||
1. Написать сопроводительное письмо для конкретной вакансии, используя расширенную лексику.
|
||||
2. Составить резюме для воображаемой должности, включая все необходимые разделы.
|
||||
3. Перевести текст собеседования на английский язык, сохраняя структуру и смысл.
|
||||
74
server/routers/kfu-m-24-1/eng-it-lean/units/data/unit-2.md
Normal file
74
server/routers/kfu-m-24-1/eng-it-lean/units/data/unit-2.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Цель урока
|
||||
|
||||
Изучение структуры документации программы с блоком кода.
|
||||
|
||||
## Лексика
|
||||
|
||||
### Базовая лексика:
|
||||
|
||||
- Documentation – документация
|
||||
- Code block – блок кода
|
||||
- Description – описание
|
||||
- Function – функция
|
||||
- Variable – переменная
|
||||
- Comment – комментарий
|
||||
|
||||
### Расширенная лексика:
|
||||
|
||||
- API – интерфейс прикладного программирования
|
||||
- Method – метод
|
||||
- Class – класс
|
||||
- Library – библиотека
|
||||
- Framework – фреймворк
|
||||
|
||||
## Грамматический фокус
|
||||
|
||||
Правило: Структура документации программы должна включать краткое описание, блок кода и примеры использования.
|
||||
|
||||
Пример:
|
||||
|
||||
Documentation for a program typically includes the following sections:
|
||||
|
||||
1. **Description**: A brief overview of what the program does and its purpose.
|
||||
2. **Code Block**: The actual code that implements the functionality described in the first section.
|
||||
3. **Examples**: One or more examples demonstrating how to use the features described in the documentation.
|
||||
|
||||
Типичные ошибки и как их избежать: Ошибки могут возникнуть из-за недостаточного описания функционала или неправильного форматирования кода. Чтобы избежать этого, важно тщательно проработать каждый раздел документации и убедиться, что все примеры корректны и понятны.
|
||||
|
||||
## Контекстуализация
|
||||
|
||||
Текст для анализа:
|
||||
|
||||
**Description**: This is a simple Python script that calculates the average value of a list of numbers.
|
||||
|
||||
**Code Block**:
|
||||
```python
|
||||
def calculate_average(numbers):
|
||||
"""Calculate the average value of a list of numbers"""
|
||||
return sum(numbers)/len(numbers)
|
||||
```
|
||||
|
||||
Примеры использования:
|
||||
|
||||
```python
|
||||
# Example usage
|
||||
numbers = [10, 20, 30]
|
||||
average = calculate_average(numbers)
|
||||
print("The average value of the list", numbers, "is", average)
|
||||
```
|
||||
|
||||
## Упражнения
|
||||
|
||||
Письменное задание: Написать документацию для простой функции на языке Python, которая принимает список чисел и возвращает среднее значение. Включить описание, код блока и пример использования.
|
||||
|
||||
Устная практика: Ролевой диалог между разработчиком и техническим писателем о структуре и содержании документации программы.
|
||||
|
||||
Аналитическое задание: Проанализировать существующую документацию программы и найти ошибки или неясности. Предложить улучшения.
|
||||
|
||||
## Домашнее задание
|
||||
|
||||
Текстовые задачи:
|
||||
|
||||
- Написать документацию для другой функции на языке Python, используя правильную структуру.
|
||||
- Исправить ошибки в существующей документации программы.
|
||||
- Перевести фрагмент документации на русский язык, сохраняя точность и стиль.
|
||||
@@ -1 +1 @@
|
||||
[{"id":0,"filename":"unit-1","name":"Unit 1: Multifunctional Verbs: Be, Have, and Do"}]
|
||||
[{"id":1,"filename":"unit-1","name":"Unit 1: Multifunctional Verbs: Be, Have, and Do"},{"id":2,"filename":"unit-2","name":"Документация программы"},{"id":3,"fileName":"job-interview","name":"Job Interview"}]
|
||||
@@ -4,55 +4,90 @@ const router = require('express').Router();
|
||||
|
||||
module.exports = router;
|
||||
|
||||
const data = require('./data/units.json');
|
||||
const data = require('./units.json');
|
||||
router.get('/', (req, res) => {
|
||||
res.send(data);
|
||||
// for every data set author from users and save it to authoredData variable
|
||||
const users = require('../users/users.json');
|
||||
const authoredData = data.map((unit) => {
|
||||
const user = users.find((user) => user.public_id == unit.author);
|
||||
let authoredUnit = undefined;
|
||||
if (user) {
|
||||
authoredUnit = { ...unit, author: user };
|
||||
}
|
||||
return authoredUnit;
|
||||
});
|
||||
|
||||
res.send(authoredData);
|
||||
});
|
||||
|
||||
router.post('/:id', (req, res) => {
|
||||
const id = parseInt(req.params.id);
|
||||
const updatedUnit = req.body;
|
||||
|
||||
if (!updatedUnit) {
|
||||
return res.status(400).send('No unit to be added');
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return res.status(500).send('No data to be updated');
|
||||
}
|
||||
|
||||
const index = data.findIndex((unit) => unit.id === id);
|
||||
|
||||
if (index < 0) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
|
||||
data.splice(index, 1);
|
||||
|
||||
data.push({...updatedUnit, author: updatedUnit.author.public_id});
|
||||
|
||||
res.status(200).send(data);
|
||||
});
|
||||
|
||||
router.put('/', (req, res) => {
|
||||
const newUnit = req.body
|
||||
const newUnit = req.body;
|
||||
|
||||
if (!newUnit) {
|
||||
return res.status(400).send('No new unit to be added')
|
||||
}
|
||||
if (!newUnit) {
|
||||
return res.status(400).send('No new unit to be added');
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return res.status(500).send('No data to be updated')
|
||||
}
|
||||
if (!newUnit.author) {
|
||||
return res.status(400).send('User is not logged in!');
|
||||
}
|
||||
|
||||
data.push({ "id": data.length, ...newUnit })
|
||||
if (!data) {
|
||||
return res.status(500).send('No data to be updated');
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, 'data', 'units.json'), JSON.stringify(data));
|
||||
res.status(200).send(data);
|
||||
const newId = data.length + 1;
|
||||
data.push({ ...newUnit, id: newId });
|
||||
|
||||
res.status(200).send(data);
|
||||
});
|
||||
|
||||
router.delete('/:id', (req, res) => {
|
||||
const id = parseInt(req.params.id);
|
||||
const index = data.findIndex((unit) => unit.id === id);
|
||||
const id = parseInt(req.params.id);
|
||||
const index = data.findIndex((unit) => unit.id === id);
|
||||
|
||||
if (index < 0) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
if (index < 0) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
|
||||
data.splice(index, 1);
|
||||
fs.writeFileSync(path.join(__dirname, 'data', 'units.json'), JSON.stringify(data));
|
||||
res.send({ message: `Unit with ID ${id} deleted` });
|
||||
data.splice(index, 1);
|
||||
res.send({ message: `Unit with ID ${id} deleted` });
|
||||
});
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
const users = require('../users/users.json');
|
||||
const id = parseInt(req.params.id);
|
||||
const unit = data.find((unit) => unit.id === id);
|
||||
|
||||
if (!unit) {
|
||||
return res.status(404).send('Not found');
|
||||
return res.status(404).send('Unit not found');
|
||||
}
|
||||
|
||||
const unitFilepath = path.join(__dirname, 'data', `${unit.filename}.md`);
|
||||
const unitContent = fs.readFileSync(unitFilepath, 'utf-8');
|
||||
const user = users.find((user) => user.public_id == unit.author);
|
||||
|
||||
if (!unitContent) {
|
||||
return res.status(404).send('Not found');
|
||||
}
|
||||
|
||||
res.send({ ...unit, content: unitContent });
|
||||
res.send({...unit, author: user});
|
||||
});
|
||||
|
||||
20
server/routers/kfu-m-24-1/eng-it-lean/units/units.json
Normal file
20
server/routers/kfu-m-24-1/eng-it-lean/units/units.json
Normal file
@@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"content": "# Цель урока\n\nИзучение структуры документации программы с блоком кода.\n\n## Лексика\n\n### Базовая лексика:\n\n- Documentation – документация\n- Code block – блок кода\n- Description – описание\n- Function – функция\n- Variable – переменная\n- Comment – комментарий\n\n### Расширенная лексика:\n\n- API – интерфейс прикладного программирования\n- Method – метод\n- Class – класс\n- Library – библиотека\n- Framework – фреймворк\n\n## Грамматический фокус\n\nПравило: Структура документации программы должна включать краткое описание, блок кода и примеры использования.\n\nПример:\n\nDocumentation for a program typically includes the following sections:\n\n1. **Description**: A brief overview of what the program does and its purpose.\n2. **Code Block**: The actual code that implements the functionality described in the first section.\n3. **Examples**: One or more examples demonstrating how to use the features described in the documentation.\n\nТипичные ошибки и как их избежать: Ошибки могут возникнуть из-за недостаточного описания функционала или неправильного форматирования кода. Чтобы избежать этого, важно тщательно проработать каждый раздел документации и убедиться, что все примеры корректны и понятны.\n\n## Контекстуализация\n\nТекст для анализа:\n\n**Description**: This is a simple Python script that calculates the average value of a list of numbers.\n\n**Code Block**: \n```python\ndef calculate_average(numbers):\n \"\"\"Calculate the average value of a list of numbers\"\"\"\n return sum(numbers)/len(numbers)\n```\n\nПримеры использования:\n\n```python\n# Example usage\nnumbers = [10, 20, 30]\naverage = calculate_average(numbers)\nprint(\"The average value of the list\", numbers, \"is\", average)\n```\n\n## Упражнения\n\nПисьменное задание: Написать документацию для простой функции на языке Python, которая принимает список чисел и возвращает среднее значение. Включить описание, код блока и пример использования.\n\nУстная практика: Ролевой диалог между разработчиком и техническим писателем о структуре и содержании документации программы.\n\nАналитическое задание: Проанализировать существующую документацию программы и найти ошибки или неясности. Предложить улучшения.\n\n## Домашнее задание\n\nТекстовые задачи:\n\n- Написать документацию для другой функции на языке Python, используя правильную структуру.\n- Исправить ошибки в существующей документации программы.\n- Перевести фрагмент документации на русский язык, сохраняя точность и стиль.\n",
|
||||
"id": 2,
|
||||
"author": "1738707541324",
|
||||
"name": "Документация программы"
|
||||
},
|
||||
{
|
||||
"content": "### Цель урока:\nИзучение ключевых слов и фраз, связанных с процессом трудоустройства, а также освоение базовой структуры диалога на собеседовании.\n\n### Лексика:\n**Базовая лексика:**\n1. **Job interview** – собеседование при приеме на работу\n2. **Resume / CV** – резюме\n3. **Cover letter** – сопроводительное письмо\n4. **Interviewer** – интервьюер\n5. **Application form** – анкета при приеме на работу\n6. **Salary** – зарплата\n7. **Benefits** – льготы\n\n**Расширенная лексика:**\n1. **To apply for a job** – подавать заявку на работу\n2. **To be offered the job** – получить предложение о работе\n3. **To negotiate salary** – вести переговоры о зарплате\n4. **To accept the offer** – принять предложение\n5. **To decline the offer** – отклонить предложение\n6. **To resign from your current position** – подать заявление об уходе с текущей работы\n7. **To start working at the company** – начать работать в компании\n8. **Probation period** – испытательный срок\n9. **References** – рекомендации\n10. **Work experience** – опыт работы\n\n### Грамматический фокус:\n**Правило:**\nСтруктура простого вопроса на английском языке:\n- Общий вопрос: \"Do you have any questions?\"\n- Специальный вопрос: \"What are your strengths and weaknesses?\"\n\n**Пример:**\nОбщий вопрос: \"How do you feel about this job opportunity?\"\nСпециальный вопрос: \"Can you tell me about your previous work experience?\"\n\n**Типичные ошибки и как их избежать:**\nОшибка: Неправильное использование порядка слов в вопросах.\nРешение: Практиковать построение вопросов до автоматизма.\n\n### Контекстуализация:\n**Текст для анализа:**\n\"I'm applying for the position of a marketing manager at XYZ Company. Here is my resume.\"\n\"Thank you for considering me. Can you please tell me more about the responsibilities of this role?\"\n\"Sure, let me give you an overview.\"\n\n### Упражнения:\n**Письменное задание:**\nСоставьте список из 5 вопросов, которые вы бы задали на собеседовании. Используйте простые вопросы и специальные вопросы.\n\n**Устная практика:**\nРолевая игра: один студент играет роль интервьюера, другой – кандидата на должность. Меняйтесь ролями.\n\n**Аналитическое задание:**\nНайдите и исправьте ошибки в следующем письме:\n\"Dear HR Manager,\n\nMy name is John Smith and I am writing to apply for the position of Sales Representative at ABC Inc. I enclose my resume for your review.\n\nI believe that my skills and experiences make me an ideal candidate for this position. In my current role as a sales representative at XYZ Corp, I have consistently met or exceeded my sales targets. Additionally, I possess strong communication and negotiation skills which will enable me to effectively represent your products and services.\n\nIf you would like to schedule an interview, please contact me at your convenience. Thank you for your time and consideration.\n\nBest regards,\nJohn Smith\"\n\n### Домашнее задание:\n**Текстовые задачи:**\n1. Написать сопроводительное письмо для конкретной вакансии, используя расширенную лексику.\n2. Составить резюме для воображаемой должности, включая все необходимые разделы.\n3. Перевести текст собеседования на английский язык, сохраняя структуру и смысл.",
|
||||
"id": 3,
|
||||
"author": "1738707541324",
|
||||
"name": "Job Interview"
|
||||
},
|
||||
{
|
||||
"content": "# Multifunctional Verbs\n\n## Overview\n\nThis unit focuses on the use of multifunctional verbs in English. These verbs are able to express multiple meanings depending on their use in a sentence.\n\n## Learning Objectives\n\nBy the end of this unit, you will be able to:\n\n* Identify the different forms of the main multifunctional verb.\n* Explain how these forms can be used interchangeably in sentences.\n* Demonstrate the correct usage of the three forms of the multifunctional verb by providing sentences and examples.\n\n## Vocabulary Review\n\n| Term | Definition |\n| ---- | -------------------------------------------------------- |\n| Be | To express a present or ongoing state of being. |\n| Have | To express ownership or possession. |\n| Do | To express an action to be done, future action or habit. |\n\n## Activities\n\n### Activity 1: Identify the Different Forms of the Main Multifunctional Verb\n\n* Read through each sentence and identify if the verb is used in its present tense (is), past tense (was/were), or future tense (will, would).\n* Discuss how this usage can vary depending on context.\n* Write down sentences that use different forms to illustrate your points.\n\n1. **Sentence 1**\n\n : \"The cat is sleeping.\"\n * Present tense: The cat is sleeping.\n * Past tense: The cat slept.\n * Future tense: The cat will sleep.\n2. **Sentence 2**\n\n : \"I have a dog at home.\"\n * Present tense: I have a dog.\n * Past tense: I had a dog.\n * Future tense: I will have a dog.\n3. **Sentence 3**\n\n : \"We are going on a hike tomorrow.\"\n * Present tense: We are going on a hike.\n * Past tense: We went on a hike.\n * Future tense: We will go on a hike.\n4. **Sentence 4**\n\n : \"He has been studying all day.\"\n * Present tense: He is studying.\n * Past tense: He studied.\n * Future tense: He will study.\n5. **Sentence 5**\n\n : \"We are going to buy some groceries later today.\"\n * Present tense: We are going to buy some groceries.\n * Past tense: We bought some groceries.\n * Future tense: We will buy some groceries.\n\n### Activity 2: Explain How These Forms Can Be Used Interchangeably in Sentences\n\n* Read through a sentence and identify the present, past, and future tense uses.\n* In pairs, explain why these forms are used interchangeably.\n* Provide examples of sentences that demonstrate this usage.\n* Highlight how the context changes the meaning.\n\n### Activity 3: Correct Usage of the Three Forms of the Multifunctional Verb\n\n* Read through a sentence and identify which form is being used.\n* In pairs, discuss why these forms are used in certain situations.\n* Provide sentences that demonstrate the correct usage of the three forms.",
|
||||
"id": 1,
|
||||
"author": "1738707541324",
|
||||
"name": "Multifunctional Verbs"
|
||||
}
|
||||
]
|
||||
53
server/routers/kfu-m-24-1/eng-it-lean/users/index.js
Normal file
53
server/routers/kfu-m-24-1/eng-it-lean/users/index.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const router = require('express').Router();
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = router;
|
||||
|
||||
let data = require('./users.json');
|
||||
const path = require('path');
|
||||
router.get('/', (req, res) => {
|
||||
res.send(data);
|
||||
});
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const newUser = req.body;
|
||||
|
||||
data.push(newUser);
|
||||
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(data));
|
||||
res.send(data);
|
||||
});
|
||||
|
||||
router.post('/login', (req, res) => {
|
||||
const { email, password } = req.body;
|
||||
const user = data.find((user) => user.email === email && user.password === password);
|
||||
|
||||
if (!user) {
|
||||
res.status(404).send('Пользователь не найден');
|
||||
}
|
||||
res.json({ public_id: user.public_id });
|
||||
});
|
||||
|
||||
router.get('/account', (req, res) => {
|
||||
const { public_id } = req.query;
|
||||
const user = data.find((user) => user.public_id == public_id);
|
||||
|
||||
if (!user) {
|
||||
res.status(404).send('Пользователь не найден');
|
||||
}
|
||||
res.send({ ...user, id: -1 });
|
||||
});
|
||||
|
||||
router.post('/account/save', (req, res) => {
|
||||
const updatedUser = req.body;
|
||||
const { public_id } = updatedUser;
|
||||
const index = data.findIndex((user) => user.public_id == public_id);
|
||||
|
||||
if (!index || index === -1) {
|
||||
res.status(404).send('Пользователь не найден');
|
||||
}
|
||||
|
||||
data[index] = { ...data[index], ...updatedUser, id: data[index].id, password: data[index].password };
|
||||
fs.writeFileSync(path.join(__dirname, 'users.json'), JSON.stringify(data));
|
||||
|
||||
res.status(200);
|
||||
});
|
||||
1
server/routers/kfu-m-24-1/eng-it-lean/users/users.json
Normal file
1
server/routers/kfu-m-24-1/eng-it-lean/users/users.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"id":1738707541324,"public_id":1738707541324,"email":"1@gmail.com","password":"1","age":"22","nickname":"324324","about":"Чиловый "}]
|
||||
75
server/routers/kfu-m-24-1/eng-it-lean/words/index.js
Normal file
75
server/routers/kfu-m-24-1/eng-it-lean/words/index.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const router = require("express").Router();
|
||||
|
||||
module.exports = router;
|
||||
|
||||
const words = require("../words/words.json");
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
res.send(words);
|
||||
});
|
||||
|
||||
router.put('/', (req, res) => {
|
||||
const newData = req.body;
|
||||
if (!newData) {
|
||||
return res.status(400).send('No data to add'); // Bad request
|
||||
}
|
||||
if (!words) {
|
||||
return res.status(500).send('No data to update'); // Internal server error
|
||||
}
|
||||
console.log(words.length)
|
||||
const indexedUpdatedData = { ...newData, id: words.length + 1 }; // Add the new word to the array
|
||||
console.log(indexedUpdatedData);
|
||||
words.push(indexedUpdatedData); // Add the new word to the array
|
||||
fs.writeFile(path.join(__dirname, 'words.json'), JSON.stringify(words), (err) => {
|
||||
if (err) {
|
||||
console.error(err); // Log the error
|
||||
return res.status(500).send('Error saving data');
|
||||
}
|
||||
res.status(200).json(indexedUpdatedData);
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/:id", (req, res) => {
|
||||
const id = parseInt(req.params.id);
|
||||
|
||||
if (!id || isNaN(id)) {
|
||||
return res.status(400).send('Invalid ID'); // Bad request
|
||||
}
|
||||
|
||||
if (!words) {
|
||||
return res.status(500).send('No data to update'); // Internal server error
|
||||
}
|
||||
const word = words.find((word) => word.id === id);
|
||||
|
||||
if (!word) {
|
||||
return res.status(404).send("Not found");
|
||||
}
|
||||
res.send(word);
|
||||
});
|
||||
|
||||
router.delete("/:id", (req, res) => {
|
||||
const id = parseInt(req.params.id);
|
||||
if (!id || isNaN(id)) {
|
||||
return res.status(400).send('Invalid ID'); // Bad request
|
||||
}
|
||||
|
||||
const index = words.findIndex((word) => word.id === id);
|
||||
if (index < 0) {
|
||||
return res.status(404).send("Not found");
|
||||
}
|
||||
|
||||
if (!words) {
|
||||
return res.status(500).send('No data to update'); // Internal server error
|
||||
}
|
||||
|
||||
words.splice(index, 1);
|
||||
fs.writeFile(path.join(__dirname, 'words.json'), JSON.stringify(words), (err) => {
|
||||
if (err) {
|
||||
console.error(err); // Log the error
|
||||
return res.status(500).send('Error saving data');
|
||||
}
|
||||
res.send({ message: `Word with id ${id} deleted` });
|
||||
});
|
||||
});
|
||||
437
server/routers/kfu-m-24-1/eng-it-lean/words/words.json
Normal file
437
server/routers/kfu-m-24-1/eng-it-lean/words/words.json
Normal file
@@ -0,0 +1,437 @@
|
||||
[
|
||||
{
|
||||
"id": 12,
|
||||
"word": "Tech",
|
||||
"definition": "short for technical, relating to the knowledge, machines, or methods used in science and industry. Tech is a whole industry, which includes IT",
|
||||
"examples": ["“As a DevOps engineer I have been working in Tech since 2020.”"],
|
||||
"synonyms": ["IT"]
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"word": "career path",
|
||||
"definition": "the series of jobs or roles that constitute a person's career, especially one in a particular field",
|
||||
"examples": ["“Technology is an evolving field with a variety of available career paths.”"],
|
||||
"synonyms": []
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"word": "Machine Learning",
|
||||
"translation": "Машинное обучение",
|
||||
"definition": "An approach to artificial intelligence where computers learn from data without being explicitly programmed.",
|
||||
"synonyms": ["Trainable Algorithms", "Automated Learning"],
|
||||
"examples": [
|
||||
"We used machine learning techniques to forecast product demand.",
|
||||
"The movie recommendation system is based on machine learning algorithms.",
|
||||
"Machine learning helped improve the accuracy of speech recognition in our application."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"word": "Neural Network",
|
||||
"translation": "Нейронная сеть",
|
||||
"definition": "A mathematical model inspired by the structure and function of biological neural networks, consisting of interconnected nodes organized in layers that can process information.",
|
||||
"synonyms": ["Artificial Neural Network", "Deep Neural Network"],
|
||||
"examples": [
|
||||
"To process large amounts of data, we created a deep learning neural network.",
|
||||
"This neural network is capable of generating realistic images.",
|
||||
"Using neural networks significantly improved the quality of text translation."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"word": "Algorithm",
|
||||
"translation": "Алгоритм",
|
||||
"definition": "A step-by-step procedure or set of instructions for solving a problem or performing a computation.",
|
||||
"synonyms": ["Procedure", "Method"],
|
||||
"examples": [
|
||||
"The algorithm we developed quickly finds the optimal delivery route.",
|
||||
"This algorithm sorts an array with a minimal number of operations.",
|
||||
"Encryption algorithms ensure secure transmission of data over the internet."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"word": "Data Model",
|
||||
"translation": "Модель данных",
|
||||
"definition": "An abstract representation of the structure of data, describing how data is organized and related to each other.",
|
||||
"synonyms": ["Data Structure", "Schema"],
|
||||
"examples": [
|
||||
"Our data model allows us to efficiently manage relationships between customers and orders.",
|
||||
"The data model was designed considering scalability and performance requirements.",
|
||||
"This data model is used for storing information about social network users."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"word": "Regression",
|
||||
"translation": "Регрессия",
|
||||
"definition": "A statistical method used to determine the relationship between one variable and others.",
|
||||
"synonyms": ["Linear Regression", "Nonlinear Regression"],
|
||||
"examples": [
|
||||
"We applied linear regression to analyze the impact of advertising campaigns on sales.",
|
||||
"Results from the regression analysis showed a strong correlation between customer age and purchase frequency.",
|
||||
"Regression helped us assess how changes in environmental conditions affect crop yield."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"word": "Clustering",
|
||||
"translation": "Кластеризация",
|
||||
"definition": "The process of grouping similar objects into clusters so that objects within the same cluster are more similar to each other than to those in other clusters.",
|
||||
"synonyms": ["Grouping", "Segmentation"],
|
||||
"examples": [
|
||||
"Clustering allowed us to divide customers into several groups according to their purchasing behavior.",
|
||||
"Clustering methods are used to automatically group news by topic.",
|
||||
"As a result of clustering, several market segments were identified, each with its own characteristics."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"word": "Supervised Learning",
|
||||
"translation": "Обучение с учителем",
|
||||
"definition": "A type of machine learning where the algorithm learns from labeled data, meaning data for which correct answers are known.",
|
||||
"synonyms": ["Controlled Learning", "Labeled Classification"],
|
||||
"examples": [
|
||||
"Supervised learning is used to classify emails as spam or not-spam.",
|
||||
"This approach was used to create a model that predicts real estate prices based on multiple parameters.",
|
||||
"Supervised learning helps diagnose diseases at early stages through medical data analysis."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"word": "Data Labeling",
|
||||
"translation": "Разметка данных",
|
||||
"definition": "The process of assigning labels or classes to data so it can be used in supervised learning.",
|
||||
"synonyms": ["Data Annotation", "Tagging"],
|
||||
"examples": [
|
||||
"Before starting model training, we labeled the data by assigning each photo an animal category.",
|
||||
"Data labeling includes marking user reviews as positive or negative.",
|
||||
"Text documents were labeled with special tags for subsequent analysis."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"word": "Hyperparameters",
|
||||
"translation": "Гиперпараметры",
|
||||
"definition": "Parameters that define the structure and behavior of a machine learning model, set before the learning process begins.",
|
||||
"synonyms": ["Model Settings", "Configuration Parameters"],
|
||||
"examples": [
|
||||
"Optimizing hyperparameters enabled us to enhance the performance of our machine learning model.",
|
||||
"Hyperparameters include settings such as the number of layers in a neural network and the learning rate.",
|
||||
"Choosing the right hyperparameters is crucial for achieving high model accuracy."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"word": "Model Validation",
|
||||
"translation": "Валидация модели",
|
||||
"definition": "The process of evaluating the quality of a model by testing it on new, previously unseen data.",
|
||||
"synonyms": ["Model Testing", "Model Verification"],
|
||||
"examples": [
|
||||
"After completing the training, we validated the model using a test dataset.",
|
||||
"During model validation, its ability to make accurate predictions on new data is checked.",
|
||||
"Validation showed that the model is robust against changes in data and has low generalization error."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"word": "resume",
|
||||
"translation": "резюме",
|
||||
"definition": "a document containing a summary of your work experience, education, and skills that you submit when applying for a job",
|
||||
"synonyms": ["CV", "curriculum vitae"],
|
||||
"examples": [
|
||||
"Make sure to update your resume before the interview."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"word": "interviewer",
|
||||
"translation": "интервьюер",
|
||||
"definition": "the person who conducts an interview, typically a representative of the company or organization offering the job",
|
||||
"synonyms": ["questioner", "examiner"],
|
||||
"examples": [
|
||||
"The interviewer asked about my previous work experiences."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"word": "qualification",
|
||||
"translation": "квалификация",
|
||||
"definition": "a quality, skill, or attribute that makes someone suitable for a particular job or activity",
|
||||
"synonyms": ["credential", "competence"],
|
||||
"examples": [
|
||||
"Do you have any qualifications in project management?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"word": "experience",
|
||||
"translation": "опыт",
|
||||
"definition": "practical contact with and observation of facts or events, especially those gained through employment",
|
||||
"synonyms": ["background", "track record"],
|
||||
"examples": [
|
||||
"She has five years of experience in marketing."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"word": "skillset",
|
||||
"translation": "набор навыков",
|
||||
"definition": "the range of skills and abilities possessed by an individual",
|
||||
"synonyms": ["abilities", "talents"],
|
||||
"examples": [
|
||||
"Her skillset includes proficiency in several programming languages."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"word": "cover letter",
|
||||
"translation": "сопроводительное письмо",
|
||||
"definition": "a document sent with your resume that provides additional information on why you're qualified for the position",
|
||||
"synonyms": ["application letter", "letter of introduction"],
|
||||
"examples": [
|
||||
"Always include a well-written cover letter with your application."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"word": "hiring manager",
|
||||
"translation": "менеджер по найму",
|
||||
"definition": "the person responsible for making hiring decisions within a company or department",
|
||||
"synonyms": ["recruiter", "HR manager"],
|
||||
"examples": [
|
||||
"The hiring manager will review all applications and select candidates for interviews."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 20,
|
||||
"word": "job description",
|
||||
"translation": "описание вакансии",
|
||||
"definition": "a detailed account of the responsibilities, duties, required skills, and working conditions associated with a specific job",
|
||||
"synonyms": ["position profile", "role specification"],
|
||||
"examples": [
|
||||
"Read the job description carefully to understand what the employer is looking for."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 21,
|
||||
"word": "salary negotiation",
|
||||
"translation": "переговоры о зарплате",
|
||||
"definition": "the process of discussing and agreeing upon the compensation for a job, including salary, benefits, and other forms of remuneration",
|
||||
"synonyms": ["compensation discussion", "pay bargaining"],
|
||||
"examples": [
|
||||
"It's important to prepare for salary negotiations during the final stages of the interview process."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 22,
|
||||
"word": "reference",
|
||||
"translation": "рекомендация",
|
||||
"definition": "a person who can vouch for your qualifications, character, and work ethic, often contacted by potential employers",
|
||||
"synonyms": ["endorsement", "testimonial"],
|
||||
"examples": [
|
||||
"Be prepared to provide references from former supervisors or colleagues."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 23,
|
||||
"word": "component",
|
||||
"translation": "компонент",
|
||||
"definition": "A reusable piece of code that renders part of the user interface.",
|
||||
"synonyms": ["module", "widget"],
|
||||
"examples": [
|
||||
"In React, components are the building blocks of the UI."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 24,
|
||||
"word": "props",
|
||||
"translation": "пропсы",
|
||||
"definition": "Short for 'properties', these are read-only components passed down from parent components to child components.",
|
||||
"synonyms": ["attributes", "parameters"],
|
||||
"examples": [
|
||||
"Props allow you to pass data between components."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 25,
|
||||
"word": "state",
|
||||
"translation": "состояние",
|
||||
"definition": "An object that holds data specific to a component which may change over time.",
|
||||
"synonyms": ["data", "context"],
|
||||
"examples": [
|
||||
"Managing state is crucial for dynamic web applications."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 26,
|
||||
"word": "render",
|
||||
"translation": "рендеринг",
|
||||
"definition": "The process of updating the DOM to match the current state of a component.",
|
||||
"synonyms": ["update", "refresh"],
|
||||
"examples": [
|
||||
"React efficiently handles rendering to ensure smooth updates."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 27,
|
||||
"word": "virtual DOM",
|
||||
"translation": "виртуальный DOM",
|
||||
"definition": "A lightweight copy of the actual DOM maintained by React to improve performance by minimizing updates to the real DOM.",
|
||||
"synonyms": ["shadow tree", "virtual representation"],
|
||||
"examples": [
|
||||
"Virtual DOM allows React to update only necessary parts of the UI."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 28,
|
||||
"word": "JSX",
|
||||
"translation": "JSX",
|
||||
"definition": "A syntax extension to JavaScript used in React to describe what the user interface should look like.",
|
||||
"synonyms": ["template language", "syntax extension"],
|
||||
"examples": [
|
||||
"JSX makes it easier to write and understand React components."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 29,
|
||||
"word": "hooks",
|
||||
"translation": "хуки",
|
||||
"definition": "Functions that let you use state and other React features without writing a class.",
|
||||
"synonyms": ["functionalities", "utilities"],
|
||||
"examples": [
|
||||
"Hooks make functional components more powerful."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 30,
|
||||
"word": "event handling",
|
||||
"translation": "обработка событий",
|
||||
"definition": "The mechanism by which React components respond to user actions such as clicks, key presses, etc.",
|
||||
"synonyms": ["interaction management", "action response"],
|
||||
"examples": [
|
||||
"Event handlers in React allow you to define how components react to user interactions."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 31,
|
||||
"word": "lifecycle methods",
|
||||
"translation": "методы жизненного цикла",
|
||||
"definition": "Methods called at different stages of a component's existence, allowing developers to perform tasks at each stage.",
|
||||
"synonyms": ["phase callbacks", "stage handlers"],
|
||||
"examples": [
|
||||
"Lifecycle methods help manage the behavior of components throughout their lifecycle."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 32,
|
||||
"word": "routing",
|
||||
"translation": "маршрутизация",
|
||||
"definition": "The process of defining and managing navigation paths within a single-page application.",
|
||||
"synonyms": ["navigation control", "path management"],
|
||||
"examples": [
|
||||
"React Router is commonly used for routing in React apps."
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"id": 33,
|
||||
"word": "server-side",
|
||||
"translation": "серверная сторона",
|
||||
"definition": "Refers to operations performed by the server in contrast to client-side operations.",
|
||||
"synonyms": ["backend", "back-end"],
|
||||
"examples": [
|
||||
"Node.js is primarily used for server-side development."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 34,
|
||||
"word": "asynchronous",
|
||||
"translation": "асинхронный",
|
||||
"definition": "Programming model where operations execute independently of other operations, allowing efficient handling of multiple requests simultaneously.",
|
||||
"synonyms": ["non-blocking", "concurrent"],
|
||||
"examples": [
|
||||
"Node.js uses asynchronous I/O to handle many concurrent connections efficiently."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 35,
|
||||
"word": "callback",
|
||||
"translation": "коллбек",
|
||||
"definition": "A function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.",
|
||||
"synonyms": ["handler", "continuation"],
|
||||
"examples": [
|
||||
"Callbacks are widely used in Node.js for handling asynchronous operations."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 36,
|
||||
"word": "event loop",
|
||||
"translation": "цикл событий",
|
||||
"definition": "Mechanism in Node.js that handles asynchronous operations and ensures non-blocking I/O by offloading operations to the system kernel whenever possible.",
|
||||
"synonyms": ["event-driven architecture", "runtime environment"],
|
||||
"examples": [
|
||||
"The event loop is fundamental to understanding how Node.js works."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 37,
|
||||
"word": "package manager",
|
||||
"translation": "менеджер пакетов",
|
||||
"definition": "Tool used to install, update, configure, and remove packages in Node.js projects.",
|
||||
"synonyms": ["dependency manager", "library manager"],
|
||||
"examples": [
|
||||
"npm and yarn are popular package managers for Node.js."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 38,
|
||||
"word": "middleware",
|
||||
"translation": "промежуточное ПО",
|
||||
"definition": "Software that sits between an application and the backend infrastructure, providing additional functionality to the request-response cycle.",
|
||||
"synonyms": ["interceptor", "filter"],
|
||||
"examples": [
|
||||
"Express.js uses middleware to handle common tasks like logging, authentication, and error handling."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 39,
|
||||
"word": "REST API",
|
||||
"translation": "REST API",
|
||||
"definition": "Architectural style for building APIs using HTTP methods to perform CRUD operations on resources.",
|
||||
"synonyms": ["web service", "API design pattern"],
|
||||
"examples": [
|
||||
"Many Node.js applications implement RESTful APIs to communicate with clients."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 40,
|
||||
"word": "streams",
|
||||
"translation": "потоки",
|
||||
"definition": "Data structures that facilitate continuous transfer of data in chunks rather than loading everything into memory at once.",
|
||||
"synonyms": ["data flow", "pipeline"],
|
||||
"examples": [
|
||||
"Streams are useful for handling large files or continuous data in Node.js."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 41,
|
||||
"word": "cluster module",
|
||||
"translation": "модуль кластера",
|
||||
"definition": "Built-in module in Node.js that allows an application to be split into multiple processes running on separate CPU cores, improving performance and scalability.",
|
||||
"synonyms": ["multi-processing", "parallel execution"],
|
||||
"examples": [
|
||||
"Using the cluster module can significantly enhance the throughput of a Node.js application."
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 42,
|
||||
"word": "event emitter",
|
||||
"translation": "излучатель событий",
|
||||
"definition": "Class in Node.js that facilitates communication between objects in an application by emitting named events that other objects can listen to.",
|
||||
"synonyms": ["publisher-subscriber", "observer pattern"],
|
||||
"examples": [
|
||||
"Event emitters are useful for implementing custom event-based systems in Node.js."
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -3,6 +3,7 @@ const router = Router()
|
||||
|
||||
router.use('/eng-it-lean', require('./eng-it-lean/index'))
|
||||
router.use('/sberhubproject', require('./sberhubproject/index'))
|
||||
router.use('/sber_web', require('./sber_web/index'))
|
||||
|
||||
module.exports = router
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user