Skip to content

Commit 4e31d4a

Browse files
committed
fix: return of the delete and download option
1 parent edbc222 commit 4e31d4a

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

Decorators/DtoServiceDecorator.cs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
namespace Gelato.Decorators;
99

10-
public sealed class DtoServiceDecorator(IDtoService inner) : IDtoService
10+
public sealed class DtoServiceDecorator(IDtoService inner, Lazy<GelatoManager> manager)
11+
: IDtoService
1112
{
13+
private readonly Lazy<GelatoManager> _manager = manager;
14+
1215
public double? GetPrimaryImageAspectRatio(BaseItem item) =>
1316
inner.GetPrimaryImageAspectRatio(item);
1417

@@ -20,7 +23,7 @@ public BaseItemDto GetBaseItemDto(
2023
)
2124
{
2225
var dto = inner.GetBaseItemDto(item, options, user, owner);
23-
Patch(dto, false);
26+
Patch(dto, item, false, user);
2427
return dto;
2528
}
2629

@@ -42,7 +45,7 @@ public IReadOnlyList<BaseItemDto> GetBaseItemDtos(
4245
var list = inner.GetBaseItemDtos(items, options, user, owner);
4346
foreach (var itemDto in list)
4447
{
45-
Patch(itemDto, true);
48+
Patch(itemDto, item, true, user);
4649
}
4750
return list;
4851
}
@@ -55,22 +58,43 @@ public BaseItemDto GetItemByNameDto(
5558
)
5659
{
5760
var dto = inner.GetItemByNameDto(item, options, taggedItems, user);
58-
Patch(dto, false);
61+
Patch(dto, item, false, user);
5962
return dto;
6063
}
6164

62-
private void Patch(BaseItemDto dto, bool isList)
65+
static bool IsGelato(BaseItemDto dto)
66+
{
67+
return dto.LocationType == LocationType.Remote
68+
&& (
69+
dto.Type == BaseItemKind.Movie
70+
|| dto.Type == BaseItemKind.Episode
71+
|| dto.Type == BaseItemKind.Series
72+
|| dto.Type == BaseItemKind.Season
73+
);
74+
}
75+
76+
private void Patch(BaseItemDto dto, BaseItem? item, bool isList, User? user)
6377
{
64-
// mark if placeholder
65-
if (
66-
isList
67-
|| dto.MediaSources?.Length != 1
68-
|| dto.Path is null
69-
|| !dto.MediaSources[0].Path.StartsWith("gelato", StringComparison.OrdinalIgnoreCase)
70-
)
71-
return;
72-
dto.LocationType = LocationType.Virtual;
73-
dto.Path = null;
74-
dto.CanDownload = false;
78+
var manager = _manager.Value;
79+
if (item is not null && user is not null && IsGelato(dto) && manager.CanDelete(item, user))
80+
{
81+
dto.CanDelete = true;
82+
}
83+
if (IsGelato(dto))
84+
{
85+
dto.CanDownload = true;
86+
// mark if placeholder
87+
if (
88+
isList
89+
|| dto.MediaSources?.Length != 1
90+
|| dto.Path is null
91+
|| !dto.MediaSources[0]
92+
.Path.StartsWith("gelato", StringComparison.OrdinalIgnoreCase)
93+
)
94+
return;
95+
dto.LocationType = LocationType.Virtual;
96+
dto.Path = null;
97+
dto.CanDownload = false;
98+
}
7599
}
76100
}

0 commit comments

Comments
 (0)