Opening PDFs from URL (#27)

* Use proxy to workaround CORS issues
This commit is contained in:
MTR 2021-04-10 12:37:46 +05:30 committed by GitHub
parent 642509a454
commit 6327d74512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 486 additions and 254 deletions

717
ui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,9 +20,9 @@
"test": "web-test-runner \"src/**/*.test.ts\""
},
"dependencies": {
"@fortawesome/free-solid-svg-icons": "^5.15.2",
"pdfjs-dist": "^2.6.347",
"string-similarity": "^4.0.4",
"@fortawesome/free-solid-svg-icons": "5.15.2",
"pdfjs-dist": "2.6.347",
"string-similarity": "4.0.4",
"svelte-file-dropzone": "0.0.15",
"uuid": "^8.3.2"
},

View File

@ -2,7 +2,7 @@
import { blur, slide } from 'svelte/transition';
import Dropzone from 'svelte-file-dropzone';
import { Download, Check } from 'svelte-hero-icons';
import { processUpload, loadExample } from '../store';
import { processUpload, loadExample, loadUrl } from '../store';
import type Progress from '@core/Progress';
import ProgressRing from '../components/ProgressRing.svelte';
import Checkbox from '../components/Checkbox.svelte';
@ -13,6 +13,14 @@
let upload: Promise<any>;
let rejectionError: string;
let parseProgress: Progress;
function handleUrlLoad() {
dragover = true;
let answer = prompt('Url of the pdf');
specifiedFileName = answer;
rejectionError = undefined;
parseProgress = undefined;
upload = loadUrl(handleProgress, answer);
}
function handleExampleLoad() {
dragover = true;
@ -49,6 +57,9 @@
<div class="py-0.5 border-2 border-gray-50 hover:underline cursor-pointer" on:click={handleExampleLoad}>
Load Example
</div>
<div class="py-0.5 border-2 border-gray-50 hover:underline cursor-pointer" on:click={handleUrlLoad}>
Open Url
</div>
<Checkbox name="Debug" bind:enabled={$debugEnabled} />
</div>

View File

@ -17,6 +17,10 @@ export async function loadExample(progressListener: ProgressListenFunction): Pro
return parsePdf('ExamplePdf.pdf', progressListener);
}
export async function loadUrl(progressListener: ProgressListenFunction, url: String): Promise<any> {
return parsePdf('https://pdf-to-markdown-proxy.herokuapp.com/' + url, progressListener);
}
export async function processUpload(file: File, progressListener: ProgressListenFunction): Promise<any> {
return new Promise((resolve, reject) => {
const reader = new FileReader();