Spaces:
Sleeping
Sleeping
DmitrMakeev
commited on
Commit
•
1258d21
1
Parent(s):
e5e0e06
Update app.py
Browse files
app.py
CHANGED
@@ -4,42 +4,19 @@ import sqlite3
|
|
4 |
import os
|
5 |
import uuid
|
6 |
|
7 |
-
import json
|
8 |
-
import base64
|
9 |
-
import unittest
|
10 |
-
import requests
|
11 |
-
|
12 |
-
own_url = os.getenv('own_url')
|
13 |
-
key_d = os.getenv('gc_api')
|
14 |
-
gc_url = os.getenv('gc_url')
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
import json
|
21 |
-
from datetime import datetime
|
22 |
-
|
23 |
-
import whatsapp_api_webhook_server_python.webhooksHandler as handler
|
24 |
-
|
25 |
app = Flask(__name__, template_folder="./")
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
app.config['DEBUG'] = True
|
31 |
|
32 |
UPLOAD_FOLDER = 'static'
|
|
|
33 |
|
34 |
-
|
35 |
-
# Создание директории, если она не существует
|
36 |
if not os.path.exists(UPLOAD_FOLDER):
|
37 |
os.makedirs(UPLOAD_FOLDER)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
@app.route('/upload', methods=['POST'])
|
45 |
def upload_file():
|
@@ -66,22 +43,30 @@ def uploaded_file(filename):
|
|
66 |
def up_fa():
|
67 |
return render_template('up_fa.html')
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
if __name__ == '__main__':
|
87 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
4 |
import os
|
5 |
import uuid
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
app = Flask(__name__, template_folder="./")
|
8 |
|
|
|
|
|
|
|
9 |
app.config['DEBUG'] = True
|
10 |
|
11 |
UPLOAD_FOLDER = 'static'
|
12 |
+
HTML_FOLDER = 'html'
|
13 |
|
14 |
+
# Создание директорий, если они не существуют
|
|
|
15 |
if not os.path.exists(UPLOAD_FOLDER):
|
16 |
os.makedirs(UPLOAD_FOLDER)
|
17 |
|
18 |
+
if not os.path.exists(HTML_FOLDER):
|
19 |
+
os.makedirs(HTML_FOLDER)
|
|
|
|
|
20 |
|
21 |
@app.route('/upload', methods=['POST'])
|
22 |
def upload_file():
|
|
|
43 |
def up_fa():
|
44 |
return render_template('up_fa.html')
|
45 |
|
46 |
+
@app.route('/up_page', methods=['POST'])
|
47 |
+
def upload_page():
|
48 |
+
if 'file' not in request.files:
|
49 |
+
return "No file part", 400
|
50 |
+
file = request.files['file']
|
51 |
+
if file.filename == '':
|
52 |
+
return "No selected file", 400
|
53 |
+
|
54 |
+
filename = request.form.get('filename')
|
55 |
+
if not filename:
|
56 |
+
return "Filename is required", 400
|
57 |
+
|
58 |
+
save_path = os.path.join(HTML_FOLDER, filename + '.html')
|
59 |
+
file.save(save_path)
|
60 |
+
|
61 |
+
# Возвращаем полный URL загруженного файла с протоколом https
|
62 |
+
full_url = request.url_root.replace('http://', 'https://') + filename
|
63 |
+
return f"Page uploaded successfully and saved to {full_url}", 200
|
64 |
+
|
65 |
+
@app.route('/<path:filename>', methods=['GET'])
|
66 |
+
def serve_html(filename):
|
67 |
+
if not filename.endswith('.html'):
|
68 |
+
filename += '.html'
|
69 |
+
return send_from_directory(HTML_FOLDER, filename)
|
70 |
|
71 |
if __name__ == '__main__':
|
72 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|