Skip to content

Commit

Permalink
Update to .NET 8, this time without force merging (#122)
Browse files Browse the repository at this point in the history
* switch to .NET 8

* switch to primary constructors
  • Loading branch information
InFTord committed Mar 31, 2024
1 parent d9cbb2a commit 0f758a0
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 223 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,28 @@ jobs:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
name: Check out code

- name: Set version
run: echo LIGHTTUBE_VERSION=`date +%Y%m%d` >> $GITHUB_ENV

- name: Check version
run: echo Building version ${{ env.LIGHTTUBE_VERSION }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
driver-opts: |
image=moby/buildkit:v0.10.6
-
name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/arm64,linux/amd64
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/r2r.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
- linux-arm
- linux-arm64
- osx-x64
- osx.11.0-arm64

if: |
!contains(github.event.head_commit.message, 'skip ci')
Expand All @@ -32,11 +31,11 @@ jobs:
contents: write # In order to be able to push releases

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand All @@ -47,7 +46,7 @@ jobs:
run: dotnet publish -c Release -r ${{ matrix.platform }} -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true -p:PublishTrimmed=true -p:TrimMode=partial --self-contained true

- name: Upload binaries
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }} R2R Binaries
path: '*/bin/Release/*/${{ matrix.platform }}/publish/'
Expand All @@ -64,7 +63,7 @@ jobs:
- name: Create Release
# You may pin to the exact commit or the version.
# uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e
uses: ncipollo/release-action@v1.12.0
uses: ncipollo/release-action@v1.13.0
if: |
github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
Expand Down
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETARCH
WORKDIR /src
COPY ["LightTube/LightTube.csproj", "LightTube/"]
RUN dotnet restore "LightTube/LightTube.csproj"
RUN dotnet restore -a $TARGETARCH "LightTube/LightTube.csproj"
COPY . .
WORKDIR "/src/LightTube"
RUN dotnet build "LightTube.csproj" -c Release -o /app/build /p:Version=`date +0.%Y.%m.%d`
RUN dotnet build "LightTube.csproj" -a $TARGETARCH -c Release -o /app/build /p:Version=`date +0.%Y.%m.%d`

FROM build AS publish
RUN dotnet publish "LightTube.csproj" -c Release -o /app/publish /p:Version=`date +0.%Y.%m.%d`
RUN dotnet publish "LightTube.csproj" -a $TARGETARCH -c Release -o /app/publish /p:Version=`date +0.%Y.%m.%d`

FROM base AS final
WORKDIR /app
Expand Down
5 changes: 1 addition & 4 deletions LightTube/Contexts/ChannelsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace LightTube.Contexts;

public class ChannelsContext : BaseContext
public class ChannelsContext(HttpContext context) : BaseContext(context)
{
public IEnumerable<DatabaseChannel?> Channels;

public ChannelsContext(HttpContext context) : base(context)
{ }
}
12 changes: 3 additions & 9 deletions LightTube/Contexts/ImportContext.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
namespace LightTube.Contexts;

public class ImportContext : BaseContext
public class ImportContext(HttpContext context, string? message = null, bool isError = false) : BaseContext(context)
{
public string? Message { get; }
public bool IsError { get; }

public ImportContext(HttpContext context, string? message = null, bool isError = false) : base(context)
{
Message = message;
IsError = isError;
}
public string? Message { get; } = message;
public bool IsError { get; } = isError;
}
21 changes: 5 additions & 16 deletions LightTube/Contexts/ModalContext.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
namespace LightTube.Contexts;

public class ModalContext : BaseContext
public class ModalContext(HttpContext context) : BaseContext(context)
{
public string Title { get; set; }

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (win-x86)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (win-x86)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-musl-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-musl-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.

Check warning on line 5 in LightTube/Contexts/ModalContext.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

'ModalContext.Title' hides inherited member 'BaseContext.Title'. Use the new keyword if hiding was intended.
public ModalButton[] Buttons { get; set; }
public bool AlignToStart { get; set; }

public ModalContext(HttpContext context) : base(context)
{
}
}

public class ModalButton
public class ModalButton(string label, string target, string type)
{
public string Type;
public string Target;
public string Label;

public ModalButton(string label, string target, string type)
{
Label = label;
Target = target;
Type = type;
}
public string Type = type;
public string Target = target;
public string Label = label;
}
5 changes: 1 addition & 4 deletions LightTube/Contexts/SubscriptionsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace LightTube.Contexts;

public class SubscriptionsContext : BaseContext
public class SubscriptionsContext(HttpContext context) : BaseContext(context)
{
public FeedVideo[] Videos;

public SubscriptionsContext(HttpContext context) : base(context)
{ }
}
11 changes: 3 additions & 8 deletions LightTube/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@
namespace LightTube.Controllers;

[Route("/api")]
public class ApiController : Controller
public class ApiController(InnerTube.InnerTube youtube) : Controller
{
private const string VIDEO_ID_REGEX = @"[a-zA-Z0-9_-]{11}";
private const string CHANNEL_ID_REGEX = @"[a-zA-Z0-9_-]{24}";
private const string PLAYLIST_ID_REGEX = @"[a-zA-Z0-9_-]{34}";
private readonly InnerTube.InnerTube _youtube;
private readonly InnerTube.InnerTube _youtube = youtube;

public ApiController(InnerTube.InnerTube youtube)
{
_youtube = youtube;
}

[Route("info")]
[Route("info")]
public LightTubeInstanceInfo GetInstanceInfo() =>
new()
{
Expand Down
11 changes: 3 additions & 8 deletions LightTube/Controllers/FeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@
namespace LightTube.Controllers;

[Route("/feed")]
public class FeedController : Controller
public class FeedController(InnerTube.InnerTube youtube) : Controller
{
private InnerTube.InnerTube _youtube;
private InnerTube.InnerTube _youtube = youtube;

public FeedController(InnerTube.InnerTube youtube)
{
_youtube = youtube;
}

[Route("subscriptions")]
[Route("subscriptions")]
public async Task<IActionResult> Subscription()
{
SubscriptionsContext ctx = new(HttpContext);
Expand Down
11 changes: 3 additions & 8 deletions LightTube/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@

namespace LightTube.Controllers;

public class HomeController : Controller
public class HomeController(ILogger<HomeController> logger) : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly ILogger<HomeController> _logger = logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index() => View(new HomepageContext(HttpContext));
public IActionResult Index() => View(new HomepageContext(HttpContext));

[Route("/rss")]
public IActionResult Rss() => View(new BaseContext(HttpContext));
Expand Down
11 changes: 3 additions & 8 deletions LightTube/Controllers/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
namespace LightTube.Controllers;

[Route("/proxy")]
public class ProxyController : Controller
public class ProxyController(InnerTube.InnerTube youtube) : Controller
{
private readonly InnerTube.InnerTube _youtube;
private readonly InnerTube.InnerTube _youtube = youtube;
private readonly HttpClient client = new HttpClient();

private string[] _blockedHeaders =
Expand All @@ -31,12 +31,7 @@ public class ProxyController : Controller
"cross-origin-resource-policy"
};

public ProxyController(InnerTube.InnerTube youtube)
{
_youtube = youtube;
}

[Route("media/{videoId}/{formatId}")]
[Route("media/{videoId}/{formatId}")]
[Route("media/{videoId}/{formatId}.{extension}")]
public async Task Media(string videoId, string formatId, string? audioTrackId, string? extension = null)
{
Expand Down
11 changes: 3 additions & 8 deletions LightTube/Controllers/OauthApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ namespace LightTube.Controllers;

[Route("/api")]
[ApiDisableable]
public class OauthApiController : Controller
public class OauthApiController(InnerTube.InnerTube youtube) : Controller
{
private readonly InnerTube.InnerTube _youtube;
private readonly InnerTube.InnerTube _youtube = youtube;

public OauthApiController(InnerTube.InnerTube youtube)
{
_youtube = youtube;
}

private ApiResponse<T> Error<T>(string message, int code,
private ApiResponse<T> Error<T>(string message, int code,
HttpStatusCode statusCode)
{
Response.StatusCode = (int)statusCode;
Expand Down
11 changes: 3 additions & 8 deletions LightTube/Controllers/OpenSearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
namespace LightTube.Controllers;

[Route("/opensearch")]
public class OpenSearchController : Controller
public class OpenSearchController(InnerTube.InnerTube youtube) : Controller
{
private readonly InnerTube.InnerTube _youtube;
private readonly InnerTube.InnerTube _youtube = youtube;

public OpenSearchController(InnerTube.InnerTube youtube)
{
_youtube = youtube;
}

[Route("osdd.xml")]
[Route("osdd.xml")]
public IActionResult OpenSearchDescriptionDocument()
{
XmlDocument doc = new();
Expand Down
11 changes: 3 additions & 8 deletions LightTube/Controllers/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
namespace LightTube.Controllers;

[Route("/settings")]
public class SettingsController : Controller
public class SettingsController(InnerTube.InnerTube youtube) : Controller
{
private readonly InnerTube.InnerTube _youtube;
private readonly InnerTube.InnerTube _youtube = youtube;

public SettingsController(InnerTube.InnerTube youtube)
{
_youtube = youtube;
}

[Route("/settings")]
[Route("/settings")]
public IActionResult Settings() => RedirectPermanent("/settings/appearance");

[Route("content")]
Expand Down
14 changes: 4 additions & 10 deletions LightTube/Controllers/YoutubeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@

namespace LightTube.Controllers;

public class YoutubeController : Controller
public class YoutubeController(InnerTube.InnerTube youtube, HttpClient client) : Controller
{
private readonly InnerTube.InnerTube _youtube;
private readonly HttpClient _client;
private readonly InnerTube.InnerTube _youtube = youtube;
private readonly HttpClient _client = client;

public YoutubeController(InnerTube.InnerTube youtube, HttpClient client)
{
_youtube = youtube;
_client = client;
}

[Route("/embed/{v}")]
[Route("/embed/{v}")]
public async Task<IActionResult> Embed(string v, bool contentCheckOk, bool compatibility = false)
{
InnerTubePlayer player;
Expand Down
16 changes: 5 additions & 11 deletions LightTube/Database/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@

namespace LightTube.Database;

public class CacheManager
public class CacheManager(IMongoCollection<DatabaseChannel> channelCollection,
IMongoCollection<DatabaseVideo> videoCollection)
{
public IMongoCollection<DatabaseChannel> ChannelCollection;
public IMongoCollection<DatabaseVideo> VideoCollection;
public IMongoCollection<DatabaseChannel> ChannelCollection = channelCollection;
public IMongoCollection<DatabaseVideo> VideoCollection = videoCollection;

public CacheManager(IMongoCollection<DatabaseChannel> channelCollection,
IMongoCollection<DatabaseVideo> videoCollection)
{
ChannelCollection = channelCollection;
VideoCollection = videoCollection;
}

public async Task AddChannel(DatabaseChannel channel, bool updateOnly = false)
public async Task AddChannel(DatabaseChannel channel, bool updateOnly = false)
{
if (await ChannelCollection.CountDocumentsAsync(x => x.ChannelId == channel.ChannelId) > 0)
await ChannelCollection.ReplaceOneAsync(x => x.ChannelId == channel.ChannelId, channel);
Expand Down
11 changes: 3 additions & 8 deletions LightTube/Database/Oauth2Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@

namespace LightTube.Database;

public class Oauth2Manager
public class Oauth2Manager(IMongoCollection<DatabaseOauthToken> oauthTokensCollection)
{
public IMongoCollection<DatabaseOauthToken> OauthTokensCollection { get; }
public IMongoCollection<DatabaseOauthToken> OauthTokensCollection { get; } = oauthTokensCollection;

public Oauth2Manager(IMongoCollection<DatabaseOauthToken> oauthTokensCollection)
{
OauthTokensCollection = oauthTokensCollection;
}

public async Task<string> CreateOauthToken(string loginToken, string clientId, string[] scopes)
public async Task<string> CreateOauthToken(string loginToken, string clientId, string[] scopes)
{
DatabaseUser user = (await DatabaseManager.Users.GetUserFromToken(loginToken))!;
string refreshToken = Utils.GenerateToken(512);
Expand Down
Loading

0 comments on commit 0f758a0

Please sign in to comment.