Пример #1
0
def edit():
    if request.method == 'POST':
        fileid = request.form.get('fileid')
        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/{}/content'.format(fileid)
        try:
            r = requests.put(url, headers=headers, data=content, timeout=10)
            data = json.loads(r.content)
            if data.get('@microsoft.graph.downloadUrl'):
                info['status'] = 0
                info['msg'] = '修改成功'
                rd.delete('{}:content'.format(fileid))
            else:
                info['status'] = 0
                info['msg'] = data.get('error').get('message')
        except:
            info['status'] = 0
            info['msg'] = '修改超时'
        return jsonify(info)
    fileid = request.args.get('fileid')
    name = GetName(fileid)
    ext = name.split('.')[-1]
    language = CodeType(ext)
    if language is None:
        language = 'Text'
    content = _remote_content(fileid)
    return render_template('admin/edit.html',
                           content=content,
                           fileid=fileid,
                           name=name,
                           language=language)
Пример #2
0
def edit():
    if request.method == 'POST':
        fileid = request.form.get('fileid')
        user = request.form.get('user')
        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/{}/content'.format(fileid)
        try:
            r = requests.put(url, headers=headers, data=content, timeout=10)
            data = json.loads(r.content)
            if data.get('id'):
                info['status'] = 0
                info['msg'] = '修改成功'
                rd.delete('{}:content'.format(fileid))
                file = items.find_one({'id': fileid})
                name = file['name']
                path = file['path'].replace(name, '', 1)
                if len(path.split('/')) > 2 and path.split('/')[-1] == '':
                    path = path[:-1]
                # if path=='':
                #     path='/'
                # if not path.startswith('/'):
                #     path='/'+path
                # path='{}:{}'.format(user,path)
                key = 'has_item$#$#$#$#{}$#$#$#$#{}'.format(path, name)
                print('edit key:{}'.format(key))
                rd.delete(key)
            else:
                info['status'] = 0
                info['msg'] = data.get('error').get('message')
        except Exception as e:
            print e
            info['status'] = 0
            info['msg'] = '修改超时'
        return jsonify(info)
    fileid = request.args.get('fileid')
    user = request.args.get('user')
    name = GetName(fileid)
    ext = name.split('.')[-1]
    language = CodeType(ext)
    if language is None:
        language = 'Text'
    content = _remote_content(fileid, user)
    return render_template('admin/setFile/edit.html',
                           content=content,
                           fileid=fileid,
                           name=name,
                           language=language,
                           cur_user=user)