Skip to content

Commit

Permalink
Fix error if puid doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
MancunianSam committed Dec 13, 2024
1 parent dc7826f commit 5b904e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package
.idea
.venv
site/
site/
indexes
10 changes: 9 additions & 1 deletion results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
)


def puid_exists(puid):
conn = sqlite3.connect("indexes")
cursor = conn.cursor()
cursor.execute("SELECT path from indexes where path = ?", (puid,))
rows = cursor.fetchall()
return len(rows) > 0


def search(search_string):
conn = sqlite3.connect('indexes')
cur = conn.cursor()
Expand All @@ -20,7 +28,7 @@ def search(search_string):
def lambda_handler(event, _):
query_params = event.get("queryStringParameters", {})
search_term = query_params.get("q") if query_params else None
if re.search(r'^(x-)?fmt\/\d{1,5}$', search_term) is not None:
if re.search(r'^(x-)?fmt\/\d{1,5}$', search_term) is not None and puid_exists(search_term):
return {
"statusCode": 302,
"headers": {'Location': f'{search_term}.html'}
Expand Down
2 changes: 2 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ <h3 class="tna-heading-m">
<a href="/search.html">Search PRONOM</a>
<br>
<a href="https://github.com/nationalarchives/pronom-signatures/">Contribute to PRONOM</a>
<br>
<a href="/signature_list.html">View signature files</a>
</h3>

0 comments on commit 5b904e7

Please sign in to comment.