temp bs
This commit is contained in:
parent
66079e5e03
commit
1567035954
5
db/db.go
5
db/db.go
@ -31,6 +31,7 @@ type Item struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Jdb struct {
|
type Jdb struct {
|
||||||
|
Foo string `json:"-"`
|
||||||
Items []Item `json:"items"`
|
Items []Item `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ func (d *Db) Transact(id int, persist bool, f func(*Item)) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Db) save() error {
|
func (d *Db) save() error {
|
||||||
data, err := json.Marshal(Jdb{d.items})
|
data, err := json.Marshal(Jdb{"", d.items})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -82,7 +83,7 @@ func (d *Db) save() error {
|
|||||||
func (d *Db) Run(f func(*Jdb)) {
|
func (d *Db) Run(f func(*Jdb)) {
|
||||||
d.mutex.Lock()
|
d.mutex.Lock()
|
||||||
defer d.mutex.Unlock()
|
defer d.mutex.Unlock()
|
||||||
f(&Jdb{d.items})
|
f(&Jdb{"", d.items})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Db) Save() error {
|
func (d *Db) Save() error {
|
||||||
|
3
main.go
3
main.go
@ -70,9 +70,11 @@ func main() {
|
|||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
defer d.Save()
|
defer d.Save()
|
||||||
|
http.Handle("/assets/", http.FileServer(http.Dir("./")))
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet {
|
||||||
d.Run(func(d *db.Jdb) {
|
d.Run(func(d *db.Jdb) {
|
||||||
|
d.Foo = "Hello"
|
||||||
if err := tmpl.Execute(w, d); err != nil {
|
if err := tmpl.Execute(w, d); err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
@ -106,7 +108,6 @@ func main() {
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("path is", p, "id is", id)
|
|
||||||
var sc <-chan string
|
var sc <-chan string
|
||||||
d.Transact(id, false, func(i *db.Item) {
|
d.Transact(id, false, func(i *db.Item) {
|
||||||
pt := i.Pt
|
pt := i.Pt
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Youtube Downloader UI</title>
|
<title>Youtube Downloader UI</title>
|
||||||
<!-- Diable favicon requests: https://stackoverflow.com/a/13416784 -->
|
<!-- Diable favicon requests: https://stackoverflow.com/a/13416784 -->
|
||||||
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|
||||||
|
<link href="assets/bootstrap/css/bootstrap.css" rel="stylesheet" >
|
||||||
<script>
|
<script>
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
progressElems = document.querySelectorAll(".ytprogress")
|
progressElems = document.querySelectorAll("[data-ytstatus=progress")
|
||||||
progressElems.forEach(function(item) {
|
progressElems.forEach(function(item) {
|
||||||
// https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
|
// https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
|
||||||
item.innerText = item.dataset.ytid
|
item.innerText = item.dataset.ytid
|
||||||
@ -21,9 +24,12 @@
|
|||||||
socket.onmessage = function(event) {
|
socket.onmessage = function(event) {
|
||||||
item.innerHTML = event.data
|
item.innerHTML = event.data
|
||||||
}
|
}
|
||||||
|
socket.onclose = function(event) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pendingTitles = document.querySelectorAll(".yttitle")
|
pendingTitles = document.querySelectorAll("[data-yttitle]")
|
||||||
pendingTitles.forEach(function(item) {
|
pendingTitles.forEach(function(item) {
|
||||||
ytid = item.dataset.ytid
|
ytid = item.dataset.ytid
|
||||||
fetch("/title/" + ytid).then(function(response) {
|
fetch("/title/" + ytid).then(function(response) {
|
||||||
@ -39,12 +45,42 @@
|
|||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h1 class="text-center"> {{ .Foo }} </h1>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row my-4 text-center">
|
||||||
<form method="POST" action="/">
|
<form method="POST" action="/">
|
||||||
<input type="text" name="youtube_url">
|
<input class="col-md-8 h-100" placeholder="Enter video link" type="text" name="youtube_url">
|
||||||
<input type="submit" value="Ask">
|
<input class="btn btn-outline-primary mx-2" type="submit" value="Download">
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="row row-cols-1 row-cols-md-3 row-cols-lg-4 m-4 g-3">
|
||||||
|
{{ range .Items }}
|
||||||
|
<div class="col my-2">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">
|
||||||
|
{{ if eq .Title "Loading" }}
|
||||||
|
<span data-yttitle="" data-ytid="{{.Id}}">Loading...</span>
|
||||||
|
{{ else }}
|
||||||
|
{{ .Title }}
|
||||||
|
{{ end }}
|
||||||
|
</h5>
|
||||||
|
<h6 class="card-subtitle mb-2 text-muted">On {{ .Date }}</h6>
|
||||||
|
<a href="{{ .URL }}" class="card-link d-block mb-2">Youtube Link</a>
|
||||||
|
{{ if eq .Status "Done" }}
|
||||||
|
<a class="btn btn-primary w-100" target="_blank" href="{{ vids_prefix }}/{{ .FileName }}">Watch</a>
|
||||||
|
{{ else if eq .Status "InProgress" }}
|
||||||
|
<span class="border border-info w-100 text-center d-block" data-ytstatus="progress" data-ytid="{{.Id}}">In Progress</span>
|
||||||
|
{{ else }}
|
||||||
|
<span class="border border-danger w-100 text-center d-block"> {{ .Status }} </span>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
<table>
|
<table>
|
||||||
<caption>Vidoes</caption>
|
<caption>All Vidoes</caption>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
@ -60,7 +96,7 @@
|
|||||||
<td>{{ .URL }}</td>
|
<td>{{ .URL }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ if eq .Title "Loading" }}
|
{{ if eq .Title "Loading" }}
|
||||||
<span class="yttitle" data-ytid="{{.Id}}">Loading...</span>
|
<span data-yttitle="" data-ytid="{{.Id}}">Loading...</span>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ .Title }}
|
{{ .Title }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@ -69,7 +105,7 @@
|
|||||||
{{ if eq .Status "Done" }}
|
{{ if eq .Status "Done" }}
|
||||||
<a target="_blank" href="{{ vids_prefix }}/{{ .FileName }}">Watch</a>
|
<a target="_blank" href="{{ vids_prefix }}/{{ .FileName }}">Watch</a>
|
||||||
{{ else if eq .Status "InProgress" }}
|
{{ else if eq .Status "InProgress" }}
|
||||||
<span class="ytprogress" data-ytid="{{.Id}}">In Progress</span>
|
<span data-ytstatus="progress" data-ytid="{{.Id}}">In Progress</span>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ .Status }}
|
{{ .Status }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@ -78,5 +114,6 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user