-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
143 lines (110 loc) · 3.75 KB
/
Copy pathapp.py
File metadata and controls
143 lines (110 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from flask import Flask
from flask import render_template, session, redirect, request, url_for
from flask_bootstrap import Bootstrap
import drive
import tool
from config import AccountSetting
temp_path = ''
# temp_path = ''
app = Flask(__name__)
bootstrap = Bootstrap(app)
app.secret_key = 'P02r31j/3yX R~XHH!nmN]LWX/,?XT'
@app.route('/')
def index():
return render_template('index.html')
# @app.route('/loading')
@app.route('/loading/<file_type>/<path>', methods=['GET', 'POST'])
def loading(path, file_type):
global temp_path
temp_path = path
# print(temp_path)
# print(file_type)
return render_template('loading.html', file_type=file_type)
@app.route('/netdrive/<path>', methods=['GET', 'POST'])
def net_drive(path):
content = drive.win_nt(path)
seg_path = drive.div_path(path)
# for i in seg_path:
# print(i)
if content is not None:
return render_template('netdrive.html', u=content, u1=seg_path)
else:
return render_template('error.html')
@app.route('/netdrive')
def net_drive_main():
content = drive.win_nt('')
return render_template('netdrive.html', u=content)
@app.route('/video', methods=['GET', 'POST'])
def video():
global temp_path
file_name = drive.get_filename(temp_path)
drive.copy_file_to_cache(temp_path)
temp_path = ''
return render_template('video.html', file_name=file_name)
@app.route('/audio', methods=['GET', 'POST'])
def audio():
global temp_path
file_name = drive.get_filename(temp_path)
drive.copy_file_to_cache(temp_path)
temp_path = ''
return render_template('audio.html', file_name=file_name)
@app.route('/image', methods=['GET', 'POST'])
def image():
global temp_path
file_name = drive.get_filename(temp_path)
drive.copy_file_to_cache(temp_path)
temp_path = ''
return render_template('image.html', file_name=file_name)
@app.route('/text', methods=['GET', 'POST'])
def text():
global temp_path
file_name = drive.get_filename(temp_path)
drive.copy_file_to_cache(temp_path)
temp_path = ''
return render_template('text.html', file_name=file_name)
@app.route('/login', methods=['POST', 'GET'])
def login():
conf = AccountSetting()
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if username == conf.get_username() and password == conf.get_password():
session['username'] = request.form['username']
return redirect(url_for('index'))
else:
redirect(url_for('login'))
return render_template('login.html')
@app.route('/logout')
def logout():
# delete all files in cache
drive.delete_cache()
# remove the username from the session if it's there
session.pop('username', None)
return render_template('logout.html')
@app.before_request
def before_login():
if 'username' not in session and request.endpoint != 'login':
return redirect(url_for('login'))
@app.route('/file', methods=['GET', 'POST'])
def file():
global temp_path
file_name = drive.get_filename(temp_path)
drive.copy_file_to_cache(temp_path)
temp_path = ''
return render_template('file.html', file_name=file_name)
@app.route('/test')
def test():
return render_template('test.html')
@app.route('/upload')
def upload():
return render_template('upload.html')
@app.route('/get-upload', methods=['POST'])
def get_upload():
uploaded_file = request.files.get('file')
if not uploaded_file:
return 'need file'
uploaded_file.save('uploaded_file/%s' % uploaded_file.filename)
return render_template('get-upload.html')
if __name__ == '__main__':
local_network_address = tool.get_local_adr()
app.run(debug=True, host=local_network_address, port=8000)