Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.vscode
.git
.gitignore
.husky
*.env

logs/*
tests/*

Dockerfile
docker-compose.yml

ecosystem.config.json
6 changes: 4 additions & 2 deletions .example.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
API_KEY="" # https://300.ya.ru/ -> API -> Получить токен -> Войти как ...
YANDEX_COOKIE="Session_id=XXXX;" # !!! Required Session_id COOKIE! You can log in to your account and then from any request to yandex catch them. AT YOUR OWN RISK !!!
SERVICE_PORT=3312
USE_WORKER="false"
API_TOKEN="" # For get sharing url
# SESSION_ID_COOKIE="XXXX" # If lib YaHMAC is invalid you can set your cookies and summarize articles/text (video requires valid YaHMAC)
148 changes: 14 additions & 134 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,134 +1,14 @@
# Editor
.vscode

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
logs/
backups/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
.vscode
.env

# dependencies
/node_modules

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

**/*.log
**/*.bun
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

bunx pretty-quick --staged
3 changes: 3 additions & 0 deletions .oxlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.d.ts
ecosystem.config.js
eslint.config.js
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 100,
"tabWidth": 2,
"semi": true,
"trailingComma": "all"
}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM oven/bun:latest AS base
WORKDIR /usr/src/app

FROM base AS release
COPY package.json bun.lock tsconfig.json ./
COPY src src
RUN bun install

ENV SERVICE_PORT=3312
# ENV USE_WORKER="true"
# ENV WORKER_HOST="http://127.0.0.1:7674/browser"
# ENV WORKER_HOST_TH="http://127.0.0.1:7674/th"
# ENV API_TOKEN=""

ENTRYPOINT [ "bun", "run", "start" ]
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2023 FOSWLY

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2023 FOSWLY
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
103 changes: 66 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,76 @@
## [FOSWLY] Summarize Backend
## Summarize Backend

[![Python Version](https://img.shields.io/badge/Python-3.11-blue?logo=python&style=for-the-badge)](https://www.python.org/)
[![GitHub Stars](https://img.shields.io/github/stars/FOSWLY/summarize-backend?logo=github&style=for-the-badge)](https://github.com/FOSWLY/summarize-backend/stargazers)
[![GitHub Issues](https://img.shields.io/github/issues/FOSWLY/summarize-backend?style=for-the-badge)](https://github.com/FOSWLY/summarize-backend/issues)
[![Current Version](https://img.shields.io/github/v/release/FOSWLY/summarize-backend?style=for-the-badge)](https://github.com/FOSWLY/summarize-backend)
[![GitHub License](https://img.shields.io/github/license/FOSWLY/summarize-backend?style=for-the-badge)](https://github.com/FOSWLY/summarize-backend/blob/master/LICENSE)

**[FOSWLY] Summarize Backend** - cервер, который реализует Yandex Summarize API для нашего браузерного расширения. Сервер не содержит никакой авторизации и может быть использован для ваших проектов.
**Summarize Backend** - cервер, унифицированные конечные точки для API суммаризации из библиотеки [@toil/neurojs](https://github.com/FOSWLY/neurojs).

## 📝 Функционал
- Суммаризатор статей
- Суммаризатор видео

- Суммаризация статей
- Суммаризация текста
- Суммаризация видео
- Получение ссылки на суммаризацию статей (необходимо указать токен к оф. апи)
- Получение суммаризации по токену (`https://300.ya.ru/TOKEN`)

## 📦 Деплой
1. Установите Python 3.11 (на других версиях не тестировался)
2. Клонируйте репозиторий
3. Установите зависимости: `pip install -r requirements.txt`
4. Заполните конфиг: `app/settings.py`
5. Переименуйте `.example.env` --> `.env`
6. Заполните: `.env`
7. Запустите сервер: `python3 -OO main.py`

## ⚙️ Заполнение .env
1. Переименуйте `.example.env` в `.env`
2. Получение `API_KEY`:
1. Перейдите на сайт [300.ya.ru](https://300.ya.ru/)
2. Внизу нажмите на "API"
3. В появившейся панельке нажмите "Получить токен"
4. Авторизуйтесь, если вы не авторизованы
5. Вставьте полученный токен в `.env`
3. Получение `YANDEX_COOKIE`:
1. Перейдите на сайт [300.ya.ru](https://300.ya.ru/)
2. Авторизуйтесь, если вы не авторизованы. Лучше всего использовать не основной аккаунт, поскольку **все действия выполняются на ваш страх и риск**.
3. Откройте DevTools (F12 или Ctrl+Shift+I)
4. Перейдите в Application

P.S. В некоторых браузерах этого пункта нету. В них вы должны сразу перейти в Storage.
5. Выберите Storage
6. Выберите Cookies
7. Найдите куки с именем `Session_id` и скопируйте ее значение
8. Вставьте скопированное значение заместо XXXX в `.env`

## 📖 Зачем нужен свой сервер, почему бы не использовать API напрямую?
В использование API напрямую есть несколько проблемы из-за которых мы от этого отказались:
1. Для работы с Yandex Summarize API нужна авторизация, т.е. необходимо посылать запросы с токеном/куки, которые не хотелось бы лишний раз "палить" на клиенте.
2. У некоторых пользователей могут быть заблокированы сервера Yandex и прямой запрос бы просто не прошёл.

### С Docker

1. Установите Docker
2. Соберите образ

```bash
docker build -t "summarize-backend" .
```

3. Запустите контейнер

```bash
docker run -p 3312:3312 summarize-backend
```

### Вручную

1. Установите [Bun](https://bun.sh/)
2. Клонируйте репозиторий:

```bash
git clone https://github.com/FOSWLY/summarize-backend
```

3. Установите зависимости

```bash
bun install
```

3.1. (опционально) Переименуйте `.example.env` в `.env` и заполните необходимые поля

4. Запустите сервер

```bash
bun start
```

Если вы хотите использовать PM2:

1. Установите зависимости:

```bash
bun install -g pm2-beta && pm2 install pm2-logrotate
```

2. Запустите сервер

```bash
pm2 start ecosystem.config.json
```

## 📖 Кому это будет полезно

1. Если вы хотите использовать логику из [neurojs](https://github.com/FOSWLY/neurojs) с помощью другого языка программирования, но не хотите переносить весь функционал в ваш код
2. Если вы не хотите тянуть зависимости от neurojs
3. Если вы хотите иметь простой унифицированный апи
Loading