def setFile(filename=None): if request.method == 'POST': path = request.form.get('path') filename = request.form.get('filename') if not path.startswith('/'): path = '/' + path remote_file = os.path.join(path, filename) content = request.form.get('content').encode('utf-8') info = {} token = GetToken() app_url = GetAppUrl() headers = {'Authorization': 'bearer {}'.format(token)} url = app_url + 'v1.0/me/drive/items/root:{}:/content'.format( remote_file) try: r = requests.put(url, headers=headers, data=content, timeout=10) data = json.loads(r.content) AddResource(data) if data.get('@microsoft.graph.downloadUrl'): info['status'] = 0 info['msg'] = '添加成功' else: info['status'] = 0 info['msg'] = data.get('error').get('message') except: info['status'] = 0 info['msg'] = '超时' return jsonify(info) path = urllib.unquote(request.args.get('path')) _, fid, i = has_item(path, filename) if fid != False: return redirect(url_for('admin.edit', fileid=fid)) return render_template('admin/setpass.html', path=path, filename=filename)
def setFile(filename=None): if request.method == 'POST': path = request.form.get('path') if path.split(':')[-1] == '': path = path.split(':')[0] + ':/' user, n_path = path.split(':') filename = request.form.get('filename') if not n_path.startswith('/'): n_path = '/' + n_path share_path = od_users.get(user).get('share_path') if share_path != '/': remote_file = os.path.join(os.path.join(share_path, n_path[1:]), filename) else: remote_file = os.path.join(n_path, filename) print(u'remote path:{}'.format(remote_file)) content = request.form.get('content').encode('utf-8') info = {} token = GetToken(user=user) app_url = GetAppUrl() headers = {'Authorization': 'bearer {}'.format(token)} url = app_url + 'v1.0/me/drive/items/root:{}:/content'.format( remote_file) try: r = requests.put(url, headers=headers, data=content, timeout=10) data = json.loads(r.content) if data.get('id'): AddResource(data, user) info['status'] = 0 info['msg'] = '添加成功' key = 'has_item$#$#$#$#{}$#$#$#$#{}'.format(path, filename) print('set key:{}'.format(key)) rd.delete(key) else: info['status'] = 0 info['msg'] = data.get('error').get('message') except Exception as e: info['status'] = 0 info['msg'] = '超时' return jsonify(info) path = urllib.unquote(request.args.get('path')) if path.split(':')[-1] == '': path = path.split(':')[0] + ':/' user, n_path = path.split(':') _, fid, i = has_item(path, filename) if fid != False: return redirect(url_for('admin.edit', fileid=fid, user=user)) return render_template('admin/setpass.html', path=path, filename=filename, cur_user=user)