code upload

This commit is contained in:
Pavel Nedoshivkin 2024-06-16 18:03:31 +07:00
parent 20439c328c
commit 2572089394
11 changed files with 1759 additions and 64 deletions

47
Jenkinsfile vendored
View File

@ -1,47 +0,0 @@
pipeline {
agent {label 'html'}
stages {
stage('Check host') {
steps {
withCredentials(bindings: [sshUserPrivateKey(credentialsId: '301d16da-51e4-438d-abf7-51b88a05bcec', \
keyFileVariable: 'SSH_KEY_PEREC', usernameVariable: 'SSH_USERNAME')]) {
sh '''
ssh -i $SSH_KEY_PEREC -o StrictHostKeyChecking=no $SSH_USERNAME@172.16.0.22 "freebsd-version"
'''
}
}
}
stage('Deploy site rsync') {
steps {
withCredentials(bindings: [sshUserPrivateKey(credentialsId: '301d16da-51e4-438d-abf7-51b88a05bcec', \
keyFileVariable: 'SSH_KEY_PEREC', usernameVariable: 'SSH_USERNAME')]) {
sh '''
rsync -avz --delete -e "ssh -i $SSH_KEY_PEREC -o StrictHostKeyChecking=no" src/ $SSH_USERNAME@172.16.0.22:/home/$SSH_USERNAME/site/web_example_static/
'''
}
}
}
// stage ('Deploy site ssh){
// steps {
// withCredentials(bindings: [sshUserPrivateKey(credentialsId: '301d16da-51e4-438d-abf7-51b88a05bcec', \
// keyFileVariable: 'SSH_KEY_PEREC', usernameVariable: 'SSH_USERNAME')]) {
// sh '''
// scp -rp -i $SSH_KEY_PEREC -o StrictHostKeyChecking=no src/* $SSH_USERNAME@172.16.0.22:/home/$SSH_USERNAME/site/web_example_static/
// '''
// }
// }
// }
}
// post{
// success {
// echo "success"
// }
// failure {
// echo "failure"
// }
// }
}

View File

@ -1,5 +1,3 @@
# example_static
# API Docs
[![Build Status](https://jenkins.myhome.ru.net/buildStatus/icon?job=GiteaMyHome%2Fexample_static%2Fmain)](https://jenkins.myhome.ru.net/job/GiteaMyHome/job/example_static/job/main/)
Example HTML static website
API docs

View File

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example HTML5 site final</title>
<link rel="stylesheet" href="/css/style.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
</body>
</html>

1056
src/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
src/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "ecokam-openapi",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
}
}

85
src/routes/auth.js Normal file
View File

@ -0,0 +1,85 @@
/**
* @swagger
* tags:
* name: auth
* description: API авторизации
* /v1/auth/signup:
* post:
* summary: Регистрация нового пользователя
* tags: [auth]
* requestBody:
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* username:
* type: string
* email:
* type: string
* password:
* type: string
* responses:
* 200:
* description: Успешная регистрация нового пользователя
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: User was registered successfully!
* 500:
* description: Ошибка сервера
* /v1/auth/signin:
* post:
* summary: Авторизация существующего пользователя
* tags: [auth]
* requestBody:
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* username:
* type: string
* password:
* type: string
* responses:
* 200:
* description: Успешный вход
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* id:
* type: integer
* username:
* type: string
* email:
* type: string
* roles:
* type: array
* accessToken:
* type: string
* example:
* id: 1
* username: admin
* email: admin@eample.net
* roles: ["admin"]
* accessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzE3ODE4MzQ4LCJleHAiOjE3MTc5MDQ3NDh9.xdcOolYP8Sc_ls0VB1McdJItn0iU0Cuvpad67AERIXU
* 404:
* description: Пользователь не найден
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: User Not found.
*/

193
src/routes/file.js Normal file
View File

@ -0,0 +1,193 @@
/**
* @swagger
* components:
* schemas:
* FileEvent:
* type: object
* required:
* - id
* properties:
* id:
* type: string
* format: uuid
* description: UUID файла
* filename:
* type: string
* description: Имя файла
* eventdate:
* type: string
* format: date
* description: Дата события
* message:
* type: string
* description: Описание события
* latitude:
* type: string
* description: Широта
* longitude:
* type: string
* description: Долгота
* status:
* type: integer
* description: Статус
*
*/
/**
* @swagger
* tags:
* name: files
* description: API работы с файлами
* /v1/upload:
* post:
* summary: Загрузка файла
* tags: [files]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* requestBody:
* required: true
* content:
* multipart/form-data:
* schema:
* type: object
* properties:
* id:
* type: string
* format: uuid
* eventdate:
* type: string
* format: date
* message:
* type: string
* latitude:
* type: string
* longitude:
* type: string
* file:
* type: string
* format: binary
* encoding:
* file: # Property name
* contentType: image/png, image/jpeg
* headers: # Custom headers
* X-Custom-Header:
* description: This is a custom header
* schema:
* type: string
* responses:
* 200:
* description: Файл загружен
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: file was upload successfully!
* 500:
* description: Ошибка сервера
* /v1/files:
* get:
* summary: Список загруженых файлов
* tags: [files]
* responses:
* 200:
* description: Списов загруженых файлов
* content:
* application/json: # Media type
* schema:
* type: array
* items:
* $ref: '#/components/schemas/FileEvent'
* 500:
* description: Ошибка сервера
* /v1/files/{id}:
* get:
* summary: Проверить наличие файла по идетификатору
* tags: [files]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: string
* required: false
* description: Идентификатор файла
* responses:
* 200:
* description: Файл по идентификатору
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* status:
* type: boolean
* 404:
* description: Файл не найден
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* status:
* type: boolean
* default: false
* 500:
* description: Ошибка сервера
* /v1/event/{id}:
* put:
* summary: Обновить статус по идетификатору
* tags: [files]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: string
* required: false
* description: Идентификатор файла события
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: integer
* responses:
* 200:
* description: Статус события обновлен по идентификатору
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* 500:
* description: Ошибка сервера
*
*/

174
src/routes/role.js Normal file
View File

@ -0,0 +1,174 @@
/**
* @swagger
* components:
* schemas:
* Role:
* type: object
* required:
* - id
* - name
* properties:
* id:
* type: string
* description: Автогенерируемый идентификатор роли
* name:
* type: string
* description: Наименование роли
* example:
* id: 1
* name: admin
*/
/**
* @swagger
* tags:
* name: roles
* description: API управления ролями (административное)
* /v1/role:
* get:
* summary: Получить список ролей
* tags: [roles]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* responses:
* 200:
* description: Список всех ролей
* content:
* application/json:
* schema:
* type: array
* items:
* $ref: '#/components/schemas/Role'
* post:
* summary: Создание новой роли
* tags: [roles]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* requestBody:
* required: true
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* name:
* type: string
* responses:
* 200:
* description: Роль создана
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: Role was create successfully!
* 500:
* description: Ошибка сервера
* /v1/roles/{id}:
* get:
* summary: Получить роль по идентификатору
* tags: [roles]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Идентификатор роли
* responses:
* 200:
* description: Роль по идентификатору
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Role'
* 404:
* description: Роль не найдена
* put:
* summary: Изменение роли по идентификатору
* tags: [roles]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Идентификатор роли
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Role'
* responses:
* 200:
* description: The role was updated
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: Role was update successfully!
* 404:
* description: Роль не найдена
* 500:
* description: Ошибка сервера
* delete:
* summary: Удаление роли по идентификатору
* tags: [roles]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Идентификатор роли
* responses:
* 200:
* description: Роль удалена
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: Role was delete successfully!
* 404:
* description: Роль не найдена
*/

191
src/routes/user.js Normal file
View File

@ -0,0 +1,191 @@
/**
* @swagger
* components:
* schemas:
* User:
* type: object
* required:
* - id
* - username
* - email
* - password
* - role
* properties:
* id:
* type: string
* description: Автогенерируемый идентификатор поьзователя
* name:
* type: string
* description: Имя пользователя
* password:
* type: string
* description: Пароль
* role:
* type: array
* description: Список ролей доступных пользователю
* example:
* id: 1
* username: user
* email: "user@example.net"
* password: secretpassword
* roles: [ "user", "moderator"]
*/
/**
* @swagger
* tags:
* name: users
* description: API управления пользователями (административное)
* /v1/user:
* get:
* summary: Список всех пользователей
* tags: [users]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* responses:
* 200:
* description: Список всех пользователей
* content:
* application/json:
* schema:
* type: array
* items:
* $ref: '#/components/schemas/User'
* example:
* id: 1
* username: user1
* email: "user1@example.net"
* password: secretpassword1
* roles: [ "user", "moderator"]
*
* post:
* summary: Создание нового пользователя
* tags: [users]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/User'
* responses:
* 200:
* description: Пользователь успешно создан
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: User was registered successfully!
* 500:
* description: Ошибка сервера
* /v1/users/{id}:
* get:
* summary: Получить пользователя по идетификатору
* tags: [users]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Идентификатор пользователя
* responses:
* 200:
* description: Пользователь по идентификатору
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/User'
* 404:
* description: Пользователь не найден
* put:
* summary: Изменение пользователя по идентификатору
* tags: [users]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Идентификатор пользователя
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/User'
* responses:
* 200:
* description: Данные пользователя изменены
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: User was update successfully!
* 404:
* description: Пользователь не найден
* 500:
* description: Ошибка сервера
* delete:
* summary: Удаление пользователя по идентификатору
* tags: [users]
* parameters:
* - in: header
* name: x-access-token
* schema:
* type: string
* required: true
* description: Токен авторизации
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Идентификатор пользователя
*
* responses:
* 200:
* description: Пользователь удален
* content:
* application/json: # Media type
* schema: # Request body contents
* type: object
* properties:
* message:
* type: string
* example:
* message: User was delete successfully!
* 404:
* description: Пользователь не найден
*/

43
src/server.js Normal file
View File

@ -0,0 +1,43 @@
const express = require("express"),
bodyParser = require("body-parser"),
swaggerJsdoc = require("swagger-jsdoc"),
swaggerUi = require("swagger-ui-express");
const app = express();
const options = {
definition: {
openapi: "3.1.0",
info: {
title: "ECOKAM API",
// version: "0.1.0",
description:
"Документация по API",
},
servers: [
{
url: "http://127.0.0.1:3201/",
},
{
url: "https://api.beartrack.ru/",
},
],
},
apis: ["./routes/*.js"],
};
const specs = swaggerJsdoc(options);
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(specs)
);
const PORT = process.env.PORT || 3200;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});