From a243cef7074917d4a2feb2b23cb0be43fa9cfec8 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sun, 20 Aug 2017 13:01:58 -0700 Subject: [PATCH] Port Podsync web UI --- .gitignore | 5 +- assets/css/site.css | 12 ++-- assets/js/site.js | 47 ++++++-------- pkg/server/server.go | 13 ++-- templates/index.html | 148 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 180 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index e636705..19b829b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,7 @@ glide.lock Gopkg.lock -.idea/ \ No newline at end of file +.idea/ + +node_modules/ +package-lock.json \ No newline at end of file diff --git a/assets/css/site.css b/assets/css/site.css index 3881801..8f6e42e 100644 --- a/assets/css/site.css +++ b/assets/css/site.css @@ -13,7 +13,7 @@ a { } .background-image { - background-image: url('/img/pc_bg.png'); + background-image: url('/assets/img/pc_bg.png'); -ms-background-repeat: repeat-x; background-repeat: repeat-x; -ms-background-position: center bottom; @@ -32,7 +32,7 @@ a { /* Footer */ .footer { - background-image: url('/img/pc_footer.png'); + background-image: url('/assets/img/pc_footer.png'); -ms-background-repeat: space; background-repeat: space; -ms-background-position: center bottom; @@ -46,7 +46,7 @@ a { margin: 0; padding: 0; -webkit-user-select: text; - z-index: 1; + z-index: -1; } .twitter-link { @@ -180,7 +180,7 @@ a { .man { width: 210px; height: 333px; - background-image: url('/img/man.png'); + background-image: url('/assets/img/man.png'); -ms-background-repeat: no-repeat; background-repeat: no-repeat; -ms-background-position: center bottom; @@ -267,11 +267,11 @@ a { @media screen and (max-width: 640px) { .background-image { - background-image: url('/img/mobile_bg.png') + background-image: url('/assets/img/mobile_bg.png') } .footer { - background-image: url('/img/mobile_footer.png'); + background-image: url('/assets/img/mobile_footer.png'); height: 50px; } diff --git a/assets/js/site.js b/assets/js/site.js index bd8a3fe..f10df09 100644 --- a/assets/js/site.js +++ b/assets/js/site.js @@ -1,6 +1,4 @@ -// Write your Javascript code. - -$(function () { +$(function () { function err(msg) { alert(msg); } @@ -12,7 +10,7 @@ $(function () { $.ajax({ dataType: 'text', - url: '/feed/create', + url: '/api/create', method: 'POST', data: JSON.stringify(data), contentType: 'application/json; charset=utf-8', @@ -22,24 +20,18 @@ $(function () { done(feedLink); }, error: function (xhr, status, error) { - if (xhr.status === 400) { - // Bad request - var text = ''; + var text = ''; - try { - var json = JSON.parse(xhr.responseText); - $.each(json, function (key, value) { - text += value + '\r\n'; - }); - } catch (e) { - text = xhr.responseText; - } - - err(text); - } else { - // Generic error - err('Server sad \'' + error + '\': ' + xhr.responseText); + try { + var json = JSON.parse(xhr.responseText); + if (json['error']) { + text = json['error']; + } + } catch (e) { + text = xhr.responseText; } + + err(text); } }); } @@ -104,15 +96,14 @@ $(function () { $('#best-quality, #worst-quality').toggleClass('selected-option'); } - function getQuality() { + function getFormat() { var isAudio = $('#audio-format').hasClass('selected-option'); - var isWorst = $('#worst-quality').hasClass('selected-option'); + return isAudio ? 'audio' : 'video' + } - if (isAudio) { - return isWorst ? 'AudioLow' : 'AudioHigh'; - } else { - return isWorst ? 'VideoLow' : 'VideoHigh'; - } + function getQuality() { + var isWorst = $('#worst-quality').hasClass('selected-option'); + return isWorst ? 'low' : 'high'; } function pageSwitch(evt) { @@ -195,7 +186,7 @@ $(function () { $('#get-link').click(function(e) { var url = $('#url-input').val(); - createFeed({ url: url, quality: getQuality(), pageSize: getPageCount() }, displayLink); + createFeed({ url: url, format: getFormat(), quality: getQuality(), page_size: getPageCount() }, displayLink); e.preventDefault(); }); diff --git a/pkg/server/server.go b/pkg/server/server.go index 2bfe45a..b2be385 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -32,16 +32,19 @@ func MakeHandlers(feed feed) http.Handler { r.LoadHTMLGlob(path.Join(rootDir, "templates/*.html")) r.GET("/", func(c *gin.Context) { - c.HTML(http.StatusOK, "index.html", gin.H{"title": "Index page"}) + c.HTML(http.StatusOK, "index.html", gin.H{ + "identity": &struct{}{}, + "enableFeatures": true, + }) }) // REST API - r.GET("/ping", func(c *gin.Context) { + r.GET("/api/ping", func(c *gin.Context) { c.String(http.StatusOK, "ok") }) - r.POST("/create", func(c *gin.Context) { + r.POST("/api/create", func(c *gin.Context) { req := &api.CreateFeedRequest{} if err := c.BindJSON(req); err != nil { @@ -58,7 +61,7 @@ func MakeHandlers(feed feed) http.Handler { c.JSON(http.StatusOK, gin.H{"id": hashId}) }) - r.GET("/feed/:hashId", func(c *gin.Context) { + r.GET("/api/feed/:hashId", func(c *gin.Context) { hashId := c.Param("hashId") if hashId == "" || len(hashId) > 12 { c.JSON(badRequest(errors.New("invalid feed id"))) @@ -74,7 +77,7 @@ func MakeHandlers(feed feed) http.Handler { c.Data(http.StatusOK, "application/rss+xml", podcast.Bytes()) }) - r.GET("/metadata/:hashId", func(c *gin.Context) { + r.GET("/api/metadata/:hashId", func(c *gin.Context) { hashId := c.Param("hashId") if hashId == "" || len(hashId) > 12 { c.JSON(badRequest(errors.New("invalid feed id"))) diff --git a/templates/index.html b/templates/index.html index 109f958..6e1b992 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,5 +1,143 @@ - -

- {{ .title }} -

- \ No newline at end of file + + + + + + + Podsync - Turn YouTube channels into podcast feeds + + + + + + + + + + + + + +
+
+

Podsync

+ +

+ Simple and free service that lets you listen to any YouTube or + Vimeo channels, playlists or user videos in podcast format. +

+ + +
+ +
+
+
+ +
+ + + +
+
+ +
+

+ {{if .enableFeatures }} + + {{else}} + + {{end}} + + + + Selected format video audio, + quality best worst, + + + + episode count 50 100 150 + + +

+
+
+
+ +
+ +
+ + Become my patron on Patreon + +
+ + + + +
+ + + + + + + + + \ No newline at end of file