Beispiel #1
0
def list(name):
    path = request.args.get('path')
    if path == None:
        return jsonify([])
        #return response.replyFailed('Path is missing')

    input = {}
    input['name'] = name
    input['path'] = path

    try:
        fileManager = LXCFileManager(input)
        try:
            results = []
            #Folder
            items = json.loads(fileManager.download().decode('utf-8'))['metadata']
            for item in items:
                input['path'] = path + '/' + item
                results.append({
                    'title': item,
                    'key': item,
                    'folder': isFolder(LXCFileManager(input)),
                    'lazy': isFolder(LXCFileManager(input)),
                })

            return jsonify(results)
            return response.reply(results)
        except:
            #File
            return jsonify([])
            return response.replyFailed('Please enter a valid directory path')
            #result = fileManager.download()

    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #2
0
def download(name):
    input = request.get_json(silent=True)
    input['name'] = name

    try:
        fileManager = LXCFileManager(input)
        return response.reply(fileManager.download())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #3
0
def edit_file(name):
    input = request.get_json(silent=True)

    input['name'] = name

    try:
        fileManager = LXCFileManager(input)
        fileManager.delete()
        return response.reply(fileManager.push())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #4
0
def upload_file(name):
    input = request.get_json(silent=True)
    #validation = doValidate(input)
    # if validation:
    #     return response.replyFailed(message=validation.message)

    input['name'] = name

    try:
        fileManager = LXCFileManager(input)
        return response.reply(fileManager.push())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #5
0
def download(name):
    input = request.get_json(silent=True)
    input['name'] = name

    try:
        fileManager = LXCFileManager(input)

        try:
            # Folder
            result = json.loads(fileManager.download().decode('utf-8'))['metadata']
        except:
            # File
            result = fileManager.download()

        return response.reply(result)
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #6
0
def upload_file(name):
    input = None
    try:
        file = request.files.get('file')
        input = {
            'name':name,
            'path':request.form.get('path')+file.filename,
            'file':file
        }
    except:
        return  response.replyFailed(message='Missing one the required fields: [path,file]')

    try:
        fileManager = LXCFileManager(input)
        return response.reply(fileManager.push())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #7
0
def download_file(name):
    path = request.args.get('path')
    token = request.args.get('token')
    print (token)
    if not checkAuthentication(token):
        return response.replyFailed('Not authorized')

    if path == None:
        return jsonify([])

    input = {}
    input['name'] = name
    input['path'] = path

    try:
        try:
            #Folder
            fileManager = LXCFileManager(input)
            items = json.loads(fileManager.download().decode('utf-8'))['metadata']
            return response.replyFailed('Please select a file for download')
        except:
            #File
            fileManager = LXCFileManager(input)
            file = io.BytesIO(fileManager.download())
            return send_file(file, attachment_filename=path.rsplit("/").pop(), mimetype="application/octet-stream", as_attachment=True)

    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #8
0
def content(name):
    path = request.args.get('path')
    if path == None:
        return jsonify([])
        #return response.replyFailed('Path is missing')

    input = {}
    input['name'] = name
    input['path'] = path

    try:

        try:
            #Folder
            fileManager = LXCFileManager(input)
            items = json.loads(fileManager.download().decode('utf-8'))['metadata']
            return response.replyFailed('Please enter a valid file path')
        except:
            #File
            result = fileManager.download().decode('utf-8')
            return response.reply(result)

    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #9
0
def list():
    try:
        fileManager = LXCFileManager()
        return response.reply(fileManager.list())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())