-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path+page.svelte
More file actions
186 lines (173 loc) · 6.41 KB
/
Copy path+page.svelte
File metadata and controls
186 lines (173 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<script lang="ts">
import {
type AttType,
EncryptionState,
type EncryptState,
} from '$lib/types/filesharing/attributes'
import SEO from '$lib/components/SEO.svelte'
import RecipientSelection from '$lib/components/filesharing/RecipientSelection.svelte'
import MessageInput from '$lib/components/filesharing/inputs/MessageInput.svelte'
import SendButton from '$lib/components/filesharing/SendButton.svelte'
import FileInput from '$lib/components/filesharing/inputs/FileInput.svelte'
import ErrorPanel from '$lib/components/filesharing/Error.svelte'
import Done from '$lib/components/filesharing/Done.svelte'
import CrashReport from '$lib/components/filesharing/CrashReport.svelte'
import { SITE_URL } from '$lib/env'
const ATTRIBUTES: Array<AttType> = [
'pbdf.sidn-pbdf.mobilenumber.mobilenumber',
'pbdf.gemeente.personalData.dateofbirth',
]
function createDefaultEncryptState(): EncryptState {
return {
recipients: [{ email: '', extra: [] }],
sender: '',
message: '',
files: [],
percentages: [],
done: [],
encryptionState: EncryptionState.FileSelection,
abort: new AbortController(),
selfAborted: false,
serverError: false,
encryptStartTime: 0,
}
}
let encryptState: EncryptState = $state(createDefaultEncryptState())
// Warn the user before they navigate away mid-upload. Cryptify does not
// support resume yet, so navigating away silently aborts the upload and
// discards all progress (see encryption4all/postguard-website#116,
// encryption4all/postguard-website#117). The built-in browser dialog is
// the only reliable cross-browser hook for this; modern browsers ignore
// the returned message and show their own wording.
$effect(() => {
if (encryptState.encryptionState !== EncryptionState.Encrypting) return
const handler = (event: BeforeUnloadEvent) => {
event.preventDefault()
event.returnValue = ''
}
window.addEventListener('beforeunload', handler)
return () => window.removeEventListener('beforeunload', handler)
})
const fileshareJsonLd = {
'@context': 'https://schema.org',
'@type': 'WebApplication',
name: 'PostGuard Secure File Sharing',
url: `${SITE_URL}/fileshare`,
description:
'Send end-to-end encrypted files to anyone using their email address. Encryption happens entirely in your browser.',
applicationCategory: 'SecurityApplication',
operatingSystem: 'Any',
offers: {
'@type': 'Offer',
price: '0',
priceCurrency: 'EUR',
},
isPartOf: {
'@id': `${SITE_URL}/#website`,
},
}
</script>
<SEO
title="Secure File Sharing"
description="Send end-to-end encrypted files to anyone using their email address. Your files are encrypted in your browser before they leave your device."
jsonLd={fileshareJsonLd}
/>
<div
class:container={encryptState.encryptionState ===
EncryptionState.FileSelection ||
encryptState.encryptionState === EncryptionState.Sign ||
encryptState.encryptionState === EncryptionState.Encrypting ||
encryptState.encryptionState === EncryptionState.Error}
class:done={encryptState.encryptionState === EncryptionState.Done}
>
<svelte:boundary>
<FileInput
bind:files={encryptState.files}
bind:percentages={encryptState.percentages}
bind:done={encryptState.done}
bind:stage={encryptState.encryptionState}
/>
{#if encryptState.encryptionState === EncryptionState.FileSelection || encryptState.encryptionState === EncryptionState.Sign || encryptState.encryptionState === EncryptionState.Encrypting}
<div class="inputs-container">
<RecipientSelection
bind:recipients={encryptState.recipients}
attributes={ATTRIBUTES}
readonly={encryptState.encryptionState ===
EncryptionState.Encrypting}
/>
<MessageInput
bind:message={encryptState.message}
readonly={encryptState.encryptionState ===
EncryptionState.Encrypting}
/>
<SendButton bind:encryptState />
</div>
{:else if encryptState.encryptionState === EncryptionState.Error}
<div class="inputs-container">
<ErrorPanel
bind:encryptionState={encryptState.encryptionState}
serverError={encryptState.serverError}
/>
</div>
{:else if encryptState.encryptionState === EncryptionState.Done}
<Done bind:encryptState {createDefaultEncryptState} />
{/if}
{#snippet failed(error, reset)}
<CrashReport
{error}
reset={() => {
encryptState = createDefaultEncryptState()
reset()
}}
/>
{/snippet}
</svelte:boundary>
</div>
<style lang="scss">
* {
list-style-type: none;
}
.container {
display: flex;
flex-direction: column;
gap: 1.5rem;
margin-inline: 1rem;
padding: 0.5rem 0;
}
.inputs-container {
display: flex;
flex-direction: column;
justify-content: flex-start;
font-size: var(--pg-font-size-lg);
min-width: 0;
gap: 1.25rem;
margin: 0;
}
.done {
display: flex;
flex-direction: column;
flex: 1;
min-width: 0;
overflow: hidden;
}
@media only screen and (min-width: 768px) {
.container {
display: grid;
grid-template-columns: 1fr min(800px, 43%);
gap: 2rem;
height: calc(
100vh - 52px - 0.5rem - 1rem
); /* navbar height + margin */
overflow-y: hidden;
}
.inputs-container {
max-height: 100%;
margin: 1rem 0 0 0;
padding-right: 1rem;
overflow-y: auto;
border-left: 2px solid var(--pg-strong-background);
display: flex;
justify-content: flex-start;
}
}
</style>