Merge branch 'final-system' into server-tx
This commit is contained in:
commit
99666d40d6
0
server-rx/files/.gitkeep
Normal file
0
server-rx/files/.gitkeep
Normal file
8
server-rx/gunicorn.py
Normal file
8
server-rx/gunicorn.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
with open("server-rx.json", 'r', encoding = "utf-8") as file:
|
||||||
|
server_data = json.load(file)
|
||||||
|
|
||||||
|
bind = f"{server_data['ip']}:{server_data['port']}"
|
||||||
|
workers = 2
|
||||||
|
timeout = 120
|
9
server-rx/requirements.txt
Normal file
9
server-rx/requirements.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
blinker==1.9.0
|
||||||
|
click==8.1.8
|
||||||
|
Flask==3.1.0
|
||||||
|
gunicorn==23.0.0
|
||||||
|
itsdangerous==2.2.0
|
||||||
|
Jinja2==3.1.5
|
||||||
|
MarkupSafe==3.0.2
|
||||||
|
packaging==24.2
|
||||||
|
Werkzeug==3.1.3
|
5
server-rx/server-rx.json
Normal file
5
server-rx/server-rx.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"port": 33333,
|
||||||
|
"secret": "PROJECT_BY_GAZAKBAYEV_AHMET"
|
||||||
|
}
|
37
server-rx/wsgi_back.py
Normal file
37
server-rx/wsgi_back.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
from flask import Flask, request
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
SECRET = None
|
||||||
|
|
||||||
|
with open("server-rx.json", 'r', encoding = "utf-8") as file:
|
||||||
|
server_data = json.load(file)
|
||||||
|
SECRET = server_data['secret']
|
||||||
|
|
||||||
|
def go_to_print(file_path, samples):
|
||||||
|
os.system(f"lp -n {samples} {file_path}")
|
||||||
|
|
||||||
|
@app.route('/printfile', methods=['POST'])
|
||||||
|
def print_file():
|
||||||
|
if 'file' not in request.files:
|
||||||
|
return 'Файл не был предоставлен.', 400
|
||||||
|
if 'secret-key' not in request.form:
|
||||||
|
return 'Секретный ключ не был предоставлен.', 400
|
||||||
|
if request.form['secret-key'] != SECRET:
|
||||||
|
return 'Авторизация не удалась.', 400
|
||||||
|
file = request.files['file']
|
||||||
|
filename = "files/" + file.filename
|
||||||
|
with open(filename, 'wb') as f:
|
||||||
|
f.write(file.read())
|
||||||
|
samples = 1
|
||||||
|
if b'samples' in request.data:
|
||||||
|
samples = request.data[b'samples']
|
||||||
|
try:
|
||||||
|
go_to_print(filename, samples)
|
||||||
|
return 'Файл отправлен на печать.', 200
|
||||||
|
except Exception as e:
|
||||||
|
return f'Ошибка при печати файла: {str(e)}.', 500
|
||||||
|
finally:
|
||||||
|
return 'OK', 200
|
Loading…
x
Reference in New Issue
Block a user