mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Query create feed API from JS
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
User-agent: *
|
||||
Disallow: /download/
|
||||
Disallow: /create/
|
||||
Disallow: /feed/
|
||||
Host: www.podsync.net
|
||||
Reference in New Issue
Block a user