From 64651523c078b9bf26a6cdc76d3eca4558105af4 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sat, 24 Dec 2016 14:40:32 -0800 Subject: [PATCH] Make links to feeds backward compatible --- src/Podsync/Controllers/FeedController.cs | 7 ++++--- src/Podsync/Controllers/StatusController.cs | 2 ++ src/Podsync/Services/Links/ILinkService.cs | 2 ++ src/Podsync/Services/Links/LinkService.cs | 5 +++++ src/Podsync/docker-compose.yml | 2 ++ src/Podsync/wwwroot/js/site.js | 8 ++++---- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Podsync/Controllers/FeedController.cs b/src/Podsync/Controllers/FeedController.cs index c093c1a..198d781 100644 --- a/src/Podsync/Controllers/FeedController.cs +++ b/src/Podsync/Controllers/FeedController.cs @@ -37,7 +37,7 @@ namespace Podsync.Controllers [HttpPost] [Route("create")] [ValidateModelState] - public Task Create([FromBody] CreateFeedRequest request) + public async Task Create([FromBody] CreateFeedRequest request) { var linkInfo = _linkService.Parse(new Uri(request.Url)); @@ -56,11 +56,12 @@ namespace Podsync.Controllers feed.PageSize = DefaultPageSize; } - return _storageService.Save(feed); + var feedId = await _storageService.Save(feed); + return _linkService.Feed(feedId); } [HttpGet] - [Route("{feedId}")] + [Route("~/{feedId:length(4, 6)}")] [ValidateModelState] public async Task Feed([Required] string feedId) { diff --git a/src/Podsync/Controllers/StatusController.cs b/src/Podsync/Controllers/StatusController.cs index 5f85613..31c0d6b 100644 --- a/src/Podsync/Controllers/StatusController.cs +++ b/src/Podsync/Controllers/StatusController.cs @@ -19,6 +19,8 @@ namespace Podsync.Controllers _resolverService = resolverService; } + [HttpGet] + [Route("~/status")] public async Task Index() { var storageStatus = ErrorStatus; diff --git a/src/Podsync/Services/Links/ILinkService.cs b/src/Podsync/Services/Links/ILinkService.cs index 27e6e41..3cf0dbd 100644 --- a/src/Podsync/Services/Links/ILinkService.cs +++ b/src/Podsync/Services/Links/ILinkService.cs @@ -9,5 +9,7 @@ namespace Podsync.Services.Links Uri Make(LinkInfo info); Uri Download(string feedId, string videoId); + + Uri Feed(string feedId); } } \ No newline at end of file diff --git a/src/Podsync/Services/Links/LinkService.cs b/src/Podsync/Services/Links/LinkService.cs index 7c813a7..033b170 100644 --- a/src/Podsync/Services/Links/LinkService.cs +++ b/src/Podsync/Services/Links/LinkService.cs @@ -206,5 +206,10 @@ namespace Podsync.Services.Links { return new Uri(_baseUrl, $"download/{feedId}/{videoId}/"); } + + public Uri Feed(string feedId) + { + return new Uri(_baseUrl, feedId); + } } } \ No newline at end of file diff --git a/src/Podsync/docker-compose.yml b/src/Podsync/docker-compose.yml index 40c5a56..a4f70c4 100644 --- a/src/Podsync/docker-compose.yml +++ b/src/Podsync/docker-compose.yml @@ -10,6 +10,8 @@ services: - PORT=56247 environment: - Podsync:RedisConnectionString=redis + env_file: + - ~/podsync.env redis: image: redis command: redis-server --appendonly yes diff --git a/src/Podsync/wwwroot/js/site.js b/src/Podsync/wwwroot/js/site.js index 845e885..7c4f1e6 100644 --- a/src/Podsync/wwwroot/js/site.js +++ b/src/Podsync/wwwroot/js/site.js @@ -16,10 +16,10 @@ $(function () { 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); + success: function (feedLink) { + // HACK: remove quotes + feedLink = JSON.parse(feedLink); + done(feedLink); }, error: function (xhr, status, error) { if (xhr.status === 400) {