diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-03 09:24:23 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-11-03 09:24:23 -0500 |
| commit | 3c53e43bc9b91aafe93853417436bf761b2a076f (patch) | |
| tree | 52edf14468ab6c7136a8b9cab41c51154beea489 /src/slskd/Shares/API | |
| parent | 3b75717ab4562a516769bc731ac978db59297a08 (diff) | |
| download | slskd-3c53e43bc9b91aafe93853417436bf761b2a076f.tar.gz | |
add statistics to Share
Diffstat (limited to 'src/slskd/Shares/API')
| -rw-r--r-- | src/slskd/Shares/API/Controllers/SharesController.cs | 45 | ||||
| -rw-r--r-- | src/slskd/Shares/API/DTO/SummarizedShare.cs | 31 |
2 files changed, 8 insertions, 68 deletions
diff --git a/src/slskd/Shares/API/Controllers/SharesController.cs b/src/slskd/Shares/API/Controllers/SharesController.cs index 671e8992..e4f82848 100644 --- a/src/slskd/Shares/API/Controllers/SharesController.cs +++ b/src/slskd/Shares/API/Controllers/SharesController.cs @@ -53,29 +53,14 @@ namespace slskd.Shares.API /// <returns></returns> [HttpGet("")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(IEnumerable<SummarizedShare>), 200)] - public async Task<IActionResult> List() + [ProducesResponseType(typeof(Dictionary<string, IEnumerable<Share>>), 200)] + public IActionResult List() { - var shares = new List<SummarizedShare>(); + var response = Shares.Hosts.ToDictionary( + keySelector: host => host.Name, + elementSelector: host => host.Shares); - foreach (var share in Shares.Hosts.SelectMany(host => host.Shares)) - { - var (directories, files) = await Shares.SummarizeShareAsync(share); - - shares.Add(new SummarizedShare() - { - Id = share.Id, - Alias = share.Alias, - IsExcluded = share.IsExcluded, - LocalPath = share.LocalPath, - Raw = share.Raw, - RemotePath = share.RemotePath, - Directories = directories, - Files = files, - }); - } - - return Ok(shares); + return Ok(response); } /// <summary> @@ -87,7 +72,7 @@ namespace slskd.Shares.API /// <returns></returns> [HttpGet("{id}")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(SummarizedShare), 200)] + [ProducesResponseType(typeof(Share), 200)] [ProducesResponseType(404)] public async Task<IActionResult> Get(string id) { @@ -98,21 +83,7 @@ namespace slskd.Shares.API return NotFound(); } - var (directories, files) = await Shares.SummarizeShareAsync(share); - - var summary = new SummarizedShare() - { - Id = share.Id, - Alias = share.Alias, - IsExcluded = share.IsExcluded, - LocalPath = share.LocalPath, - Raw = share.Raw, - RemotePath = share.RemotePath, - Directories = directories, - Files = files, - }; - - return Ok(summary); + return Ok(share); } /// <summary> diff --git a/src/slskd/Shares/API/DTO/SummarizedShare.cs b/src/slskd/Shares/API/DTO/SummarizedShare.cs deleted file mode 100644 index 4e296d1c..00000000 --- a/src/slskd/Shares/API/DTO/SummarizedShare.cs +++ /dev/null @@ -1,31 +0,0 @@ -// <copyright file="SummarizedShare.cs" company="slskd Team"> -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// </copyright> - -namespace slskd.Shares -{ - public record SummarizedShare - { - public string Id { get; init; } - public string Alias { get; init; } - public bool IsExcluded { get; init; } - public string LocalPath { get; init; } - public string Raw { get; init; } - public string RemotePath { get; init; } - public int Directories { get; init; } - public int Files { get; init; } - } -}
\ No newline at end of file |
