Skip to content

Commit

Permalink
Next js migration (#99)
Browse files Browse the repository at this point in the history
Move to nextjs
  • Loading branch information
SenexCrenshaw authored Oct 5, 2023
1 parent c65866b commit d9b464e
Show file tree
Hide file tree
Showing 379 changed files with 20,863 additions and 37,303 deletions.
390 changes: 3 additions & 387 deletions .gitignore

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ WORKDIR "/src/StreamMasterAPI"
#RUN if [ "$ENV" = "debug" ] ; then dotnet build "StreamMasterAPI.csproj" -c Debug -o /app/build; else dotnet build "StreamMasterAPI.csproj" -c Release -o /app/build; fi
RUN dotnet build "StreamMasterAPI.csproj" -c Debug -o /app/build -a $TARGETARCH
# installs NodeJS and NPM
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -yq nodejs build-essential
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq ca-certificates curl gnupg git nano

RUN mkdir -p /etc/apt/keyrings
RUN curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install -yq nodejs build-essential
WORKDIR /src
COPY ["streammasterwebui/", "streammasterwebui/"]
WORKDIR "/src/streammasterwebui"
Expand Down
66 changes: 36 additions & 30 deletions HookGenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System.Net.Sockets;
using System.Text;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
internal class Program
{
private static readonly List<string> blackList = new() { "programmesGetProgramme", "programmesGetProgrammeChannels", "programmesGetProgrammes", "programmesGetProgrammeFromDisplayName", "schedulesDirectGetHeadends", "schedulesDirectGetSchedules", "schedulesDirectGetStations", "videoStreamsGetAllStatisticsForAllUrls", "streamGroupVideoStreamsGetStreamGroupVideoStreamIds" };
private static readonly Dictionary<string, string> overRideArgs = new() { { "GetIconFromSource", "StringArg" } };
private static readonly Dictionary<string, string> additionalImports = new() { { "Icons", "import { type StringArg } from \"../../components/selectors/BaseSelector\";" } };
private static readonly Dictionary<string, string> additionalImports = new() { { "Icons", "import { type StringArg } from '@/src/components/selectors/BaseSelector';" } };


private const string SwaggerUrl = "http://127.0.0.1:7095/swagger/v1/swagger.json";
private const string LocalFileName = "swagger.json";
private const string OutputDir = @"..\..\..\..\StreamMasterwebui\src\smAPI";
private const string OutputDir = @"..\..\..\..\StreamMasterwebui\lib\smAPI";
private static readonly Dictionary<string, StringBuilder> tagToGetContentMap = new();
private static readonly Dictionary<string, StringBuilder> tagToMutateContentMap = new();
private static readonly Dictionary<string, Dictionary<string, string>> getMethodResponseTypes = new();
Expand Down Expand Up @@ -65,9 +64,10 @@ private static (Dictionary<string, StringBuilder> getMap, Dictionary<string, Str
{
tagToGetContentMap[tag] = new StringBuilder();
// Add imports at the start of each new file's content
tagToGetContentMap[tag].AppendLine("import { hubConnection } from \"../../app/signalr\";");
tagToGetContentMap[tag].AppendLine("import { isDebug } from \"../../settings\";");
tagToGetContentMap[tag].AppendLine("import type * as iptv from \"../../store/iptvApi\";");
tagToGetContentMap[tag].AppendLine("/* eslint unused-imports/no-unused-imports-ts: off */");
tagToGetContentMap[tag].AppendLine("/* eslint @typescript-eslint/no-unused-vars: off */");
tagToGetContentMap[tag].AppendLine("import { invokeHubConnection } from '@/lib/signalr/signalr';");
tagToGetContentMap[tag].AppendLine("import type * as iptv from '@/lib/iptvApi';");
if (additionalImports.ContainsKey(tag))
{
tagToGetContentMap[tag].AppendLine(additionalImports[tag]);
Expand Down Expand Up @@ -100,27 +100,32 @@ private static (Dictionary<string, StringBuilder> getMap, Dictionary<string, Str
{
tagToMutateContentMap[tag] = new StringBuilder();
// Add imports at the start of each new file's content
tagToMutateContentMap[tag].AppendLine("import { hubConnection } from \"../../app/signalr\";");
tagToMutateContentMap[tag].AppendLine("import { isDebug } from \"../../settings\";");
tagToMutateContentMap[tag].AppendLine("import type * as iptv from \"../../store/iptvApi\";\r\n");
tagToMutateContentMap[tag].AppendLine("/* eslint unused-imports/no-unused-imports-ts: off */");
tagToMutateContentMap[tag].AppendLine("/* eslint @typescript-eslint/no-unused-vars: off */");
tagToMutateContentMap[tag].AppendLine("import { invokeHubConnection } from '@/lib/signalr/signalr';");
tagToMutateContentMap[tag].AppendLine("import type * as iptv from '@/lib/iptvApi';\r\n");
}
contentToUse = tagToMutateContentMap[tag];
}
if (overRideArgs.ContainsKey(functionName))
{
argType = overRideArgs[functionName];
}
contentToUse.AppendLine($"export const {functionName} = async {(argType != null ? $"(arg: {argType})" : "()")}: Promise<{responseType}> => {{");
contentToUse.AppendLine($" if (isDebug) console.log('{functionName}');");
contentToUse.AppendLine($"export const {functionName} = async {(argType != null ? $"(arg: {argType})" : "()")}: Promise<{responseType} | null> => {{");
//contentToUse.AppendLine($" if (hubConnection.state === 'Connected') {{");
//contentToUse.AppendLine($" if (isDev) console.log('{functionName}');");
if (responseType != "void")
{
contentToUse.AppendLine($" const data = await hubConnection.invoke('{functionName}'{(argType != null ? ", arg" : "")});");
contentToUse.AppendLine($" return data;");
contentToUse.AppendLine($" return await invokeHubConnection<{responseType}> ('{functionName}'{(responseType != "void" ? ", arg" : "")});");
//contentToUse.AppendLine($" const data = await hubConnection.invoke('{functionName}'{(argType != null ? ", arg" : "")});");
//contentToUse.AppendLine($" return data;");
}
else
{
contentToUse.AppendLine($" await hubConnection.invoke('{functionName}'{(argType != null ? ", arg" : "")});");
//contentToUse.AppendLine($" await hubConnection.invoke('{functionName}'{(argType != null ? ", arg" : "")});");
contentToUse.AppendLine($" await invokeHubConnection<void> ('{functionName}'{(argType != null ? ", arg" : "")});");
}
//contentToUse.AppendLine(" };\r\n");
contentToUse.AppendLine("};\r\n");
}
}
Expand All @@ -144,7 +149,7 @@ private static bool IsPagedOrIsArray(string responseType)
{
return IsPaged(responseType) || IsArray(responseType);
}
private static string GetUpdateFunction(string endpointName,string argType, string responseType,string tag)
private static string GetUpdateFunction(string endpointName, string argType, string responseType, string tag)
{

List<string> args = getMethodArgTypes.SelectMany(kv => kv.Value.Keys).ToList();
Expand All @@ -155,13 +160,13 @@ private static string GetUpdateFunction(string endpointName,string argType, stri
if (IsPagedOrIsArray(responseType))
{
ret.AppendLine($" if (!data || isEmptyObject(data)) {{");
ret.AppendLine($" console.log('empty', data);");
ret.AppendLine($" if (isDev) console.log('empty', data);");
ret.AppendLine($" dispatch(iptvApi.util.invalidateTags(['{tag}']));");
ret.AppendLine($" return;");
ret.AppendLine($" }}");
ret.AppendLine();
ret.AppendLine($" updateCachedData(() => {{");
//ret.AppendLine($" console.log('updateCachedData', data);");
//ret.AppendLine($" if (isDev) console.log('updateCachedData', data);");
ret.AppendLine($" for (const {{ endpointName, originalArgs }} of iptvApi.util.selectInvalidatedBy(getState(), [{{ type: '{tag}' }}])) {{");
ret.AppendLine($" if (endpointName !== '{endpointName}') continue;");
ret.AppendLine($" dispatch(");
Expand All @@ -172,7 +177,7 @@ private static string GetUpdateFunction(string endpointName,string argType, stri
ret.AppendLine($" const index = {draft}.findIndex(existingItem => existingItem.id === item.id);");
ret.AppendLine($" if (index !== -1) {{");
ret.AppendLine($" {draft}[index] = item;");
ret.AppendLine($" }}");
ret.AppendLine($" }}");
ret.AppendLine($" }});");
ret.AppendLine();
ret.AppendLine($" return draft;");
Expand All @@ -197,16 +202,16 @@ private static string GetUpdateFunction(string endpointName,string argType, stri
return ret.ToString();
}
ret.AppendLine($" updateCachedData(() => {{");
ret.AppendLine($" console.log('updateCachedData', data);");
ret.AppendLine($" if (isDev) console.log('updateCachedData', data);");
ret.AppendLine($" for (const {{ endpointName, originalArgs }} of iptvApi.util.selectInvalidatedBy(getState(), [{{ type: '{tag}' }}])) {{");
ret.AppendLine($" if (endpointName !== '{endpointName}') continue;");
ret.AppendLine($" dispatch(iptvApi.util.updateQueryData(endpointName, originalArgs, (draft) => {{");
ret.AppendLine($" console.log('updateCachedData', data, draft);");
ret.AppendLine($" if (isDev) console.log('updateCachedData', data, draft);");
ret.AppendLine($" }})");
ret.AppendLine($" );");
ret.AppendLine($" }}");
ret.AppendLine();

return ret.ToString();
}
private static Dictionary<string, StringBuilder> BuildEnhanced()
Expand All @@ -218,11 +223,12 @@ private static Dictionary<string, StringBuilder> BuildEnhanced()

StringBuilder rtkContent = new();

rtkContent.AppendLine($"import {{ {singleTon} }} from '../../app/createSingletonListener';");
rtkContent.AppendLine($"import {{ isEmptyObject }} from '../../common/common';");
rtkContent.AppendLine($"import isPagedTableDto from '../../components/dataSelector/isPagedTableDto';");
rtkContent.AppendLine($"import {{ iptvApi }} from '../../store/iptvApi';");
rtkContent.AppendLine($"import type * as iptv from '../../store/iptvApi';");
rtkContent.AppendLine("import { isDev } from '@/lib/settings';");
rtkContent.AppendLine($"import {{ {singleTon} }} from '@/lib/signalr/singletonListeners';");
rtkContent.AppendLine($"import {{ isEmptyObject }} from '@/lib/common/common';");
rtkContent.AppendLine($"import isPagedTableDto from '@/lib/common/isPagedTableDto';");
rtkContent.AppendLine($"import {{ iptvApi }} from '@/lib/iptvApi';");
rtkContent.AppendLine($"import type * as iptv from '@/lib/iptvApi';");
rtkContent.AppendLine();
rtkContent.AppendLine($"export const enhancedApi{ConvertToTypeScriptPascalCase(tag)} = iptvApi.enhanceEndpoints({{");
rtkContent.AppendLine($" endpoints: {{");
Expand Down Expand Up @@ -252,8 +258,8 @@ private static Dictionary<string, StringBuilder> BuildEnhanced()
//arg = getMethodArgTypes[tag][getMethod];

anyToWrite = true;
string updateFunction = GetUpdateFunction(name,arg, responseType,tag);
string updateFunction = GetUpdateFunction(name, arg, responseType, tag);

rtkContent.AppendLine($" {name}: {{");
rtkContent.AppendLine($" async onCacheEntryAdded(api, {{ dispatch, getState, updateCachedData, cacheDataLoaded, cacheEntryRemoved }}) {{");
rtkContent.AppendLine($" try {{");
Expand All @@ -265,7 +271,7 @@ private static Dictionary<string, StringBuilder> BuildEnhanced()
//rtkContent.AppendLine($" return draft;");
rtkContent.AppendLine($" }});");
rtkContent.AppendLine($" }};");
rtkContent.AppendLine();
rtkContent.AppendLine();
rtkContent.AppendLine($" {singleTon}.addListener(updateCachedDataWithResults);");
rtkContent.AppendLine();
rtkContent.AppendLine($" await cacheEntryRemoved;");
Expand Down
14 changes: 9 additions & 5 deletions StreamMasterAPI/ConfigureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using StreamMasterApplication.Hubs;
using StreamMasterApplication.Services;

using StreamMasterDomain.Enums;
using StreamMasterDomain.EnvironmentInfo;
using StreamMasterDomain.Logging;

Expand Down Expand Up @@ -66,7 +67,7 @@ public static IServiceCollection AddWebUIServices(this IServiceCollection servic
{
options.AddPolicy("DevPolicy",
builder =>
builder
builder
.WithOrigins("http://localhost:3000")
.AllowAnyMethod()
.AllowAnyHeader()
Expand All @@ -75,14 +76,17 @@ public static IServiceCollection AddWebUIServices(this IServiceCollection servic
options.AddPolicy(VersionedApiControllerAttribute.API_CORS_POLICY,
builder =>
builder.AllowAnyOrigin()
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
options.AddPolicy("AllowGet",
builder =>
builder.AllowAnyOrigin()
.WithMethods("GET", "OPTIONS")
builder
.AllowAnyOrigin()
//.WithMethods("GET", "OPTIONS")
.AllowAnyMethod()
.AllowAnyHeader());
});

Expand Down Expand Up @@ -159,7 +163,7 @@ public static IServiceCollection AddWebUIServices(this IServiceCollection servic
});
// Require auth on everything except those marked [AllowAnonymous]
options.FallbackPolicy = new AuthorizationPolicyBuilder("API")
options.FallbackPolicy = new AuthorizationPolicyBuilder(AuthenticationType.Forms.ToString(), "API")
.RequireAuthenticatedUser()
.Build();
});
Expand Down
4 changes: 4 additions & 0 deletions StreamMasterAPI/Controllers/FilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class FilesController(IMemoryCache memoryCache, IContentTypeProvider mime
public async Task<IActionResult> GetFile(string source, SMFileTypes filetype, CancellationToken cancellationToken)
{
string sourceDecoded = HttpUtility.UrlDecode(source);
if (source == "noimage.png")
{
return Redirect("/images/default.png");
}

(byte[]? image, string? fileName) = await GetCacheEntryAsync(sourceDecoded, filetype, cancellationToken).ConfigureAwait(false);
if (image == null || fileName == null)
Expand Down
17 changes: 17 additions & 0 deletions StreamMasterAPI/Controllers/VideoStreamsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public async Task<ActionResult<PagedResponse<VideoStreamDto>>> GetPagedVideoStre

[Authorize(Policy = "SGLinks")]
[HttpGet]
[HttpHead]
[Route("stream/{encodedIds}")]
[Route("stream/{encodedIds}.mp4")]
[Route("stream/{encodedIds}/{name}")]
Expand Down Expand Up @@ -262,6 +263,22 @@ public async Task<IActionResult> SimulateStreamFailure(SimulateStreamFailureRequ
return Ok();
}

[HttpPatch]
[Route("[action]")]
public async Task<IActionResult> AutoSetEPG(AutoSetEPGRequest request)
{
await Mediator.Send(request).ConfigureAwait(false);
return Ok();
}

[HttpPatch]
[Route("[action]")]
public async Task<IActionResult> AutoSetEPGFromParameters(AutoSetEPGFromParametersRequest request)
{
await Mediator.Send(request).ConfigureAwait(false);
return Ok();
}

private class UnregisterClientOnDispose : IDisposable
{
private readonly IChannelManager _channelManager;
Expand Down
3 changes: 2 additions & 1 deletion StreamMasterAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
{
_ = app.UseCors();
}
//_ = app.UseCors();

app.UseAuthentication();
app.UseAuthorization();
Expand Down Expand Up @@ -174,7 +175,7 @@
}
});

app.MapHub<StreamMasterHub>("/streammasterhub").RequireAuthorization("SignalR");
app.MapHub<StreamMasterHub>("/streammasterhub");//.RequireAuthorization(AuthenticationType.Forms.ToString());

app.Run();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FluentValidation;

using StreamMasterDomain.EPG;
using StreamMasterDomain.Models;

namespace StreamMasterApplication.EPGFiles.Commands;

Expand Down Expand Up @@ -111,14 +110,17 @@ private async Task AddProgrammesFromEPG(EPGFile epgFile, CancellationToken cance
//bool needsEpgName = epgs.Count > 1;

// Convert the list of channels to a dictionary for faster lookups, only considering the first occurrence of each ID
var channelLookup = epg.Channel
Dictionary<string?, TvChannel> channelLookup = epg.Channel
.Where(ch => ch.Id != null)
.GroupBy(ch => ch.Id)
.ToDictionary(group => group.Key, group => group.First());

foreach (Programme p in epg.Programme)
{
if (cancellationToken.IsCancellationRequested) break;
if (cancellationToken.IsCancellationRequested)
{
break;
}

if (channelLookup.TryGetValue(p.Channel, out TvChannel channel))
{
Expand All @@ -128,17 +130,20 @@ private async Task AddProgrammesFromEPG(EPGFile epgFile, CancellationToken cance
{
p.DisplayName = epgFile.Name + " : " + channelNameSuffix;
p.ChannelName = p.Channel + " - " + channelNameSuffix;
p.Name = channelNameSuffix;
}
else
{
p.DisplayName = epgFile.Name + " : " + p.Channel;
p.ChannelName = p.Channel;
p.Name = p.Channel;
}
}
else
{
p.DisplayName = epgFile.Name + " : " + p.Channel;
p.ChannelName = p.Channel;
p.Name = p.Channel;
}

p.EPGFileId = epgFile.Id;
Expand Down
Loading

0 comments on commit d9b464e

Please sign in to comment.