示例#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))
示例#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')
示例#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')
示例#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")
示例#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")
示例#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
     )
示例#7
0
 def test_root_symlink_escape(self):
     with self.assertRaises(ValueError):
         util.get_complete_path(
             self.symlink_to_bad_name,
             self.root_dir
         )
示例#8
0
 def test_root_relative_escape(self):
     with self.assertRaises(ValueError):
         util.get_complete_path(
             "../" + self.bad_file_name,
             self.root_dir
         )