aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Social
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Social')
-rw-r--r--Emby.Server.Implementations/Social/SharingManager.cs101
-rw-r--r--Emby.Server.Implementations/Social/SharingRepository.cs135
2 files changed, 0 insertions, 236 deletions
diff --git a/Emby.Server.Implementations/Social/SharingManager.cs b/Emby.Server.Implementations/Social/SharingManager.cs
deleted file mode 100644
index 23ce7492a..000000000
--- a/Emby.Server.Implementations/Social/SharingManager.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-using MediaBrowser.Common.Extensions;
-using MediaBrowser.Controller;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Model.Social;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Emby.Server.Implementations.Social
-{
- public class SharingManager : ISharingManager
- {
- private readonly ISharingRepository _repository;
- private readonly IServerConfigurationManager _config;
- private readonly ILibraryManager _libraryManager;
- private readonly IServerApplicationHost _appHost;
-
- public SharingManager(ISharingRepository 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 = (await _appHost.GetPublicSystemInfo(CancellationToken.None).ConfigureAwait(false)).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,
- UserId = userId
- };
-
- AddShareInfo(info, externalUrl);
-
- _repository.CreateShare(info);
-
- return info;
- }
-
- private string GetTitle(BaseItem item)
- {
- return item.Name;
- }
-
- public SocialShareInfo GetShareInfo(string id)
- {
- var info = _repository.GetShareInfo(id);
-
- AddShareInfo(info, _appHost.GetPublicSystemInfo(CancellationToken.None).Result.WanAddress);
-
- return info;
- }
-
- private void AddShareInfo(SocialShareInfo info, string externalUrl)
- {
- info.ImageUrl = externalUrl + "/Social/Shares/Public/" + info.Id + "/Image";
- info.Url = externalUrl + "/emby/web/shared.html?id=" + info.Id;
-
- var item = _libraryManager.GetItemById(info.ItemId);
-
- if (item != null)
- {
- info.Overview = item.Overview;
- info.Name = GetTitle(item);
- }
- }
-
- public void DeleteShare(string id)
- {
- _repository.DeleteShare(id);
- }
- }
-}
diff --git a/Emby.Server.Implementations/Social/SharingRepository.cs b/Emby.Server.Implementations/Social/SharingRepository.cs
deleted file mode 100644
index 3c9e1024f..000000000
--- a/Emby.Server.Implementations/Social/SharingRepository.cs
+++ /dev/null
@@ -1,135 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using Emby.Server.Implementations.Data;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.Model.Social;
-using SQLitePCL.pretty;
-using MediaBrowser.Model.Extensions;
-using MediaBrowser.Model.IO;
-
-namespace Emby.Server.Implementations.Social
-{
- public class SharingRepository : BaseSqliteRepository, ISharingRepository
- {
- protected IFileSystem FileSystem { get; private set; }
-
- public SharingRepository(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem)
- : base(logger)
- {
- FileSystem = fileSystem;
- DbFilePath = Path.Combine(appPaths.DataPath, "shares.db");
- }
-
- public void Initialize()
- {
- try
- {
- InitializeInternal();
- }
- catch (Exception ex)
- {
- Logger.ErrorException("Error loading database file. Will reset and retry.", ex);
-
- FileSystem.DeleteFile(DbFilePath);
-
- InitializeInternal();
- }
- }
-
- /// <summary>
- /// Opens the connection to the database
- /// </summary>
- /// <returns>Task.</returns>
- private void InitializeInternal()
- {
- using (var connection = CreateConnection())
- {
- RunDefaultInitialization(connection);
-
- string[] queries = {
-
- "create table if not exists Shares (Id GUID NOT NULL, ItemId TEXT NOT NULL, UserId TEXT NOT NULL, ExpirationDate DateTime NOT NULL, PRIMARY KEY (Id))",
- "create index if not exists idx_Shares on Shares(Id)",
-
- "pragma shrink_memory"
- };
-
- connection.RunQueries(queries);
- }
- }
-
- public void CreateShare(SocialShareInfo info)
- {
- if (info == null)
- {
- throw new ArgumentNullException("info");
- }
- if (string.IsNullOrWhiteSpace(info.Id))
- {
- throw new ArgumentNullException("info.Id");
- }
-
- using (WriteLock.Write())
- {
- using (var connection = CreateConnection())
- {
- connection.RunInTransaction(db =>
- {
- var commandText = "replace into Shares (Id, ItemId, UserId, ExpirationDate) values (?, ?, ?, ?)";
-
- db.Execute(commandText,
- info.Id.ToGuidBlob(),
- info.ItemId,
- info.UserId,
- info.ExpirationDate.ToDateTimeParamValue());
- }, TransactionMode);
- }
- }
- }
-
- public SocialShareInfo GetShareInfo(string id)
- {
- if (string.IsNullOrWhiteSpace(id))
- {
- throw new ArgumentNullException("id");
- }
-
- using (WriteLock.Read())
- {
- using (var connection = CreateConnection(true))
- {
- var commandText = "select Id, ItemId, UserId, ExpirationDate from Shares where id = ?";
-
- var paramList = new List<object>();
- paramList.Add(id.ToGuidBlob());
-
- foreach (var row in connection.Query(commandText, paramList.ToArray(paramList.Count)))
- {
- return GetSocialShareInfo(row);
- }
- }
- }
-
- return null;
- }
-
- private SocialShareInfo GetSocialShareInfo(IReadOnlyList<IResultSetValue> reader)
- {
- var info = new SocialShareInfo();
-
- info.Id = reader[0].ReadGuidFromBlob().ToString("N");
- info.ItemId = reader[1].ToString();
- info.UserId = reader[2].ToString();
- info.ExpirationDate = reader[3].ReadDateTime();
-
- return info;
- }
-
- public void DeleteShare(string id)
- {
-
- }
- }
-}