diff --git a/client/src/App.js b/client/src/App.js index 96914d7..dc6c929 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -5,33 +5,34 @@ import './App.css'; function App() { const [response, setResponse] = useState({}); - const [show, setShow] = useState(false); + const [loading, setLoading] = useState(false); const [fetchError, setFetchError] = useState(''); - const [pdfBlob, setPdfBlob] = useState(null); + const [buffer, setBuffer] = useState(null); - const loadURL = (url, width, height) => { - setShow(true); - fetch( - `http://127.0.0.1:3001/website?url=${url}&width=${width}&height=${height}` - ) - .then(async (response) => { - if (response.ok) { - const json = await response.json(); - if (json.data.url) { - json.data.url = `http://localhost:3000/redirect/${json.data.url}`; - } - setResponse({ - url: json.data.url, - width, - height, - thumb: json.data.thumb, - origUrl: url - }); - setShow(false); + const PORT = 3100; + const PATH = `0.0.0.0:${PORT}`; + + + const loadURL = (url) => { + setLoading(true); + setFetchError(''); + fetch(`http://${PATH}/website-proxy-pdftron?url=${url}`) + .then(async (res) => { + var size = { width: 1800, height: 7000 }; + try { + size = JSON.parse(res.statusText); + } catch (e) { } + setResponse({ + url: `http://${PATH}`, + thumb: '', + ...size, + origUrl: `http://${PATH}`, + }); + setLoading(false); }) .catch((err) => { - setShow(false); + setLoading(false); setFetchError( 'Trouble fetching the URL, please make sure the server is running. `cd server && npm start`' ); @@ -39,30 +40,29 @@ function App() { }; const downloadPDF = () => { - setShow(true); if (response.url) { - const urlArray = response.url.split('/'); - fetch( - `http://127.0.0.1:3001/getpdf?url=${urlArray[4]}&width=${response.width}&height=${response.height}` - ).then((res) => { - return res.blob('application/pdf'); - }).then((blob) => { - console.log(blob); - setPdfBlob(blob); - }); + setLoading(true); + fetch(`http://${PATH}/pdftron-pdf`) + .then(async (res) => { + console.log(res); + setBuffer(res); + setLoading(false); + }).catch(err => console.log(err)); } - setShow(false); }; + // receive new loading state from Viewer as loadDocAndAnnots takes a while + const loadingFromViewer = (value) => setLoading(value); + return (
); } diff --git a/client/src/components/navigation/Nav.js b/client/src/components/navigation/Nav.js index 14b51ba..15767a9 100644 --- a/client/src/components/navigation/Nav.js +++ b/client/src/components/navigation/Nav.js @@ -14,54 +14,39 @@ import './Nav.css'; const Nav = ({ handleSubmit, fetchError, showSpinner, handleDownload }) => { const [url, setUrl] = useState(''); - const [width, setWidth] = useState(1000); - const [height, setHeight] = useState(2000); const [error, setError] = useState(false); + // test is URL (without https://) is valid https://regexr.com/3e6m0 + const isValidURL = (url) => { + // eslint-disable-next-line no-useless-escape + return /(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi.test(url); + } + return (
WebViewer HTML - In this demo, you can pass any URL. The URL passed in will be scraped - and saved server-side as a snapshot in time. Then you will be annotate - that copy here. + In this demo, you can pass any URL. The URL passed in will be proxied + and you will be able to annotate directly here. URL of the page { - setUrl(`http://${e.target.value}`); + setUrl(e.target.value); }} > - + - - Width of the page - { - setWidth(e.target.value); - }} - value={width} - /> - - - Height of the page - { - setHeight(e.target.value); - }} - placeholder="2000" - value={height} - /> + - -