diff --git a/openai-proxy/py_proxy/proxy.py b/openai-proxy/py_proxy/proxy.py index 0b4b045..e57b652 100755 --- a/openai-proxy/py_proxy/proxy.py +++ b/openai-proxy/py_proxy/proxy.py @@ -140,6 +140,15 @@ def proxy(): download_name = download_name ) +@app.route('/viewHtml/', methods=['GET', 'OPTIONS']) +def proxy_html(arg): + if request.method == 'OPTIONS': + return optionsResp('GET') + path = "/" + arg + if "/../" in path: # Prevent filesystem snooping + return "invalid path" + return send_file(path, mimetype='text/html') + def make_openai_call(messages, model_id="gpt-4"): response = openai.ChatCompletion.create( model=model_id, diff --git a/ui/src/ConversationList.tsx b/ui/src/ConversationList.tsx index ecb85aa..b7920b2 100644 --- a/ui/src/ConversationList.tsx +++ b/ui/src/ConversationList.tsx @@ -1,7 +1,7 @@ import React, { Dispatch, SetStateAction, useState, useEffect, useRef } from 'react'; import { ActionIcon, createStyles, Loader, Navbar, Text, useMantineTheme, rem, Center, Container, Group, Anchor, TextInput } from '@mantine/core'; import { Settings } from './Types' -import { createConversation, deleteConversation, getConversations, is2dot12plus } from './OpenSearch'; +import { createConversation, deleteConversation, getConversations } from './OpenSearch'; import { IconChevronRight, IconMessagePlus, IconTrash } from '@tabler/icons-react'; import { useHover } from '@mantine/hooks'; const useStyles = createStyles((theme) => ({ diff --git a/ui/src/Doclist.tsx b/ui/src/Doclist.tsx index cce07d6..0619cde 100644 --- a/ui/src/Doclist.tsx +++ b/ui/src/Doclist.tsx @@ -14,6 +14,10 @@ const DocumentItem = ({ document }: { document: SearchResultDocument }) => { console.log("You clicked: ", document) localStorage.setItem('pdfDocumentMetadata', dataString); window.open('/viewPdf'); + } else if (document.hasAbsoluteUrl()) { + window.open(document.url); + } else if (document.url.startsWith("/")) { + window.open("/viewHtml" + document.url); } else { window.open(document.url); } diff --git a/ui/src/Types.tsx b/ui/src/Types.tsx index 0f1bf0d..a9f3305 100644 --- a/ui/src/Types.tsx +++ b/ui/src/Types.tsx @@ -21,6 +21,10 @@ export class SearchResultDocument { } return false; } + + hasAbsoluteUrl() { + return this.url.search(/^[a-z]+:\/\//i) >= 0; + } } export class UserChat { id: string = "";