initial pdf viewer implementation

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-09-07 19:36:52 +02:00
parent b2771486f1
commit 4167dcd129
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
5 changed files with 67 additions and 7 deletions

View File

@ -100,6 +100,7 @@ specifiers:
minio: ^7.0.19
mongodb: ^4.1.0
node-html-parser: ^4.1.3
pdfjs-dist: ~2.9.359
postcss: ^8.3.4
postcss-load-config: ^3.1.0
postcss-loader: ^6.1.0
@ -218,6 +219,7 @@ dependencies:
minio: 7.0.19
mongodb: 4.1.1
node-html-parser: 4.1.3
pdfjs-dist: 2.9.359
postcss: 8.3.6
postcss-load-config: 3.1.0
postcss-loader: 6.1.1_postcss@8.3.6+webpack@5.48.0
@ -1528,6 +1530,10 @@ packages:
resolution: {integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==}
dev: false
/@types/pdfjs-dist/2.7.4:
resolution: {integrity: sha512-X4CpJgsDr44/xq/SK8NukTV2uyRAMz9dXAVHMUtJrBPtpf4CYnbQevmD95G9fbNwsjJNItOlgsS+yECrBJLUHw==}
dev: false
/@types/prettier/1.19.1:
resolution: {integrity: sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==}
dev: false
@ -6460,6 +6466,12 @@ packages:
engines: {node: '>=8'}
dev: false
/pdfjs-dist/2.9.359:
resolution: {integrity: sha512-P2nYtkacdlZaNNwrBLw1ZyMm0oE2yY/5S/GDCAmMJ7U4+ciL/D0mrlEC/o4HZZc/LNE3w8lEVzBEyVgEQlPVKQ==}
peerDependencies:
worker-loader: ^3.0.7
dev: false
/performance-now/2.1.0:
resolution: {integrity: sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=}
dev: false
@ -9683,7 +9695,7 @@ packages:
dev: false
file:projects/prod.tgz_sass@1.37.5+typescript@4.3.5:
resolution: {integrity: sha512-G3BL3t90DKvIe4q8KAJxSZorpHF40el2hDey8ZQVnAXiax7Eb0kIVVWBuWgAGPnw7vgiE0nNJ3+XRMqz4Y64+g==, tarball: file:projects/prod.tgz}
resolution: {integrity: sha512-AWA9mq0Y9LG3jOjY+7OnWnUVjK1EVeIIYYOLYx6+MeZQ/AJR4rXtfupyICWRxDtZpqKc1dfwW9jd/KzI75KMqA==, tarball: file:projects/prod.tgz}
id: file:projects/prod.tgz
name: '@rush-temp/prod'
version: 0.0.0
@ -9746,11 +9758,13 @@ packages:
dev: false
file:projects/recruit-resources.tgz_c38cf1a7a413db8918b0b4754c21e4c5:
resolution: {integrity: sha512-ZHEMy8SOs9qPwWBjWKnS9eFirCDcIMDFiDvVSYanumEIEnJ6A/lkMZj1Lcj/6ZIssCTDl9cTSmPi2Yl2jejW3Q==, tarball: file:projects/recruit-resources.tgz}
resolution: {integrity: sha512-sshlnbz7EH+jFgvs6H/ydSr4wDXXcSNmuQtiyObN3k46huKfy5NSsoVyejK3T+Rh17cTd5r2FGRiog7DlLaQNg==, tarball: file:projects/recruit-resources.tgz}
id: file:projects/recruit-resources.tgz
name: '@rush-temp/recruit-resources'
version: 0.0.0
dependencies:
'@types/pdfjs-dist': 2.7.4
pdfjs-dist: 2.9.359
sass: 1.37.5
svelte: 3.42.1
svelte-loader: 3.1.2_svelte@3.42.1
@ -9766,6 +9780,7 @@ packages:
- stylus
- sugarss
- typescript
- worker-loader
dev: false
file:projects/recruit.tgz_6c259fadfeb3a4b20890aefe87070b8b:

View File

@ -22,7 +22,7 @@
export let icon: Asset | AnySvelteComponent | undefined
</script>
<span class="container">
<span class="container" on:click>
{#if icon}
<span class="icon">
{#if typeof (icon) === 'string'}

View File

@ -132,7 +132,7 @@
</div>
<div class="abs-lb-content flex-row-center">
{#if resume.id}
<Link label={resume.name} href={'#'} icon={FileIcon} />
<Link label={resume.name} href={'#'} icon={FileIcon} on:click={ () => { showPopup(PDFViewer, { file: resume.uuid }, 'right') } }/>
{:else}
<Button label={'Upload resume'} {loading} icon={FileUpload} size={'small'} transparent primary on:click={() => { inputFile.click() }}/>
<input bind:this={inputFile} type="file" name="file" id="file" style="display: none" on:change={fileSelected}/>

View File

@ -14,11 +14,27 @@
-->
<script lang="ts">
import { onMount } from 'svelte'
import { Button, CircleButton, IconClose } from '@anticrm/ui'
import { Avatar } from '@anticrm/presentation'
import ArrowLeft from './icons/ArrowLeft.svelte'
import ExpandUp from './icons/ExpandUp.svelte'
import ExpandDown from './icons/ExpandDown.svelte'
import { getMetadata } from '@anticrm/platform'
import login from '@anticrm/login'
export let file: string
function getSource(): string {
const uploadUrl = getMetadata(login.metadata.UploadUrl)
const token = getMetadata(login.metadata.LoginToken)
const url = `${uploadUrl}?file=${file}&token=${token}`
return url
}
</script>
<div class="pdfviewer-container">
@ -39,9 +55,7 @@
</div>
</div>
<div class="flex-grow content">
</div>
<iframe class="flex-grow content" src={getSource()}/>
<div class="flex-between footer">
<div class="flex-row-reverse">
@ -57,6 +71,7 @@
</div>
<style lang="scss">
.pdfviewer-container {
display: flex;
flex-direction: column;

View File

@ -80,6 +80,35 @@ export function start (transactorEndpoint: string, elasticUrl: string, minio: Cl
app.use(cors())
app.use(fileUpload())
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.get('/', async (req, res) => {
try {
const token = req.query.token as string
const payload = decode(token, 'secret', false) as Token
const uuid = req.query.file as string
minio.getObject(payload.workspace, uuid, function (err, dataStream) {
if (err !== null) {
return console.log(err)
}
res.status(200)
res.setHeader('Content-Type', 'application/pdf')
dataStream.on('data', function (chunk) {
res.write(chunk)
})
dataStream.on('end', function () {
res.end()
})
dataStream.on('error', function (err) {
console.log(err)
})
})
} catch (error) {
console.log(error)
res.status(500).send()
}
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
app.post('/', async (req, res) => {
const file = req.files?.file as UploadedFile
@ -100,6 +129,7 @@ export function start (transactorEndpoint: string, elasticUrl: string, minio: Cl
const payload = decode(token ?? '', 'secret', false) as Token
// const fileId = await awsUpload(file as UploadedFile)
const uuid = await minioUpload(minio, payload.workspace, file)
console.log('uploaded uuid', uuid)
const id = req.query.id as Ref<Doc>
const space = req.query.space as Ref<Space>