2015-06-30 23:59:45 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Social;
|
|
|
|
|
using MediaBrowser.Model.Social;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Social
|
|
|
|
|
{
|
|
|
|
|
public class SharingManager : ISharingManager
|
|
|
|
|
{
|
|
|
|
|
private readonly SharingRepository _repository;
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
|
|
|
|
|
|
|
|
|
public SharingManager(SharingRepository repository, IServerConfigurationManager config, ILibraryManager libraryManager, IServerApplicationHost appHost)
|
|
|
|
|
{
|
|
|
|
|
_repository = repository;
|
|
|
|
|
_config = config;
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_appHost = appHost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<SocialShareInfo> CreateShare(string itemId, string userId)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(itemId))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("itemId");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrWhiteSpace(userId))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("userId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var item = _libraryManager.GetItemById(itemId);
|
|
|
|
|
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ResourceNotFoundException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var externalUrl = _appHost.GetSystemInfo().WanAddress;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(externalUrl))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("No external server address is currently available.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var info = new SocialShareInfo
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid().ToString("N"),
|
|
|
|
|
ExpirationDate = DateTime.UtcNow.AddDays(_config.Configuration.SharingExpirationDays),
|
|
|
|
|
ItemId = itemId,
|
2015-07-02 05:08:05 +00:00
|
|
|
|
UserId = userId
|
2015-06-30 23:59:45 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-07-02 05:08:05 +00:00
|
|
|
|
AddShareInfo(info);
|
|
|
|
|
|
2015-06-30 23:59:45 +00:00
|
|
|
|
await _repository.CreateShare(info).ConfigureAwait(false);
|
|
|
|
|
|
2015-07-02 05:08:05 +00:00
|
|
|
|
return info;
|
2015-06-30 23:59:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetTitle(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SocialShareInfo GetShareInfo(string id)
|
|
|
|
|
{
|
|
|
|
|
var info = _repository.GetShareInfo(id);
|
|
|
|
|
|
2015-07-02 05:08:05 +00:00
|
|
|
|
AddShareInfo(info);
|
|
|
|
|
|
2015-06-30 23:59:45 +00:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 05:08:05 +00:00
|
|
|
|
private void AddShareInfo(SocialShareInfo info)
|
|
|
|
|
{
|
|
|
|
|
var externalUrl = _appHost.GetSystemInfo().WanAddress;
|
|
|
|
|
|
|
|
|
|
info.ImageUrl = externalUrl + "/Social/Shares/Public/" + info.Id + "/Image";
|
2016-04-08 18:00:35 +00:00
|
|
|
|
info.Url = externalUrl + "/emby/web/shared.html?id=" + info.Id;
|
2015-07-02 05:08:05 +00:00
|
|
|
|
|
|
|
|
|
var item = _libraryManager.GetItemById(info.ItemId);
|
|
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
|
|
|
|
info.Overview = item.Overview;
|
|
|
|
|
info.Name = GetTitle(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-30 23:59:45 +00:00
|
|
|
|
public Task DeleteShare(string id)
|
|
|
|
|
{
|
|
|
|
|
return _repository.DeleteShare(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|