diff --git a/src/Podsync/Controllers/FeedController.cs b/src/Podsync/Controllers/FeedController.cs index 841ac7a..73ed962 100644 --- a/src/Podsync/Controllers/FeedController.cs +++ b/src/Podsync/Controllers/FeedController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; using System.Threading.Tasks; @@ -32,24 +33,6 @@ namespace Podsync.Controllers _storageService = storageService; } - [HttpGet] - [Route("{feedId}")] - [ValidateModelState] - public async Task Index([Required] string feedId) - { - var rss = await _rssBuilder.Query(feedId); - - // Serialize feed to string - string body; - using (var writer = new StringWriter()) - { - _serializer.Serialize(writer, rss); - body = writer.ToString(); - } - - return Content(body, "text/xml"); - } - [HttpPost] [Route("create")] [ValidateModelState] @@ -68,5 +51,32 @@ namespace Podsync.Controllers return _storageService.Save(feed); } + + [HttpGet] + [Route("{feedId}")] + [ValidateModelState] + public async Task Feed([Required] string feedId) + { + Rss rss; + + try + { + rss = await _rssBuilder.Query(feedId); + } + catch (KeyNotFoundException) + { + return NotFound(feedId); + } + + // Serialize feed to string + string body; + using (var writer = new StringWriter()) + { + _serializer.Serialize(writer, rss); + body = writer.ToString(); + } + + return Content(body, "text/xml"); + } } } \ No newline at end of file diff --git a/src/Podsync/Views/Home/Index.cshtml b/src/Podsync/Views/Home/Index.cshtml index 9716ed8..48d3e80 100644 --- a/src/Podsync/Views/Home/Index.cshtml +++ b/src/Podsync/Views/Home/Index.cshtml @@ -24,9 +24,9 @@
- + diff --git a/src/Podsync/wwwroot/js/site.js b/src/Podsync/wwwroot/js/site.js index 82ecce7..8fde0e8 100644 --- a/src/Podsync/wwwroot/js/site.js +++ b/src/Podsync/wwwroot/js/site.js @@ -1 +1,54 @@ // Write your Javascript code. + +$(function () { + + function err(msg) { + alert(msg); + } + + function createFeed(data, done) { + if (!data.url) { + err('Please fill the URL field first'); + return; + } + + $.ajax({ + dataType: 'text', + url: '/feed/create', + method: 'POST', + data: JSON.stringify(data), + contentType: 'application/json; charset=utf-8', + success: function (feedId) { + var proto = $(location).attr('protocol'); + var host = $(location).attr('host'); + done(proto + '//' + host + '/feed/' + feedId); + }, + error: function (xhr, status, error) { + if (xhr.status === 400) { + // Bad request + var json = JSON.parse(xhr.responseText); + + var text = ''; + $.each(json, function (key, value) { + text += value + '\r\n'; + }); + + err(text); + } else { + // Generic error + err('Server sad \'' + error + '\': ' + xhr.responseText); + } + } + }); + } + + function displayLink(link) { + alert(link); + } + + $('#get-link').click(function(e) { + var url = $('#url-input').val(); + createFeed({ url: url, quality: 'VideoHigh' }, displayLink); + e.preventDefault(); + }); +}); \ No newline at end of file diff --git a/src/Podsync/wwwroot/robots.txt b/src/Podsync/wwwroot/robots.txt index 48f8819..3af4436 100644 --- a/src/Podsync/wwwroot/robots.txt +++ b/src/Podsync/wwwroot/robots.txt @@ -1,4 +1,4 @@ User-agent: * Disallow: /download/ -Disallow: /create/ +Disallow: /feed/ Host: www.podsync.net \ No newline at end of file