fixed configuration saving issues

This commit is contained in:
LukePulverenti 2013-03-04 21:05:59 -05:00
parent e17b515697
commit cd69bd7c7d
10 changed files with 69 additions and 123 deletions

View File

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MediaBrowser.Api
{
class Api
{
}
}

View File

@ -1126,7 +1126,29 @@ var ApiClient = {
var url = ApiClient.getUrl("System/Configuration");
return $.post(url, JSON.stringify(configuration));
return $.ajax({
type: "POST",
url: url,
data: JSON.stringify(configuration),
dataType: "json",
contentType: "application/json"
});
},
/**
* Updates plugin security info
*/
updatePluginSecurityInfo: function (info) {
var url = ApiClient.getUrl("Plugins/SecurityInfo");
return $.ajax({
type: "POST",
url: url,
data: JSON.stringify(info),
dataType: "json",
contentType: "application/json"
});
},
/**
@ -1141,7 +1163,13 @@ var ApiClient = {
var url = ApiClient.getUrl("Users");
return $.post(url, JSON.stringify(user));
return $.ajax({
type: "POST",
url: url,
data: JSON.stringify(user),
dataType: "json",
contentType: "application/json"
});
},
/**
@ -1156,7 +1184,13 @@ var ApiClient = {
var url = ApiClient.getUrl("Users/" + user.Id);
return $.post(url, JSON.stringify(user));
return $.ajax({
type: "POST",
url: url,
data: JSON.stringify(user),
dataType: "json",
contentType: "application/json"
});
},
/**
@ -1176,7 +1210,13 @@ var ApiClient = {
var url = ApiClient.getUrl("ScheduledTasks/" + id + "/Triggers");
return $.post(url, JSON.stringify(triggers));
return $.ajax({
type: "POST",
url: url,
data: JSON.stringify(triggers),
dataType: "json",
contentType: "application/json"
});
},
/**
@ -1196,7 +1236,13 @@ var ApiClient = {
var url = ApiClient.getUrl("Plugins/" + id + "/Configuration");
return $.post(url, JSON.stringify(configuration));
return $.ajax({
type: "POST",
url: url,
data: JSON.stringify(configuration),
dataType: "json",
contentType: "application/json"
});
},
/**

View File

@ -106,13 +106,8 @@ namespace MediaBrowser.Api
/// Class UpdatePluginSecurityInfo
/// </summary>
[Route("/Plugins/SecurityInfo", "POST")]
public class UpdatePluginSecurityInfo : IReturnVoid, IRequiresRequestStream
public class UpdatePluginSecurityInfo : PluginSecurityInfo, IReturnVoid
{
/// <summary>
/// The raw Http Request Input Stream
/// </summary>
/// <value>The request stream.</value>
public Stream RequestStream { get; set; }
}
/// <summary>
@ -227,7 +222,7 @@ namespace MediaBrowser.Api
/// <param name="request">The request.</param>
public void Post(UpdatePluginSecurityInfo request)
{
var info = _jsonSerializer.DeserializeFromStream<PluginSecurityInfo>(request.RequestStream);
var info = request;
_securityManager.SupporterKey = info.SupporterKey;
_securityManager.LegacyKey = info.LegacyKey;

View File

@ -64,19 +64,13 @@ namespace MediaBrowser.Api.ScheduledTasks
/// Class UpdateScheduledTaskTriggers
/// </summary>
[Route("/ScheduledTasks/{Id}/Triggers", "POST")]
public class UpdateScheduledTaskTriggers : IRequiresRequestStream
public class UpdateScheduledTaskTriggers : List<TaskTriggerInfo>, IReturnVoid
{
/// <summary>
/// Gets or sets the task id.
/// </summary>
/// <value>The task id.</value>
public Guid Id { get; set; }
/// <summary>
/// The raw Http Request Input Stream
/// </summary>
/// <value>The request stream.</value>
public Stream RequestStream { get; set; }
}
/// <summary>
@ -202,7 +196,7 @@ namespace MediaBrowser.Api.ScheduledTasks
throw new ResourceNotFoundException("Task not found");
}
var triggerInfos = _jsonSerializer.DeserializeFromStream<TaskTriggerInfo[]>(request.RequestStream);
var triggerInfos = request;
task.Triggers = triggerInfos.Select(ScheduledTaskHelpers.GetTrigger);
}

View File

@ -49,13 +49,8 @@ namespace MediaBrowser.Api
/// Class UpdateConfiguration
/// </summary>
[Route("/System/Configuration", "POST")]
public class UpdateConfiguration : IRequiresRequestStream
public class UpdateConfiguration : ServerConfiguration, IReturnVoid
{
/// <summary>
/// The raw Http Request Input Stream
/// </summary>
/// <value>The request stream.</value>
public Stream RequestStream { get; set; }
}
/// <summary>
@ -160,9 +155,13 @@ namespace MediaBrowser.Api
/// <param name="request">The request.</param>
public void Post(UpdateConfiguration request)
{
var serverConfig = _jsonSerializer.DeserializeFromStream<ServerConfiguration>(request.RequestStream);
// Silly, but we need to serialize and deserialize or the XmlSerializer will write the xml with an element name of UpdateConfiguration
_configurationManager.ReplaceConfiguration(serverConfig);
var json = _jsonSerializer.SerializeToString(request);
var config = _jsonSerializer.DeserializeFromString<ServerConfiguration>(json);
_configurationManager.ReplaceConfiguration(config);
}
}
}

View File

@ -62,25 +62,13 @@ namespace MediaBrowser.Api.UserLibrary
/// </summary>
[Route("/Users/{UserId}/Items/{Id}/DisplayPreferences", "POST")]
[ServiceStack.ServiceHost.Api(("Updates a user's display preferences for an item"))]
public class UpdateDisplayPreferences : IReturnVoid, IRequiresRequestStream
public class UpdateDisplayPreferences : DisplayPreferences, IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public Guid UserId { get; set; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public string Id { get; set; }
/// <summary>
/// The raw Http Request Input Stream
/// </summary>
/// <value>The request stream.</value>
public Stream RequestStream { get; set; }
}
/// <summary>
@ -434,7 +422,7 @@ namespace MediaBrowser.Api.UserLibrary
var item = (Folder)DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id);
var displayPreferences = _jsonSerializer.DeserializeFromStream<DisplayPreferences>(request.RequestStream);
var displayPreferences = request;
var task = _libraryManager.SaveDisplayPreferencesForFolder(user, item, displayPreferences);

View File

@ -102,32 +102,16 @@ namespace MediaBrowser.Api
/// Class UpdateUser
/// </summary>
[Route("/Users/{Id}", "POST")]
public class UpdateUser : IRequiresRequestStream, IReturnVoid
public class UpdateUser : UserDto, IReturnVoid
{
/// <summary>
/// The raw Http Request Input Stream
/// </summary>
/// <value>The request stream.</value>
public Stream RequestStream { get; set; }
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public Guid Id { get; set; }
}
/// <summary>
/// Class CreateUser
/// </summary>
[Route("/Users", "POST")]
public class CreateUser : IRequiresRequestStream, IReturn<UserDto>
public class CreateUser : UserDto, IReturn<UserDto>
{
/// <summary>
/// The raw Http Request Input Stream
/// </summary>
/// <value>The request stream.</value>
public Stream RequestStream { get; set; }
}
/// <summary>
@ -292,7 +276,7 @@ namespace MediaBrowser.Api
var pathInfo = PathInfo.Parse(Request.PathInfo);
var id = new Guid(pathInfo.GetArgumentValue<string>(1));
var dtoUser = _jsonSerializer.DeserializeFromStream<UserDto>(request.RequestStream);
var dtoUser = request;
var user = _userManager.GetUserById(id);
@ -310,7 +294,7 @@ namespace MediaBrowser.Api
/// <returns>System.Object.</returns>
public object Post(CreateUser request)
{
var dtoUser = _jsonSerializer.DeserializeFromStream<UserDto>(request.RequestStream);
var dtoUser = request;
var newUser = _userManager.CreateUser(dtoUser.Name).Result;

View File

@ -22,22 +22,6 @@ namespace MediaBrowser.Common.Implementations.Serialization
netSerializer.Serialize(writer, obj);
}
/// <summary>
/// Deserializes from stream.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="stream">The stream.</param>
/// <returns>``0.</returns>
public T DeserializeFromStream<T>(Stream stream)
{
using (var reader = new XmlTextReader(stream))
{
var netSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
return (T)netSerializer.Deserialize(reader);
}
}
/// <summary>
/// Deserializes from stream.
/// </summary>
@ -67,20 +51,6 @@ namespace MediaBrowser.Common.Implementations.Serialization
}
}
/// <summary>
/// Deserializes from file.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="file">The file.</param>
/// <returns>``0.</returns>
public T DeserializeFromFile<T>(string file)
{
using (var stream = File.OpenRead(file))
{
return DeserializeFromStream<T>(stream);
}
}
/// <summary>
/// Serializes to file.
/// </summary>

View File

@ -5,14 +5,6 @@ namespace MediaBrowser.Model.Serialization
{
public interface IXmlSerializer
{
/// <summary>
/// Deserializes from stream.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="stream">The stream.</param>
/// <returns>``0.</returns>
T DeserializeFromStream<T>(Stream stream);
/// <summary>
/// Deserializes from stream.
/// </summary>
@ -28,14 +20,6 @@ namespace MediaBrowser.Model.Serialization
/// <param name="stream">The stream.</param>
void SerializeToStream(object obj, Stream stream);
/// <summary>
/// Deserializes from file.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="file">The file.</param>
/// <returns>``0.</returns>
T DeserializeFromFile<T>(string file);
/// <summary>
/// Serializes to file.
/// </summary>

View File

@ -37,9 +37,7 @@
LegacyKey: legacyKey
};
var url = ApiClient.getUrl("Plugins/SecurityInfo");
console.log(url);
$.post(url, JSON.stringify(info)).done(function () {
ApiClient.updateSecurityInfo(info).done(function () {
Dashboard.resetPluginSecurityInfo();
Dashboard.hideLoadingMsg();
SupporterPage.load();