From d444a33c98241465a70751e7a98c5899e8f56e81 Mon Sep 17 00:00:00 2001 From: mrekk-hub Date: Sat, 22 Feb 2025 12:25:56 +0300 Subject: [PATCH 1/5] Add server side --- playground/server/Dockerfile | 9 ++++++++ playground/server/app.py | 34 ++++++++++++++++++++++++++++ playground/server/docker-compose.yml | 22 ++++++++++++++++++ playground/server/requirements.txt | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 playground/server/Dockerfile create mode 100644 playground/server/app.py create mode 100644 playground/server/docker-compose.yml create mode 100644 playground/server/requirements.txt diff --git a/playground/server/Dockerfile b/playground/server/Dockerfile new file mode 100644 index 0000000..06d2212 --- /dev/null +++ b/playground/server/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.12 + +WORKDIR /app + +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["python", "app.py"] diff --git a/playground/server/app.py b/playground/server/app.py new file mode 100644 index 0000000..0f4031a --- /dev/null +++ b/playground/server/app.py @@ -0,0 +1,34 @@ +import os +from flask import Flask, jsonify +from flask_pymongo import PyMongo + +app = Flask(__name__) + +# Подключение к локальной MongoDB +app.config["MONGO_URI"] = os.getenv("MONGO_URI", "mongodb://localhost:27017/testdb") +mongo = PyMongo(app) + + +@app.route("/") +def home(): + return jsonify({"message": "Flask + MongoDB works!"}) + + +@app.route("/insert") +def insert_data(): + """Тестовая вставка данных в коллекцию 'users'""" + users = mongo.db.users + user_id = users.insert_one({"name": "Test user", "age": 25}).inserted_id + return jsonify({"message": "User was added", "id": str(user_id)}) + + +@app.route("/get_users") +def get_users(): + """Получение всех пользователей из коллекции 'users'""" + users = mongo.db.users.find() + result = [{"id": str(user["_id"]), "name": user["name"], "age": user["age"]} for user in users] + return jsonify(result) + + +if __name__ == "__main__": + app.run(host="0.0.0.0", debug=True) diff --git a/playground/server/docker-compose.yml b/playground/server/docker-compose.yml new file mode 100644 index 0000000..8247008 --- /dev/null +++ b/playground/server/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.8" + +services: + flask_app: + build: . + ports: + - "5000:5000" + depends_on: + - mongodb + environment: + - MONGO_URI=mongodb://mongodb:27017/testdb + + mongodb: + image: mongo:latest + container_name: mongodb + ports: + - "27017:27017" + volumes: + - mongo_data:/data/db + +volumes: + mongo_data: diff --git a/playground/server/requirements.txt b/playground/server/requirements.txt new file mode 100644 index 0000000..05a7bdd --- /dev/null +++ b/playground/server/requirements.txt @@ -0,0 +1,2 @@ +flask +flask-pymongo \ No newline at end of file From ae5041c512775bb5ed8bd131a4b9742407975a8d Mon Sep 17 00:00:00 2001 From: mrekk-hub Date: Sat, 22 Feb 2025 13:58:06 +0300 Subject: [PATCH 2/5] Add client side --- playground/client/background.js | 3 ++ playground/client/icon.png | Bin 0 -> 4191 bytes playground/client/manifest.json | 18 +++++++++++ playground/client/popup.html | 34 +++++++++++++++++++++ playground/client/popup.js | 52 ++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 playground/client/background.js create mode 100644 playground/client/icon.png create mode 100644 playground/client/manifest.json create mode 100644 playground/client/popup.html create mode 100644 playground/client/popup.js diff --git a/playground/client/background.js b/playground/client/background.js new file mode 100644 index 0000000..76e5a8e --- /dev/null +++ b/playground/client/background.js @@ -0,0 +1,3 @@ +chrome.action.onClicked.addListener((tab) => { + chrome.tabs.create({ url: chrome.runtime.getURL("popup.html") }); +}); \ No newline at end of file diff --git a/playground/client/icon.png b/playground/client/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..63a8661501b362b266191bacd494279810fc76f7 GIT binary patch literal 4191 zcmV-l5TNggP)4^;+1c6C)6@L?{Jgxp^z`)L;NZ#0$SkSoGU9U5D*YKIXQ)eg&iFo>FMcOT3TdeWTvL3baZqV7Z*=YPew*Y zYinzajEr${aX>&oF)=YoNlANqdzhG*x4bq1000k`NklL+7+u`}|Xh-)Qz!oxam zu&Z@ve>=5;(P%X8_xt1DKZDlkw(qQS1=9LZmo3@eWYhM!Y4zLQAfx5LYxi55&ult3 z?YB~5MsJ@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^>L>(ZVlDxIMf|XI zge#*ET;Ht32N;x=JFzkfVHak_>oCeP@h0koA_l3fx z>|`%4qD?e`dRetFm2K~L#i)7C_7LZ~*=P0cfG|nH|1aWmwuiyt@`}8RVqGK;eCjDi}zA%fzFD{OEo3rAfbD`%sn@I|y2+n@PH ziJ^V*%0i4?@x>{I_+CyE1TRVN%>2P)JqwA9(>!xG2k^mbd4*S%koh!}A6ShE4doZt zmMj{PM+=x4y!W1d?fOF^4V09NgksP;whS6c?>%wf>KE!|aL`9J;m2Fsd%d$F z`w`_ZDe-~lI&w?OqYrIFd%L>H?zh%obM=|I7qOjXxuLI zGyuMOOU*vMe$#n))Q0lmCh;&d@Mx~;ql@<0qnqdCOy4)qh@{Bp_}DsXlE^7+lN^b4y=mLG&4rR@KigX)`?7^c>7 z-B(-@%UF5J?nJm3pczQ>s{9M` z>lN7NSM( literal 0 HcmV?d00001 diff --git a/playground/client/manifest.json b/playground/client/manifest.json new file mode 100644 index 0000000..972a51b --- /dev/null +++ b/playground/client/manifest.json @@ -0,0 +1,18 @@ +{ + "manifest_version": 3, + "name": "Screen Recorder Extension", + "version": "1.0", + "description": "Расширение для записи экрана", + "permissions": [ + "tabs", + "activeTab" + ], + "action": { + "default_popup": "popup.html", + "default_icon": { + "16": "icon.png", + "48": "icon.png", + "128": "icon.png" + } + } +} diff --git a/playground/client/popup.html b/playground/client/popup.html new file mode 100644 index 0000000..dcc6a2d --- /dev/null +++ b/playground/client/popup.html @@ -0,0 +1,34 @@ + + + + + + Запись экрана + + + +

Запись экрана

+ + + + + + + + + + diff --git a/playground/client/popup.js b/playground/client/popup.js new file mode 100644 index 0000000..5ba0017 --- /dev/null +++ b/playground/client/popup.js @@ -0,0 +1,52 @@ +const startBtn = document.getElementById("start-btn"); +const stopBtn = document.getElementById("stop-btn"); +const usernameInput = document.getElementById("username"); + +let mediaRecorder; +let chunks = []; + +startBtn.addEventListener("click", async () => { + const username = usernameInput.value.trim(); + + if (!username) { + alert("Введите имя пользователя!"); + return; + } + + try { + const stream = await navigator.mediaDevices.getDisplayMedia({ video: true }); + + mediaRecorder = new MediaRecorder(stream); + chunks = []; + + mediaRecorder.ondataavailable = event => chunks.push(event.data); + mediaRecorder.onstop = () => { + const blob = new Blob(chunks, { type: 'video/webm' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = `${username}_recording.webm`; // Имя пользователя в названии файла + a.click(); + + stopBtn.style.display = "none"; + startBtn.style.display = "inline-block"; + }; + + mediaRecorder.start(); + console.log("Запись началась"); + + startBtn.style.display = "none"; + stopBtn.style.display = "inline-block"; + + } catch (error) { + console.error("Ошибка при получении доступа к экрану:", error); + } +}); + +stopBtn.addEventListener("click", () => { + if (mediaRecorder && mediaRecorder.state !== "inactive") { + mediaRecorder.stop(); + console.log("Запись остановлена"); + } +}); From b339fde690bed59a5afc51a66f29b166914d69ee Mon Sep 17 00:00:00 2001 From: mrekk-hub Date: Sat, 22 Feb 2025 15:05:41 +0300 Subject: [PATCH 3/5] Add README.md + move directories --- playground/shlyahtin/README.md | 27 ++++++++++++++++++ .../{ => shlyahtin}/client/background.js | 0 playground/{ => shlyahtin}/client/icon.png | Bin .../{ => shlyahtin}/client/manifest.json | 0 playground/{ => shlyahtin}/client/popup.html | 0 playground/{ => shlyahtin}/client/popup.js | 0 playground/{ => shlyahtin}/server/Dockerfile | 0 playground/{ => shlyahtin}/server/app.py | 0 .../{ => shlyahtin}/server/docker-compose.yml | 0 .../{ => shlyahtin}/server/requirements.txt | 0 10 files changed, 27 insertions(+) create mode 100644 playground/shlyahtin/README.md rename playground/{ => shlyahtin}/client/background.js (100%) rename playground/{ => shlyahtin}/client/icon.png (100%) rename playground/{ => shlyahtin}/client/manifest.json (100%) rename playground/{ => shlyahtin}/client/popup.html (100%) rename playground/{ => shlyahtin}/client/popup.js (100%) rename playground/{ => shlyahtin}/server/Dockerfile (100%) rename playground/{ => shlyahtin}/server/app.py (100%) rename playground/{ => shlyahtin}/server/docker-compose.yml (100%) rename playground/{ => shlyahtin}/server/requirements.txt (100%) diff --git a/playground/shlyahtin/README.md b/playground/shlyahtin/README.md new file mode 100644 index 0000000..b35819a --- /dev/null +++ b/playground/shlyahtin/README.md @@ -0,0 +1,27 @@ +# Прототип локального прокторинга + +## Client + +### 1. Подготовьте папку с расширением + +- `manifest.json` +- `background.js` +- `popup.html` +- `popup.js` +- `icon.png` +### 2. Откройте Google Chrome +### 3. Перейдите в раздел "Расширения" +Адрес `chrome://extensions` +### 4. Включите режим разработчика +### 5. Загрузите распакованное расширение +### 6. Откройте расширение + +## Server + +### 1. Соберите и запустите контейнеры: + +`docker-compose up --build` + +### 2. После запуска откройте браузер и перейдите по адресу: + +`http://localhost:5000/` \ No newline at end of file diff --git a/playground/client/background.js b/playground/shlyahtin/client/background.js similarity index 100% rename from playground/client/background.js rename to playground/shlyahtin/client/background.js diff --git a/playground/client/icon.png b/playground/shlyahtin/client/icon.png similarity index 100% rename from playground/client/icon.png rename to playground/shlyahtin/client/icon.png diff --git a/playground/client/manifest.json b/playground/shlyahtin/client/manifest.json similarity index 100% rename from playground/client/manifest.json rename to playground/shlyahtin/client/manifest.json diff --git a/playground/client/popup.html b/playground/shlyahtin/client/popup.html similarity index 100% rename from playground/client/popup.html rename to playground/shlyahtin/client/popup.html diff --git a/playground/client/popup.js b/playground/shlyahtin/client/popup.js similarity index 100% rename from playground/client/popup.js rename to playground/shlyahtin/client/popup.js diff --git a/playground/server/Dockerfile b/playground/shlyahtin/server/Dockerfile similarity index 100% rename from playground/server/Dockerfile rename to playground/shlyahtin/server/Dockerfile diff --git a/playground/server/app.py b/playground/shlyahtin/server/app.py similarity index 100% rename from playground/server/app.py rename to playground/shlyahtin/server/app.py diff --git a/playground/server/docker-compose.yml b/playground/shlyahtin/server/docker-compose.yml similarity index 100% rename from playground/server/docker-compose.yml rename to playground/shlyahtin/server/docker-compose.yml diff --git a/playground/server/requirements.txt b/playground/shlyahtin/server/requirements.txt similarity index 100% rename from playground/server/requirements.txt rename to playground/shlyahtin/server/requirements.txt From 6588219695aa8f00f5bbba61e89303c9eb127406 Mon Sep 17 00:00:00 2001 From: mrekk-hub Date: Sun, 23 Feb 2025 12:43:32 +0300 Subject: [PATCH 4/5] Applied suggested fixes --- playground/shlyahtin/server/app.py | 21 ++++++++----- .../shlyahtin/server/docker-compose.yml | 30 +++++++++---------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/playground/shlyahtin/server/app.py b/playground/shlyahtin/server/app.py index 0f4031a..fc218bb 100644 --- a/playground/shlyahtin/server/app.py +++ b/playground/shlyahtin/server/app.py @@ -5,7 +5,7 @@ app = Flask(__name__) # Подключение к локальной MongoDB -app.config["MONGO_URI"] = os.getenv("MONGO_URI", "mongodb://localhost:27017/testdb") +app.config["MONGO_URI"] = os.getenv("MONGO_URI") mongo = PyMongo(app) @@ -17,18 +17,23 @@ def home(): @app.route("/insert") def insert_data(): """Тестовая вставка данных в коллекцию 'users'""" - users = mongo.db.users - user_id = users.insert_one({"name": "Test user", "age": 25}).inserted_id - return jsonify({"message": "User was added", "id": str(user_id)}) + try: + users = mongo.db.users + user_id = users.insert_one({"name": "Test user", "age": 25}).inserted_id + return jsonify({"message": "User was added", "id": str(user_id)}) + except Exception as e: + return f"Error while inserting data : {e}" @app.route("/get_users") def get_users(): """Получение всех пользователей из коллекции 'users'""" - users = mongo.db.users.find() - result = [{"id": str(user["_id"]), "name": user["name"], "age": user["age"]} for user in users] - return jsonify(result) - + try: + users = mongo.db.users.find() + result = [{"id": str(user["_id"]), "name": user["name"], "age": user["age"]} for user in users] + return jsonify(result) + except Exception as e: + return f"Error while extracting data : {e}" if __name__ == "__main__": app.run(host="0.0.0.0", debug=True) diff --git a/playground/shlyahtin/server/docker-compose.yml b/playground/shlyahtin/server/docker-compose.yml index 8247008..c5cacf1 100644 --- a/playground/shlyahtin/server/docker-compose.yml +++ b/playground/shlyahtin/server/docker-compose.yml @@ -1,22 +1,22 @@ -version: "3.8" +version: '3.8' services: + mongodb: + image: mongo:6.0 # Фиксируем версию, чтобы избежать неожиданных обновлений + container_name: mongodb + restart: always + env_file: + - .env # Переменные теперь загружаются из .env + ports: + - ${MONGO_PORT}:${MONGO_PORT} # Используем переменную из .env + flask_app: build: . + container_name: flask_app + restart: always ports: - - "5000:5000" + - ${FLASK_PORT}:${FLASK_PORT} depends_on: - mongodb - environment: - - MONGO_URI=mongodb://mongodb:27017/testdb - - mongodb: - image: mongo:latest - container_name: mongodb - ports: - - "27017:27017" - volumes: - - mongo_data:/data/db - -volumes: - mongo_data: + env_file: + - .env From f8c2b5b38efe1925e8d2e68c67695e2ec386429f Mon Sep 17 00:00:00 2001 From: mrekk-hub Date: Sun, 23 Feb 2025 18:20:56 +0300 Subject: [PATCH 5/5] Add .env file --- playground/shlyahtin/server/.env | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 playground/shlyahtin/server/.env diff --git a/playground/shlyahtin/server/.env b/playground/shlyahtin/server/.env new file mode 100644 index 0000000..e6411bd --- /dev/null +++ b/playground/shlyahtin/server/.env @@ -0,0 +1,3 @@ +MONGO_URI=mongodb://mongodb:27017/testdb +MONGO_PORT=27017 +FLASK_PORT=5000 \ No newline at end of file