Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lm317379829 authored May 29, 2023
1 parent c557087 commit be22cf2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
15 changes: 9 additions & 6 deletions ali.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ def refresh_token(self, token, delFile=False):
params = {}
header = headers.copy()
try:
r = requests.post(url='https://auth.aliyundrive.com/v2/account/token',
json={'grant_type': 'refresh_token', 'refresh_token': token},
headers=header,
timeout=10)
if r.status_code != 200:
return {}
retry = 1
while retry <= 3:
retry += 1
r = requests.post(url='https://auth.aliyundrive.com/v2/account/token',
json={'grant_type': 'refresh_token', 'refresh_token': token},
headers=header,
timeout=10)
if r.status_code == 200:
break
jo = json.loads(r.text)
params['token'] = jo['refresh_token']
params['authorization'] = '{} {}'.format(jo['token_type'], jo['access_token'])
Expand Down
36 changes: 21 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aes import AES
from ali import Ali


class cryption():
def decrypt(self, iv, key, content):
iv_bit = iv.encode()
Expand All @@ -21,6 +22,7 @@ def decrypt(self, iv, key, content):
content = 'Erro'
return content


def encrypt(self, iv, key, content):
iv_bit = iv.encode()
key_bit = key.encode()
Expand All @@ -29,6 +31,7 @@ def encrypt(self, iv, key, content):
content_str = base64.b64encode(content_bit).decode()
return content_str


def refresh(self, iv, key, rtime, delFile=False):
while True:
if 'stime' in rtime:
Expand All @@ -50,22 +53,23 @@ def refresh(self, iv, key, rtime, delFile=False):
file.write(json.dumps(app.config['content']))
time.sleep(stime)

app = Flask(__name__)

app = Flask(__name__)
with open('content.txt', 'r') as file:
app.config['content'] = json.loads(file.read())
app.config['alicache'] = {}



@app.route('/')
def web():
return render_template('index.html')


@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'templates'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')


@app.route('/token')
def token():
# 获取相关参数
Expand All @@ -83,18 +87,18 @@ def token():
key = key.rjust(16, '0')
else:
key = key[:16]
refresh = request.args.get('refresh')
delFile = request.args.get('delFile')
display = request.args.get('display')
if delFile and delFile.lower() == 'true':
delFile = True
else:
delFile = False
if refresh and refresh.lower() == 'true':
refresh = True
else:
refresh = False
try:
refresh = request.args.get('refresh')
delFile = request.args.get('delFile')
if delFile and delFile.lower() == 'true':
delFile = True
else:
delFile = False
if refresh and refresh.lower() == 'true':
refresh = True
else:
refresh = False

# 检测定时刷新线程是否在运行
for t in threading.enumerate():
if t.name == "refresh":
Expand Down Expand Up @@ -139,7 +143,7 @@ def token():
if os.access('content.txt', os.W_OK):
with open('content.txt', "w") as file:
file.write(json.dumps(app.config['content']))
# 缓存app.config['alicache']为空
# 缓存app.config['alicache']为空或强制刷新
else:
# 缓存app.config['content']为空
if app.config['content'] == {}:
Expand All @@ -163,7 +167,6 @@ def token():
with open('content.txt', "w") as file:
file.write(json.dumps(app.config['content']))

display = request.args.get('display')
if not display:
display = 'token'
if display == 'all':
Expand All @@ -175,6 +178,7 @@ def token():
except:
return redirect('/submit')


@app.route('/process', methods=['POST'])
def process():
iv = request.form.get('iv')
Expand Down Expand Up @@ -220,9 +224,11 @@ def process():
pass
return render_template('result.html', message=message, show_token=show_token, get_token=get_token, get_all=get_all, force_refresh=force_refresh, del_file=del_file)


@app.route('/submit')
def submit():
return render_template('cryption.html')


if __name__ == '__main__':
app.run(host="0.0.0.0", threaded=True, port=8888)

1 comment on commit be22cf2

@vercel
Copy link

@vercel vercel bot commented on be22cf2 May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.