Skip to content

Commit e35b939

Browse files
committed
abstract away VersionCacheEntry creation into the Release model class
1 parent 8ce5a60 commit e35b939

2 files changed

Lines changed: 40 additions & 41 deletions

File tree

src/Server/Services/Forgejo/ForgejoVersionCache.cs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -210,47 +210,9 @@ public async Task RefreshAsync()
210210
}
211211
}
212212

213-
var tempCacheEntries = releases.Select(release =>
214-
new VersionCacheEntry
215-
{
216-
Tag = release.TagName,
217-
ReleaseUrl = ReleaseUrlFormat.Format(release.TagName),
218-
Downloads = new DownloadLinks
219-
{
220-
Windows = new DownloadLinks.SupportedPlatform
221-
{
222-
X64 = release.Assets?
223-
.FirstOrDefault(x => x.Name.ContainsIgnoreCase("win_x64"))
224-
?.DownloadUrl ?? string.Empty,
225-
Arm64 = release.Assets?
226-
.FirstOrDefault(x => x.Name.ContainsIgnoreCase("win_arm64"))
227-
?.DownloadUrl ?? string.Empty
228-
},
229-
Linux = new DownloadLinks.SupportedPlatform
230-
{
231-
X64 = release.Assets?
232-
.FirstOrDefault(x => x.Name.ContainsIgnoreCase("linux_x64"))
233-
?.DownloadUrl ?? string.Empty,
234-
Arm64 = release.Assets?
235-
.FirstOrDefault(x => x.Name.ContainsIgnoreCase("linux_arm64"))
236-
?.DownloadUrl ?? string.Empty
237-
},
238-
LinuxAppImage = new DownloadLinks.SupportedPlatform
239-
{
240-
X64 = release.Assets?
241-
.FirstOrDefault(x => x.Name.EndsWithIgnoreCase("x64.AppImage"))
242-
?.DownloadUrl ?? string.Empty,
243-
Arm64 = release.Assets?
244-
.FirstOrDefault(x => x.Name.EndsWithIgnoreCase("arm64.AppImage"))
245-
?.DownloadUrl ?? string.Empty
246-
},
247-
MacOS = release.Assets?
248-
.FirstOrDefault(x =>
249-
x.Name.ContainsIgnoreCase("macos_universal") ||
250-
x.Name.ContainsIgnoreCase("macos_arm64"))
251-
?.DownloadUrl ?? string.Empty
252-
}
253-
}).ToDictionary(x => x.Tag, x => x);
213+
var tempCacheEntries = releases
214+
.Select(release => release.AsCacheEntry(ReleaseUrlFormat))
215+
.ToDictionary(x => x.Tag, x => x);
254216

255217
await _semaphore.WaitAsync();
256218

src/Server/Services/Forgejo/Model/Release.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.Text.Json.Serialization;
2+
using Gommon;
3+
using Ryujinx.Systems.Update.Common;
24

35
namespace Ryujinx.Systems.Update.Server.Services.Forgejo;
46

@@ -18,6 +20,41 @@ public class Release
1820
[JsonPropertyName("upload_url")] public string? UploadUrl { get; set; }
1921
[JsonPropertyName("url")] public string? Url { get; set; }
2022
[JsonPropertyName("zipball_url")] public string? ZipballUrl { get; set; }
23+
24+
public VersionCacheEntry AsCacheEntry(string releaseUrlFormat) =>
25+
new()
26+
{
27+
Tag = Guard.Require(TagName, nameof(TagName)),
28+
ReleaseUrl = releaseUrlFormat.Format(TagName),
29+
Downloads = new DownloadLinks
30+
{
31+
Windows = new DownloadLinks.SupportedPlatform
32+
{
33+
X64 = GetAttachmentUrl(x => x.Name.ContainsIgnoreCase("win_x64")),
34+
Arm64 = GetAttachmentUrl(x => x.Name.ContainsIgnoreCase("win_arm64"))
35+
},
36+
Linux = new DownloadLinks.SupportedPlatform
37+
{
38+
X64 = GetAttachmentUrl(x => x.Name.ContainsIgnoreCase("linux_x64")),
39+
Arm64 = GetAttachmentUrl(x => x.Name.ContainsIgnoreCase("linux_arm64"))
40+
},
41+
LinuxAppImage = new DownloadLinks.SupportedPlatform
42+
{
43+
X64 = GetAttachmentUrl(x => x.Name.EndsWithIgnoreCase("x64.AppImage")),
44+
Arm64 = GetAttachmentUrl(x => x.Name.EndsWithIgnoreCase("arm64.AppImage"))
45+
},
46+
MacOS = GetAttachmentUrl(x =>
47+
x.Name.ContainsIgnoreCase("macos_universal") ||
48+
x.Name.ContainsIgnoreCase("macos_arm64")
49+
)
50+
}
51+
};
52+
53+
public Attachment? GetAttachment(Func<Attachment, bool> predicate)
54+
=> Assets?.FirstOrDefault(predicate);
55+
56+
public string GetAttachmentUrl(Func<Attachment, bool> predicate)
57+
=> GetAttachment(predicate)?.DownloadUrl ?? string.Empty;
2158
}
2259

2360
public class Attachment

0 commit comments

Comments
 (0)