Compare commits

33 Commits

Author SHA1 Message Date
11f468a5c1 increase font size 2025-06-19 14:10:50 +00:00
d24065471b fix default note creation 2025-01-10 13:51:16 +00:00
538ddeeb4f adjusted save note argument signature 2025-01-09 11:41:18 -05:00
9a5a082f6d lighter color for links 2025-01-07 14:10:30 +00:00
bf9e8c0c69 adjust styling on password login and button 2025-01-06 08:59:47 -05:00
f35c2e499c modify logging message 2024-12-16 16:24:27 -05:00
769eabd9e4 try catch and logging in hub 2024-12-16 16:10:17 -05:00
d21a0e176a add some logging to the hub 2024-12-16 15:36:47 -05:00
f69d19100d remove old deploy script 2024-12-16 15:36:39 -05:00
dabd5d6a50 Merge branch 'master' of https://git.binarydad.com/ryan/Notes 2024-12-16 15:22:05 -05:00
1efa4b04d0 add login button 2024-12-16 15:22:03 -05:00
255b62a3b3 dark by default 2024-12-16 15:05:25 -05:00
e5cb210df2 method renames 2024-05-07 21:43:09 -04:00
aa3accb412 use alpine image 2024-05-08 01:34:16 +00:00
e20e8d907f reload page is WS connection failure 2024-01-25 20:12:50 -05:00
fe56bd903d make non nullable 2024-01-25 20:11:39 -05:00
6563838738 Merge branch 'master' of https://git.binarydad.com/ryan/Notes 2024-01-15 21:24:32 -05:00
6f5413ce95 exclude notes folder in git 2024-01-15 21:24:29 -05:00
9309b7012e make a notes folder in dockerfile 2024-01-08 17:17:38 -05:00
c38e4cd8bf fix merge issue with scripts 2024-01-06 21:15:50 -05:00
b5a4ce68a5 Merge branch 'dev/multiple-notes' 2024-01-06 21:10:06 -05:00
66111b81fe change framework for publish 2024-01-03 13:13:15 -05:00
be95f53647 change default port from 80 to 8080 as default 2023-11-15 11:25:16 -05:00
3eaa5c1910 update dockerfile for .net 8 2023-11-15 11:07:03 -05:00
ca8344cbb2 Merge branch 'master' of https://git.binarydad.com/ryan/Notes 2023-11-15 11:03:31 -05:00
3dbc7050de updated to .net 8 2023-11-15 11:03:26 -05:00
c307de995d add docker.sh 2023-11-03 12:23:18 +00:00
2acec128e8 add authorize to notehub 2023-10-30 10:07:35 -04:00
ca48d79f55 move scripts to appropriate pages 2023-10-29 16:15:47 -04:00
3a91b6db3c add env check for config 2023-08-29 20:26:04 -04:00
38287093b4 use iconfiguration for app passphrase 2023-08-29 20:25:45 -04:00
2e4903481c use expression bodies 2023-07-28 14:52:53 -04:00
70b0d0cba3 force sliding expiration to be true 2023-07-28 14:46:06 -04:00
17 changed files with 115 additions and 70 deletions

12
.config/dotnet-tools.json Normal file
View File

@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "8.0.0",
"commands": [
"dotnet-ef"
]
}
}
}

3
.gitignore vendored
View File

@ -229,6 +229,9 @@ _pkginfo.txt
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# exclude notes
notes/*
# Others
ClientBin/
~$*

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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)
{

View File

@ -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()
};

View File

@ -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"]

View File

@ -1,15 +1,19 @@
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
namespace BinaryDad.Notes
{
[Authorize]
public class NoteHub : Hub
{
private readonly INoteService noteService;
private readonly ILogger<NoteHub> logger;
public NoteHub(INoteService noteService)
public NoteHub(INoteService noteService, ILogger<NoteHub> logger)
{
this.noteService = noteService;
this.logger = logger;
}
public override Task OnConnectedAsync()
@ -21,9 +25,11 @@ namespace BinaryDad.Notes
return base.OnConnectedAsync();
}
public async Task SaveNote(string content, string? noteName)
public async Task SaveNote(string noteName, string content)
{
noteService.SaveText(content, noteName);
try
{
noteService.SaveNote(noteName, content);
// find all other connections except for the current one
var clientConnections = NoteContext.ClientNotes
@ -35,6 +41,13 @@ namespace BinaryDad.Notes
await Clients
.Clients(clientConnections)
.SendAsync("updateNote", content);
logger.LogInformation($"Note \"{noteName}\" saved! Updated {clientConnections.Count} other client(s).");
}
catch (Exception ex)
{
logger.LogError($"Unable to save note \"{noteName}\" => {ex}");
}
}
}
}

View File

@ -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();

View File

@ -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>

View File

@ -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 noteName, string content)
{
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(noteName, "Hi! Feel free to start typing. Everything will be saved soon after you are done typing.");
}
}

View File

@ -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 noteName, string content);
void DeleteNote(string noteName);
}
}

View File

@ -2,6 +2,7 @@
<form method="post">
<input type="password" name="passphrase" placeholder="Passphrase" />
<button type="submit">Login</button>
</form>
@section scripts {

View File

@ -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>
}

View File

@ -8,14 +8,12 @@
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
</head>
<body>
<body class="dark">
@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>

View File

@ -28,19 +28,19 @@ div.note-names {
opacity: 0.5;
}
div.note-names a {
color: #666;
div.note-names a {
color: #aaa;
padding-left: 10px;
text-decoration: none;
}
}
div.note-names a.current {
div.note-names a.current {
font-weight: bold;
}
}
div .note-names a:not(:last-of-type) {
div .note-names a:not(:last-of-type) {
border-right: 1px solid #666;
}
}
textarea {
width: 100%;
@ -49,7 +49,7 @@ textarea {
margin: 0;
resize: none;
color: #444;
font-size: 12px;
font-size: 16px;
font-family: Consolas, 'Courier New', monospace;
outline: none;
position: absolute;
@ -57,7 +57,9 @@ textarea {
border-width: 0;
}
body.dark, body.dark input, body.dark textarea {
body.dark,
body.dark input,
body.dark textarea {
background-color: #222;
color: #ddd;
}
@ -74,24 +76,37 @@ body.dark, body.dark input, body.dark textarea {
border-radius: 5px 5px 0 0;
}
.toast.show {
.toast.show {
bottom: 0;
}
}
.toast#saved-indicator {
.toast#saved-indicator {
background-color: green;
}
}
.toast#update-indicator {
.toast#update-indicator {
background-color: orangered;
}
}
form input[type=password] {
form input[type=password],
button {
display: block;
width: 100%;
max-width: 300px;
margin: 20px auto;
font-size: 20px;
padding: 8px;
border: 1px solid #999;
border-radius: 4px;
border: 1px solid #333;
border-radius: 8px;
box-sizing: border-box;
}
form input[type=password] {
color: #999;
}
form button {
cursor: pointer;
color: #fff;
background-color: #009E60;
}

View File

@ -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();
});
}
@ -29,7 +29,7 @@ function saveContent($textarea) {
var content = $textarea.val();
connection.invoke('SaveNote', content, noteName).then(function () {
connection.invoke('SaveNote', noteName, content).then(function () {
showToast('#saved-indicator');
}).catch(function (err) {
console.error(err.toString());
@ -63,11 +63,6 @@ $(function () {
});
});
// set dark mode
if (window.location.hash == '#dark') {
$('body').addClass('dark');
}
let timer = null;
const ignoredKeyCodes = [17, 18, 20, 27, 37, 38, 39, 40, 91];