Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jim60105 committed May 25, 2024
2 parents 2582c21 + 93e646d commit 9dfa2af
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"azureFunctions.deploySubpath": "bin/Release/net6.0/publish",
"azureFunctions.deploySubpath": "bin/Release/net8.0/publish",
"azureFunctions.projectLanguage": "C#",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"type": "func",
"dependsOn": "build (functions)",
"options": {
"cwd": "${workspaceFolder}/bin/Debug/net6.0"
"cwd": "${workspaceFolder}/bin/Debug/net8.0"
},
"command": "host start",
"isBackground": true,
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG DatabaseService="ApacheCouchDB"
### Build Python
FROM debian:11 as build-python

RUN apt-get update && apt-get install -y --no-install-recommends python3=3.9.2-3 python3-pip && \
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-pip && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Expand All @@ -28,7 +28,7 @@ RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/r
find "/root/.local" -type d -name '__pycache__' -print0 | xargs -0 rm -rf || true ;

### Build .NET
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-dotnet
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-dotnet

WORKDIR /src

Expand All @@ -43,9 +43,9 @@ RUN --mount=source=.,target=.,rw \
dotnet publish "LivestreamRecorderBackend.csproj" -c $BUILD_CONFIGURATION -o /app/publish

### Final image
FROM mcr.microsoft.com/azure-functions/dotnet:4
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0

RUN apt-get update && apt-get install -y --no-install-recommends python3=3.9.2-3 dumb-init=1.2.5-1 && \
RUN apt-get update && apt-get install -y --no-install-recommends python3 dumb-init && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Expand All @@ -61,7 +61,7 @@ ENV ASPNETCORE_URLS=http://+:8080
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true
ENV CORS_SUPPORT_CREDENTIALS=true
ENV FUNCTIONS_WORKER_RUNTIME=dotnet
ENV FUNCTIONS_WORKER_RUNTIME=dotnet-isolated
ENV CORS_ALLOWED_ORIGINS=["https://localhost:4200"]
ENV FrontEndUri=https://localhost:4200
ENV AzureWebJobsStorage=
Expand Down
7 changes: 3 additions & 4 deletions Functions/Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.OpenApi.Models;
using Serilog;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;

namespace LivestreamRecorderBackend.Functions;

Expand All @@ -28,7 +27,7 @@ public Authentication(GithubService githubService)
_githubService = githubService;
}

[FunctionName(nameof(GithubSignin))]
[Function(nameof(GithubSignin))]
[OpenApiOperation(operationId: nameof(GithubSignin), tags: new[] { "Authentication" })]
[OpenApiParameter(name: "code", In = ParameterLocation.Query, Required = true, Type = typeof(string))]
[OpenApiParameter(name: "state", In = ParameterLocation.Query, Required = true, Type = typeof(string))]
Expand Down
37 changes: 20 additions & 17 deletions Functions/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
using LivestreamRecorderBackend.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.OpenApi.Models;
using Serilog;
using System;
Expand All @@ -18,6 +14,11 @@
using System.Text.Json;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;

namespace LivestreamRecorderBackend.Functions;

Expand All @@ -37,14 +38,14 @@ public Channel(
_userService = userService;
}

[FunctionName(nameof(AddChannelAsync))]
[Function(nameof(AddChannelAsync))]
[OpenApiOperation(operationId: nameof(AddChannelAsync), tags: new[] { nameof(Channel) })]
[OpenApiRequestBody("application/json", typeof(AddChannelRequest), Required = true)]
[OpenApiResponseWithBody(HttpStatusCode.OK, "application/json", typeof(string), Description = "Response")]
public async Task<IActionResult> AddChannelAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Channel")]
HttpRequest req,
[DurableClient] IDurableClient starter)
[DurableClient] DurableTaskClient starter)
{
try
{
Expand Down Expand Up @@ -122,8 +123,8 @@ public async Task<IActionResult> AddChannelAsync(

_logger.Information("Finish adding channel {channelName}:{channelId}", channelName, channelId);

var instanceId = await starter.StartNewAsync(
orchestratorFunctionName: nameof(UpdateChannel_Durable),
var instanceId = await starter.ScheduleNewOrchestrationInstanceAsync(
orchestratorName: nameof(UpdateChannel_Durable),
input: new UpdateChannelRequest()
{
id = channelId,
Expand All @@ -137,7 +138,8 @@ public async Task<IActionResult> AddChannelAsync(

_logger.Information("Started orchestration with ID {instanceId}.", instanceId);
// Wait for the instance to start executing
return await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId, TimeSpan.FromSeconds(15));
await starter.WaitForInstanceStartAsync(instanceId);
return new OkResult();
}
catch (Exception e)
{
Expand All @@ -151,15 +153,15 @@ public async Task<IActionResult> AddChannelAsync(
}
}

[FunctionName(nameof(UpdateChannel_Http))]
[Function(nameof(UpdateChannel_Http))]
[OpenApiOperation(operationId: nameof(UpdateChannel_Http), tags: new[] { nameof(Channel) })]
[OpenApiParameter(name: "channelId", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "ChannelId")]
[OpenApiResponseWithBody(HttpStatusCode.OK, "application/json", typeof(string), Description = "Response")]
// skipcq: CS-R1073
public async Task<IActionResult> UpdateChannel_Http(
[HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "Channel")]
HttpRequest req,
[DurableClient] IDurableClient starter)
[DurableClient] DurableTaskClient starter)
{
try
{
Expand All @@ -176,8 +178,8 @@ public async Task<IActionResult> UpdateChannel_Http(
var data = JsonSerializer.Deserialize<UpdateChannelRequest>(requestBody)
?? throw new InvalidOperationException("Invalid request body!!");

await starter.StartNewAsync(
orchestratorFunctionName: nameof(UpdateChannel_Durable),
await starter.ScheduleNewOrchestrationInstanceAsync(
orchestratorName: nameof(UpdateChannel_Durable),
input: data);

return new OkResult();
Expand All @@ -189,11 +191,12 @@ await starter.StartNewAsync(
}
}

[FunctionName(nameof(UpdateChannel_Durable))]
[Function(nameof(UpdateChannel_Durable))]
public bool UpdateChannel_Durable(
[OrchestrationTrigger] IDurableOrchestrationContext context)
[OrchestrationTrigger] TaskOrchestrationContext context)
{
var data = context.GetInput<UpdateChannelRequest>();
if (null == data) throw new InvalidOperationException("Invalid request body!!");
_ = Task.Run(async () =>
{
_logger.Information("Start updating channel {channelId}", data.id);
Expand All @@ -219,7 +222,7 @@ public bool UpdateChannel_Durable(
return true;
}

[FunctionName(nameof(EnableChannelAsync))]
[Function(nameof(EnableChannelAsync))]
[OpenApiOperation(operationId: nameof(EnableChannelAsync), tags: new[] { nameof(Channel) })]
[OpenApiRequestBody("application/json", typeof(EnableChannelRequest), Required = true)]
[OpenApiResponseWithoutBody(HttpStatusCode.OK, Description = "Response")]
Expand Down Expand Up @@ -258,7 +261,7 @@ public async Task<IActionResult> EnableChannelAsync(
}
}

[FunctionName(nameof(HideChannelAsync))]
[Function(nameof(HideChannelAsync))]
[OpenApiOperation(operationId: nameof(HideChannelAsync), tags: new[] { nameof(Channel) })]
[OpenApiRequestBody("application/json", typeof(HideChannelRequest), Required = true)]
[OpenApiResponseWithoutBody(HttpStatusCode.OK, Description = "Response")]
Expand Down
11 changes: 5 additions & 6 deletions Functions/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
using LivestreamRecorderBackend.Services.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Omu.ValueInjecter;
using Serilog;
using System;
Expand All @@ -16,6 +13,8 @@
using System.Text.Json;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;

namespace LivestreamRecorderBackend.Functions;

Expand All @@ -35,7 +34,7 @@ public User(
_authenticationService = authenticationService;
}

[FunctionName(nameof(GetUserAsync))]
[Function(nameof(GetUserAsync))]
[OpenApiOperation(operationId: nameof(GetUserAsync), tags: new[] { nameof(User) })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(GetUserResponse), Description = "User")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Description = "User not found.")]
Expand All @@ -61,7 +60,7 @@ public async Task<IActionResult> GetUserAsync(
}


[FunctionName(nameof(CreateOrUpdateUser))]
[Function(nameof(CreateOrUpdateUser))]
[OpenApiOperation(operationId: nameof(CreateOrUpdateUser), tags: new[] { nameof(User) })]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.OK, Description = "The OK response")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Description = "Issuer not supported")]
Expand Down Expand Up @@ -97,7 +96,7 @@ public async Task<IActionResult> CreateOrUpdateUser(
}
}

[FunctionName(nameof(UpdateUserAsync))]
[Function(nameof(UpdateUserAsync))]
[OpenApiOperation(operationId: nameof(UpdateUserAsync), tags: new[] { nameof(User) })]
[OpenApiRequestBody("application/json", typeof(UpdateUserRequest), Required = true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(GetUserResponse), Description = "User")]
Expand Down
13 changes: 7 additions & 6 deletions Functions/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Serilog;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;

namespace LivestreamRecorderBackend.Functions;

Expand All @@ -18,17 +17,19 @@ public Utility(
_logger = logger;
}

[FunctionName(nameof(Wake))]
[Function(nameof(Wake))]
[OpenApiOperation(operationId: nameof(Wake), tags: new[] { nameof(Utility) })]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.OK, Description = "Waked.")]
public IActionResult Wake([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Utility/Wake")] HttpRequest req)
public IActionResult Wake(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Utility/Wake")]
HttpRequest req)
{
Wake();
return new OkResult();
}

#if RELEASE && Windows
[FunctionName(nameof(WakeByTimer))]
[Function(nameof(WakeByTimer))]
public void WakeByTimer([TimerTrigger("0 * * * * *")] TimerInfo timerInfo)
=> Wake();
#endif
Expand Down
18 changes: 9 additions & 9 deletions Functions/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
using LivestreamRecorderBackend.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.OpenApi.Models;
using Serilog;
using System;
Expand All @@ -16,6 +13,9 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using System.Linq;

namespace LivestreamRecorderBackend.Functions;

Expand All @@ -37,7 +37,7 @@ public Video(
_frontEndUri = Environment.GetEnvironmentVariable("FrontEndUri") ?? "http://localhost:4200";
}

[FunctionName(nameof(AddVideoAsync))]
[Function(nameof(AddVideoAsync))]
[OpenApiOperation(operationId: nameof(AddVideoAsync), tags: new[] { nameof(Video) })]
[OpenApiRequestBody("application/json", typeof(AddVideoRequest), Required = true)]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.OK, Description = "Ok")]
Expand Down Expand Up @@ -83,7 +83,7 @@ public async Task<IActionResult> AddVideoAsync(
}
}

[FunctionName(nameof(UpdateVideoAsync))]
[Function(nameof(UpdateVideoAsync))]
[OpenApiOperation(operationId: nameof(UpdateVideoAsync), tags: new[] { nameof(Video) })]
[OpenApiRequestBody("application/json", typeof(UpdateVideoRequest), Required = true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Video), Description = "Video")]
Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task<IActionResult> UpdateVideoAsync(
}
}

[FunctionName(nameof(RemoveVideoAsync))]
[Function(nameof(RemoveVideoAsync))]
[OpenApiOperation(operationId: nameof(RemoveVideoAsync), tags: new[] { nameof(Video) })]
[OpenApiParameter(name: "videoId", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "VideoId")]
[OpenApiParameter(name: "channelId", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "ChannelId")]
Expand All @@ -161,7 +161,7 @@ public async Task<IActionResult> RemoveVideoAsync(
if (null == user) return new UnauthorizedResult();
if (!user.IsAdmin) return new StatusCodeResult(403);

IDictionary<string, string> queryDictionary = req.GetQueryParameterDictionary();
IDictionary<string, string?> queryDictionary = req.Query.ToDictionary(p => p.Key, p => p.Value.Last());
queryDictionary.TryGetValue("videoId", out var videoId);
queryDictionary.TryGetValue("channelId", out var channelId);

Expand Down Expand Up @@ -196,7 +196,7 @@ public async Task<IActionResult> RemoveVideoAsync(
}
}

[FunctionName(nameof(GetToken))]
[Function(nameof(GetToken))]
[OpenApiOperation(operationId: nameof(GetToken), tags: new[] { nameof(Video) })]
[OpenApiParameter(name: "videoId", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "VideoId")]
[OpenApiParameter(name: "channelId", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "ChannelId")]
Expand All @@ -215,7 +215,7 @@ public async Task<IActionResult> GetToken(
&& !user.IsAdmin)
return new StatusCodeResult(403);

IDictionary<string, string> queryDictionary = req.GetQueryParameterDictionary();
IDictionary<string, string?> queryDictionary = req.Query.ToDictionary(p => p.Key, p => p.Value.Last());
queryDictionary.TryGetValue("videoId", out var videoId);
queryDictionary.TryGetValue("channelId", out var channelId);

Expand Down
2 changes: 1 addition & 1 deletion LivestreamRecorder.DB
Loading

0 comments on commit 9dfa2af

Please sign in to comment.