Exemple #1
0
def api_v1():
    method = request.args.get("method", None)
    results = ()
    success = False
    try:
        if method == "getSearch":
            query = request.args["q"]
            s = searchd.search(query, request.args, start=True, group=True, no_group=True)
            ids = list(s.get_results((1.4, 0.1), last_items=[], min_results=100, max_results=100, extra_browse=0))
            stats = s.get_stats()
            results = enumerate(filter(None, [secure_fill_data(f,text=query) for f in filesdb.get_files(ids,True)]))
            success = True
    except BaseException as e:
        logging.debug(e)

    return render_template("api/v1.xml",
        api_method=method,
        results=results,
        success = success
        )
Exemple #2
0
def api_v2():
    method = request.args.get("method", None)
    success = True
    result = None
    if method == "search":
        query = request.args["q"]
        s = searchd.search(query, request.args, start=True, group=True, no_group=True)
        ids = list(s.get_results((1.4, 0.1), last_items=[], min_results=100, max_results=100, extra_browse=0))
        stats = s.get_stats()
        result = [{
            "size": f["file"]["z"] if "z" in f["file"] else 0,
            "type": f["view"]["file_type"],
            "link": url_for("files.download", file_id=f["view"]["url"], file_name=f["view"]["qfn"]+".htm", _external=True),
            "metadata": {k: (_api_v2_md_parser[k](v) if k in _api_v2_md_parser else v)
                for k, v in f["view"]["md"].iteritems()},
            } for f in filter(None, [secure_fill_data(f,text=query) for f in filesdb.get_files(ids,True)])]
        success = True
    return jsonify(
        method = method,
        success = success,
        result = result
        )