mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Simplify feed controller (move serialization to ToString method)
This commit is contained in:
@@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Podsync.Helpers;
|
||||
using Podsync.Services;
|
||||
@@ -12,7 +11,6 @@ using Podsync.Services.Links;
|
||||
using Podsync.Services.Resolver;
|
||||
using Podsync.Services.Rss;
|
||||
using Podsync.Services.Rss.Feed;
|
||||
using Podsync.Services.Rss.Feed.Internal;
|
||||
using Podsync.Services.Storage;
|
||||
using Shared;
|
||||
|
||||
@@ -28,8 +26,6 @@ namespace Podsync.Controllers
|
||||
["audio/mp4"] = "m4a"
|
||||
};
|
||||
|
||||
private readonly XmlSerializer _serializer = new XmlSerializer(typeof(Rss));
|
||||
|
||||
private readonly IRssBuilder _rssBuilder;
|
||||
private readonly ILinkService _linkService;
|
||||
private readonly IStorageService _storageService;
|
||||
@@ -111,15 +107,7 @@ namespace Podsync.Controllers
|
||||
item.DownloadLink = new Uri(selfHost, $"download/{feedId}/{item.Id}.{ext}");
|
||||
});
|
||||
|
||||
// Serialize feed to string
|
||||
string body;
|
||||
using (var writer = new Utf8StringWriter())
|
||||
{
|
||||
_serializer.Serialize(writer, rss);
|
||||
body = writer.ToString();
|
||||
}
|
||||
|
||||
return Content(body, "application/rss+xml; charset=UTF-8");
|
||||
return Content(rss.ToString(), "application/rss+xml; charset=UTF-8");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Schema;
|
||||
using System.Xml.Serialization;
|
||||
using Podsync.Services.Rss.Feed.Internal;
|
||||
using Shared;
|
||||
|
||||
namespace Podsync.Services.Rss.Feed
|
||||
@@ -43,5 +44,17 @@ namespace Podsync.Services.Rss.Feed
|
||||
var serializer = new XmlSerializer(typeof(Channel));
|
||||
Channels.ForEach(channel => serializer.Serialize(writer, channel));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var serializer = new XmlSerializer(typeof(Rss));
|
||||
|
||||
// Serialize feed to XML string
|
||||
using (var writer = new Utf8StringWriter())
|
||||
{
|
||||
serializer.Serialize(writer, this);
|
||||
return writer.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user