diff --git a/.gitignore b/.gitignore index fb0f672..5746745 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ node_modules /.svelte /build /functions +.env diff --git a/Cargo.lock b/Cargo.lock index 27fe5bd..0045a8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -521,9 +521,9 @@ dependencies = [ "actix-web", "bs62", "byte-unit", + "dotenv", "lazy_static", "memcache", - "mime", "ring", "serde", "serde_json", @@ -557,6 +557,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "either" version = "1.6.1" diff --git a/Cargo.toml b/Cargo.toml index 69b413c..c525408 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,4 @@ ring = "0.16" bs62 = "0.1" memcache = "0.16" byte-unit = "4" -mime = "0.3" +dotenv = "0.15" diff --git a/client/src/app.css b/client/src/app.css index 15f25e4..eeaff16 100644 --- a/client/src/app.css +++ b/client/src/app.css @@ -97,3 +97,24 @@ fieldset { padding: 0; border: none; } + +.box { + width: 100%; + min-height: min(calc(100vh - 30rem), 30rem); + margin: 0; + border: 2px solid var(--ui-bg-1); + resize: vertical; + outline: none; + padding: 0.5rem; +} + +@media screen and (max-width: 30rem) { + .box { + min-height: calc(100vh - 25rem); + } +} + +.box:hover, +.box:focus { + border-color: var(--ui-clr-primary); +} diff --git a/client/src/lib/api.ts b/client/src/lib/api.ts index e884bcf..d585e9e 100644 --- a/client/src/lib/api.ts +++ b/client/src/lib/api.ts @@ -1,10 +1,18 @@ +export type NoteMeta = { type: 'text' | 'file' } + export type Note = { contents: string + meta: NoteMeta views?: number expiration?: number } export type NoteInfo = {} -export type NotePublic = Pick +export type NotePublic = Pick +export type NoteCreate = Omit & { meta: string } + +export type FileDTO = Pick & { + contents: string +} type CallOptions = { url: string @@ -32,26 +40,35 @@ async function call(options: CallOptions) { } export async function create(note: Note) { + const { meta, ...rest } = note + const body: NoteCreate = { + ...rest, + meta: JSON.stringify(meta), + } const data = await call({ url: 'notes', method: 'post', - body: note, + body, }) return data as { id: string } } -export async function get(id: string) { +export async function get(id: string): Promise { const data = await call({ url: `notes/${id}`, method: 'delete', }) - return data as NotePublic + const { contents, meta } = data + return { + contents, + meta: JSON.parse(meta) as NoteMeta, + } } -export async function info(id: string) { +export async function info(id: string): Promise { const data = await call({ url: `notes/${id}`, method: 'get', }) - return data as NoteInfo + return data } diff --git a/client/src/lib/files.ts b/client/src/lib/files.ts new file mode 100644 index 0000000..26cf3e2 --- /dev/null +++ b/client/src/lib/files.ts @@ -0,0 +1,13 @@ +export class Files { + static toString(f: File | Blob): Promise { + const reader = new window.FileReader() + reader.readAsDataURL(f) + return new Promise((resolve) => { + reader.onloadend = () => resolve(reader.result as string) + }) + } + + static fromString(s: string): Promise { + return fetch(s).then((r) => r.blob()) + } +} diff --git a/client/src/lib/ui/FileUpload.svelte b/client/src/lib/ui/FileUpload.svelte new file mode 100644 index 0000000..d6194c9 --- /dev/null +++ b/client/src/lib/ui/FileUpload.svelte @@ -0,0 +1,69 @@ + + + + + diff --git a/client/src/lib/ui/ShowNote.svelte b/client/src/lib/ui/ShowNote.svelte new file mode 100644 index 0000000..a166c9d --- /dev/null +++ b/client/src/lib/ui/ShowNote.svelte @@ -0,0 +1,69 @@ + + +

you will not get the chance to see the note again.

+{#if note.meta.type === 'text'} +
+ {note.contents} +
+ +{:else} + {#each files as file} +
+ downloadFile(file)}>↓ {file.name} + {file.type} - {prettyBytes(file.size)} +
+ {/each} + +{/if} + + diff --git a/client/src/lib/ui/Switch.svelte b/client/src/lib/ui/Switch.svelte index 2253aa9..e170884 100644 --- a/client/src/lib/ui/Switch.svelte +++ b/client/src/lib/ui/Switch.svelte @@ -4,7 +4,7 @@ export let color = true -
+