Esempio n. 1
0
def file_listing():
    # Validate path and construct an absolute path
    try:
        path = get_complete_path(request.args.get("path", "/"), root)
    except Exception as e:
        return error(str(e))

    try:
        listing = json.dumps(directory_listing(path))
        return Response(listing, mimetype='application/json')
    except Exception as e:
        return error(str(e))
Esempio n. 2
0
def stream_file():
    if not request.args['path']:
        err_msg = "Not a streamable path: {}".format(requests.args['path'])
        return error(err_msg)

    # Validate path and construct an absolute path
    try:
        path = get_complete_path(request.args['path'], root)
    except Exception as e:
        return error(str(e))

    return Response(transcode(path), mimetype='audio/webm')
Esempio n. 3
0
def stream_file() -> Response:
    if not request.args['path']:
        log_msg = "Not a streamable path: {}".format(request.args['path'])
        app.logger.warning(log_msg)
        return error("Could not stream")

    # Validate path and construct an absolute path
    try:
        path = get_complete_path(request.args['path'], root)
    except Exception as e:
        log_msg = "Error in get_complete_path: {}".format(str(e))
        app.logger.warning(log_msg)
        return error("Could not stream")

    return Response(transcode(path), mimetype='audio/webm')
Esempio n. 4
0
def metadata() -> Response:
    # Validate path and construct an absolute path
    try:
        path = get_complete_path(request.args.get("path", "/"), root)
    except Exception as e:
        msg = "Error in get_complete_path: {}".format(str(e))
        app.logger.warning(msg)
        return error("Could not browse")

    try:
        result = json.dumps(get_metadata(path))
        return Response(result, mimetype='application/json')
    except Exception as e:
        msg = "Error getting metadata: {}".format(str(e))
        app.logger.error(msg)
        return error("Could not retrieve metadata")
Esempio n. 5
0
def file_listing() -> Response:
    # Validate path and construct an absolute path
    try:
        path = get_complete_path(request.args.get("path", "/"), root)
    except Exception as e:
        msg = "Error in get_complete_path: {}".format(str(e))
        app.logger.warning(msg)
        return error("Could not browse")

    try:
        listing = json.dumps(directory_listing(path, root))
        return Response(listing, mimetype='application/json')
    except Exception as e:
        msg = "Error in directory_listing: {}".format(str(e))
        app.logger.error(msg)
        msg = "path: {}, root: {}".format(path, root)
        app.logger.error(msg)
        return error("Could not browse")
Esempio n. 6
0
 def test_valid_complete_path(self):
     self.assertEqual(
         util.get_complete_path(self.good_file_name, self.root_dir),
         self.good_file_abs_path
     )
Esempio n. 7
0
 def test_root_symlink_escape(self):
     with self.assertRaises(ValueError):
         util.get_complete_path(
             self.symlink_to_bad_name,
             self.root_dir
         )
Esempio n. 8
0
 def test_root_relative_escape(self):
     with self.assertRaises(ValueError):
         util.get_complete_path(
             "../" + self.bad_file_name,
             self.root_dir
         )