add bootstrap assets
This commit is contained in:
		
							
								
								
									
										7
									
								
								assets/bootstrap.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								assets/bootstrap.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										34
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								main.go
									
									
									
									
									
								
							@@ -2,6 +2,7 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"bufio"
 | 
						"bufio"
 | 
				
			||||||
 | 
						"embed"
 | 
				
			||||||
	_ "embed"
 | 
						_ "embed"
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
@@ -24,11 +25,16 @@ import (
 | 
				
			|||||||
//go:embed templates/index.html
 | 
					//go:embed templates/index.html
 | 
				
			||||||
var page string
 | 
					var page string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//go:embed assets
 | 
				
			||||||
 | 
					var assetsFS embed.FS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	ytdlCmd    = []string{"youtube-dl"}
 | 
						ytdlCmd    = []string{"youtube-dl"}
 | 
				
			||||||
	videosPath = "./vids"
 | 
						videosPath = "./vids"
 | 
				
			||||||
	videosUrl  = "/vids"
 | 
						videosUrl  = "/vids"
 | 
				
			||||||
	cachePath  = "./cache"
 | 
						cachePath  = "./cache"
 | 
				
			||||||
 | 
						assetsPath = "./assets"
 | 
				
			||||||
 | 
						saveAssets = false
 | 
				
			||||||
	dbPath     = "./db.json"
 | 
						dbPath     = "./db.json"
 | 
				
			||||||
	port       = 8080
 | 
						port       = 8080
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -42,6 +48,8 @@ func parse() {
 | 
				
			|||||||
	flag.StringVar(&videosUrl, "videosurl", videosUrl, "Prefix of the url, i.e. https://domain.com/<this var>/<video filename>")
 | 
						flag.StringVar(&videosUrl, "videosurl", videosUrl, "Prefix of the url, i.e. https://domain.com/<this var>/<video filename>")
 | 
				
			||||||
	flag.StringVar(&cachePath, "cachepath", cachePath, "Path where temporary download files are saved")
 | 
						flag.StringVar(&cachePath, "cachepath", cachePath, "Path where temporary download files are saved")
 | 
				
			||||||
	flag.StringVar(&dbPath, "dbpath", dbPath, "Path where downloaded info is saved")
 | 
						flag.StringVar(&dbPath, "dbpath", dbPath, "Path where downloaded info is saved")
 | 
				
			||||||
 | 
						flag.StringVar(&assetsPath, "assetspath", assetsPath, "Path where css files are saved and served")
 | 
				
			||||||
 | 
						flag.BoolVar(&saveAssets, "saveassets", saveAssets, "Should the assets be saved in dir, so can be served by web server")
 | 
				
			||||||
	flag.IntVar(&port, "port", port, "Port to listen on")
 | 
						flag.IntVar(&port, "port", port, "Port to listen on")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flag.Parse()
 | 
						flag.Parse()
 | 
				
			||||||
@@ -51,6 +59,9 @@ func parse() {
 | 
				
			|||||||
	os.MkdirAll(cachePath, 0755)
 | 
						os.MkdirAll(cachePath, 0755)
 | 
				
			||||||
	os.MkdirAll(videosPath, 0755)
 | 
						os.MkdirAll(videosPath, 0755)
 | 
				
			||||||
	os.MkdirAll(path.Dir(dbPath), 0755)
 | 
						os.MkdirAll(path.Dir(dbPath), 0755)
 | 
				
			||||||
 | 
						if saveAssets {
 | 
				
			||||||
 | 
							os.MkdirAll(assetsPath, 0755)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
@@ -70,7 +81,28 @@ func main() {
 | 
				
			|||||||
		log.Panic(err)
 | 
							log.Panic(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer d.Save()
 | 
						defer d.Save()
 | 
				
			||||||
	http.Handle("/assets/", http.FileServer(http.Dir("./")))
 | 
					
 | 
				
			||||||
 | 
						assets := []string{"assets/bootstrap.css"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if saveAssets {
 | 
				
			||||||
 | 
							for _, assetFile := range assets {
 | 
				
			||||||
 | 
								fname := strings.TrimPrefix(assetFile, "assets/")
 | 
				
			||||||
 | 
								contents, err := assetsFS.ReadFile(assetFile)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									log.Panic(err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								destination := path.Join(assetsPath, fname)
 | 
				
			||||||
 | 
								err = os.WriteFile(destination, contents, 0644)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									log.Printf("failed writing asset, assetFile: %s, destination: %s\n", assetFile, destination)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, assetFile := range assets {
 | 
				
			||||||
 | 
							http.Handle("/"+assetFile, http.FileServer(http.FS(assetsFS)))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	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) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@
 | 
				
			|||||||
        <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" >
 | 
					        <link href="assets/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', () => {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user