Compare commits
21 Commits
dev/multip
...
master
Author | SHA1 | Date | |
---|---|---|---|
e5cb210df2 | |||
aa3accb412 | |||
|
e20e8d907f | ||
|
fe56bd903d | ||
6563838738 | |||
6f5413ce95 | |||
|
9309b7012e | ||
|
c38e4cd8bf | ||
|
b5a4ce68a5 | ||
|
66111b81fe | ||
|
be95f53647 | ||
|
3eaa5c1910 | ||
|
ca8344cbb2 | ||
|
3dbc7050de | ||
c307de995d | |||
|
2acec128e8 | ||
|
ca48d79f55 | ||
3a91b6db3c | |||
38287093b4 | |||
|
2e4903481c | ||
|
70b0d0cba3 |
12
.config/dotnet-tools.json
Normal file
12
.config/dotnet-tools.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "8.0.0",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -229,6 +229,9 @@ _pkginfo.txt
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# exclude notes
|
||||
notes/*
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
|
@ -8,12 +8,9 @@ namespace BinaryDad.Notes.Controllers
|
||||
{
|
||||
private readonly INoteService noteService;
|
||||
|
||||
public ApiController(INoteService noteService)
|
||||
{
|
||||
this.noteService = noteService;
|
||||
}
|
||||
public ApiController(INoteService noteService) => this.noteService = noteService;
|
||||
|
||||
[Route("note/{noteName}")]
|
||||
public string Note(string noteName) => noteService.GetText(noteName);
|
||||
public string Note(string noteName) => noteService.GetNote(noteName);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,13 @@ namespace BinaryDad.Notes.Controllers
|
||||
{
|
||||
public class LoginController : Controller
|
||||
{
|
||||
private readonly IConfiguration configuration;
|
||||
|
||||
public LoginController(IConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
[Route("login")]
|
||||
public IActionResult Login()
|
||||
{
|
||||
@ -21,7 +28,7 @@ namespace BinaryDad.Notes.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var appPassphrase = Environment.GetEnvironmentVariable("APP_PASSPHRASE");
|
||||
var appPassphrase = configuration["APP_PASSPHRASE"];
|
||||
|
||||
if (passphrase == appPassphrase)
|
||||
{
|
||||
|
@ -10,10 +10,7 @@ public class NoteController : Controller
|
||||
{
|
||||
private readonly INoteService noteService;
|
||||
|
||||
public NoteController(INoteService noteService)
|
||||
{
|
||||
this.noteService = noteService;
|
||||
}
|
||||
public NoteController(INoteService noteService) => this.noteService = noteService;
|
||||
|
||||
[Route("{noteName=default}")]
|
||||
public IActionResult Index(string noteName)
|
||||
@ -21,7 +18,7 @@ public class NoteController : Controller
|
||||
var model = new ContentModel
|
||||
{
|
||||
CurrentNote = noteName,
|
||||
Text = noteService.GetText(noteName),
|
||||
Text = noteService.GetNote(noteName),
|
||||
NoteNames = noteService.GetNoteNames()
|
||||
};
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
|
||||
RUN dotnet publish "BinaryDad.Notes.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
|
||||
WORKDIR /app
|
||||
RUN mkdir notes
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
EXPOSE 80
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT ["dotnet", "BinaryDad.Notes.dll"]
|
@ -1,8 +1,10 @@
|
||||
using BinaryDad.Notes.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace BinaryDad.Notes
|
||||
{
|
||||
[Authorize]
|
||||
public class NoteHub : Hub
|
||||
{
|
||||
private readonly INoteService noteService;
|
||||
@ -21,9 +23,9 @@ namespace BinaryDad.Notes
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
public async Task SaveNote(string content, string? noteName)
|
||||
public async Task SaveNote(string content, string noteName)
|
||||
{
|
||||
noteService.SaveText(content, noteName);
|
||||
noteService.SaveNote(content, noteName);
|
||||
|
||||
// find all other connections except for the current one
|
||||
var clientConnections = NoteContext.ClientNotes
|
||||
|
@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Configuration.AddEnvironmentVariables();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddSignalR();
|
||||
@ -14,6 +16,7 @@ builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSc
|
||||
o.LoginPath = "/login";
|
||||
o.Cookie.Name = "NotesUser";
|
||||
o.Cookie.MaxAge = TimeSpan.FromDays(3);
|
||||
o.SlidingExpiration = true;
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
@ -14,7 +14,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<SiteUrlToLaunchAfterPublish />
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<ProjectGuid>bf137709-fcd2-4bb0-ade0-8fc71a244485</ProjectGuid>
|
||||
<SelfContained>false</SelfContained>
|
||||
|
@ -16,7 +16,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
public string GetText(string noteName)
|
||||
public string GetNote(string noteName)
|
||||
{
|
||||
CheckFile(noteName);
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void SaveText(string content, string noteName)
|
||||
public void SaveNote(string content, string noteName)
|
||||
{
|
||||
File.WriteAllText(GetFilePath(noteName), content);
|
||||
}
|
||||
@ -51,7 +51,7 @@
|
||||
{
|
||||
Directory.CreateDirectory(folderPath);
|
||||
|
||||
SaveText("Hi! Feel free to start typing. Everything will be saved soon after you are done typing.", noteName);
|
||||
SaveNote("Hi! Feel free to start typing. Everything will be saved soon after you are done typing.", noteName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
public interface INoteService
|
||||
{
|
||||
ICollection<string> GetNoteNames();
|
||||
string GetText(string noteName);
|
||||
void SaveText(string content, string noteName);
|
||||
string GetNote(string noteName);
|
||||
void SaveNote(string content, string noteName);
|
||||
void DeleteNote(string noteName);
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,7 @@
|
||||
<script>
|
||||
var noteName = '@Model.CurrentNote';
|
||||
</script>
|
||||
|
||||
<script src="~/lib/signalr/dist/browser/signalr.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
}
|
||||
|
@ -11,11 +11,9 @@
|
||||
<body>
|
||||
@RenderBody()
|
||||
|
||||
@RenderSection("scripts", false)
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/signalr/dist/browser/signalr.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
@RenderSection("scripts", false)
|
||||
|
||||
</body>
|
||||
|
||||
|
7
docker.sh
Executable file
7
docker.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#! /bin/bash
|
||||
|
||||
# build the image
|
||||
sudo docker build -f ./Dockerfile . -t docker.io/binarydad/notes:latest
|
||||
|
||||
# push the image
|
||||
sudo docker push docker.io/binarydad/notes:latest
|
@ -9,7 +9,7 @@ function start() {
|
||||
console.log('Started websocket listener');
|
||||
}).catch(function (err) {
|
||||
console.error(err.toString());
|
||||
return alert('Connection error. Reload page.');
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user