Mercurial > code > home > repos > video
annotate src/ingest/IngestDrop.ts @ 22:ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
author | drewp@bigasterisk.com |
---|---|
date | Mon, 17 Apr 2023 13:33:05 -0700 |
parents | 1b388ee5dd09 |
children | 1a9a8af1aa19 |
rev | line source |
---|---|
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
1 import { LitElement, html, css, TemplateResult } from "lit"; |
13 | 2 import { customElement, property } from "lit/decorators.js"; |
3 | |
4 @customElement("ingest-drop") | |
5 export class IngestDrop extends LitElement { | |
6 static styles = [ | |
7 css` | |
15 | 8 #drop { |
9 min-width: 10em; | |
10 min-height: 10em; | |
11 background: gray; | |
12 border: 5px gray dashed; | |
13 margin: 1% 10%; | |
14 } | |
15 #drop.dnd-hover { | |
16 background: yellow; | |
17 } | |
13 | 18 `, |
19 ]; | |
18 | 20 |
13 | 21 render() { |
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
22 return html` |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
23 <div id="drop" @dragover=${this.dragover} @dragleave=${this.leave} @drop=${this.drop}> |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
24 Drop video file or url here to upload to <em>TOP${this.folder}</em> |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
25 </div> |
15 | 26 } |
27 dragover(ev: DragEvent) { | |
28 this.shadowRoot?.querySelector("#drop")?.classList.add("dnd-hover"); | |
29 ev.preventDefault(); | |
30 if (ev.dataTransfer) { | |
31 ev.dataTransfer.dropEffect = "copy"; | |
32 } | |
33 } | |
34 leave() { | |
35 this.shadowRoot?.querySelector("#drop")?.classList.remove("dnd-hover"); | |
36 } | |
37 drop(ev: DragEvent) { | |
38 ev.preventDefault(); | |
39 this.leave(); | |
40 | |
41 if (!ev.dataTransfer) { | |
42 return; | |
43 } | |
44 | |
45 const url = ev.dataTransfer.getData("text/plain"); | |
46 if (url) { | |
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
47 this.queueUrlToFetch(url); |
17
071943adf000
dnd a file or a url which we'll queue and fetch
drewp@bigasterisk.com
parents:
15
diff
changeset
|
48 } else { |
071943adf000
dnd a file or a url which we'll queue and fetch
drewp@bigasterisk.com
parents:
15
diff
changeset
|
49 for (let i = 0; i < ev.dataTransfer.files.length; i++) { |
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
50 this.uploadVideoFile(ev.dataTransfer.files[i]); |
17
071943adf000
dnd a file or a url which we'll queue and fetch
drewp@bigasterisk.com
parents:
15
diff
changeset
|
51 } |
15 | 52 } |
13 | 53 } |
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
54 queueUrlToFetch(url: string) { |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
55 fetch("../api/ingest/videoUrl?folder=" + encodeURIComponent(this.folder), { |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
56 method: "POST", |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
57 body: url, |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
58 }); |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
59 } |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
60 uploadVideoFile(f: File) { |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
61 fetch("../api/ingest/videoUpload?name=" + encodeURIComponent(this.folder + "/" + f.name), { |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
62 method: "POST", |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
63 body: f.stream(), |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
64 duplex: "half", |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
65 } as any /* types don't include 'duplex' */ ); |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
18
diff
changeset
|
66 } |
13 | 67 } |