Query create feed API from JS

This commit is contained in:
Maksym Pavlenko
2016-12-16 15:35:24 -08:00
parent c90a9bc2ad
commit ee7f16c764
4 changed files with 84 additions and 21 deletions
+28 -18
View File
@@ -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<IActionResult> 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<IActionResult> 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");
}
}
}
+2 -2
View File
@@ -24,9 +24,9 @@
<div class="main">
<div class="main-border">
<div class="input-border">
<input type="url" placeholder="paste your link here" spellcheck="false" autofocus />
<input id="url-input" type="url" placeholder="paste your link here" spellcheck="false" autofocus />
<div class="arrow-button">
<a href="#">
<a href="#" id="get-link">
<i class="fa fa-arrow-right" aria-hidden="true"></i>
</a>
</div>
+53
View File
@@ -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();
});
});
+1 -1
View File
@@ -1,4 +1,4 @@
User-agent: *
Disallow: /download/
Disallow: /create/
Disallow: /feed/
Host: www.podsync.net