diff --git a/partitioncloud/modules/partition.py b/partitioncloud/modules/partition.py index b0800c3..5a663dd 100644 --- a/partitioncloud/modules/partition.py +++ b/partitioncloud/modules/partition.py @@ -3,7 +3,7 @@ Partition module """ import os -from flask import Blueprint, abort, send_file, render_template +from flask import Blueprint, abort, send_file, render_template, request, redirect from .db import get_db from .auth import login_required, admin_required @@ -38,7 +38,7 @@ def partition_search(uuid): db = get_db() partition = db.execute( """ - SELECT * FROM search_results + SELECT uuid, url FROM search_results WHERE uuid = ? """, (uuid,) @@ -46,6 +46,8 @@ def partition_search(uuid): if partition is None: abort(404) + if request.args.get("redirect") == "true" and partition["url"] is not None: + return redirect(partition["url"]) return send_file(os.path.join("search-partitions", f"{uuid}.pdf")) diff --git a/partitioncloud/modules/search.py b/partitioncloud/modules/search.py index 692a8a5..470713d 100644 --- a/partitioncloud/modules/search.py +++ b/partitioncloud/modules/search.py @@ -59,10 +59,10 @@ def online_search(query, num_queries): uuid = str(uuid4()) db.execute( """ - INSERT INTO search_results (uuid) - VALUES (?) + INSERT INTO search_results (uuid, url) + VALUES (?, ?) """, - (uuid,) + (uuid, element,) ) db.commit() urllib.request.urlretrieve(element, f"partitioncloud/search-partitions/{uuid}.pdf") diff --git a/partitioncloud/schema.sql b/partitioncloud/schema.sql index ea28e2d..2cd2b2a 100644 --- a/partitioncloud/schema.sql +++ b/partitioncloud/schema.sql @@ -39,5 +39,6 @@ CREATE TABLE contient_user ( CREATE TABLE search_results ( uuid TEXT(36) PRIMARY KEY, + url TEXT, creation_time TEXT NULL DEFAULT (datetime('now', 'localtime')) ); \ No newline at end of file