mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-13 19:52:46 +00:00
Compare commits
8 Commits
v1.0-alpha
...
v1.0-alpha
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
881354ab83 | ||
|
|
5c1944d29f | ||
|
|
cbd0c01d28 | ||
|
|
ad590f6011 | ||
|
|
2f5bd75d4e | ||
|
|
3c8c8ebc81 | ||
|
|
2bbb50e9f6 | ||
|
|
d0a1a2ea9f |
@@ -32,6 +32,7 @@ RUN dotnet publish -c Release -o /app/publish \
|
||||
/p:TrimMode=partial \
|
||||
/p:PublishTrimmed=true \
|
||||
/p:PublishSingleFile=true \
|
||||
/p:JsonSerializerIsReflectionEnabledByDefault=true \
|
||||
-a $TARGETARCH
|
||||
|
||||
FROM --platform=$BUILDPLATFORM base AS final
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace Notesnook.API
|
||||
app.UseResponseCompression();
|
||||
|
||||
app.UseCors("notesnook");
|
||||
app.UseVersion();
|
||||
app.UseVersion(Servers.NotesnookAPI);
|
||||
|
||||
app.UseWamp(WampServers.NotesnookServer, (realm, server) =>
|
||||
{
|
||||
|
||||
13
README.md
13
README.md
@@ -8,7 +8,7 @@ This repo contains the full source code of the Notesnook Sync Server licensed un
|
||||
|
||||
Requirements:
|
||||
|
||||
1. [.NET 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
||||
1. [.NET 8](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
|
||||
2. [git](https://git-scm.com/downloads)
|
||||
|
||||
The first step is to `clone` the repository:
|
||||
@@ -55,19 +55,14 @@ dotnet run --project Streetwriters.Identity/Streetwriters.Identity.csproj
|
||||
|
||||
The sync server can easily be started using Docker.
|
||||
|
||||
The first step is to `clone` the repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/streetwriters/notesnook-sync-server.git
|
||||
|
||||
# change directory
|
||||
cd notesnook-sync-server
|
||||
wget https://raw.githubusercontent.com/streetwriters/notesnook-sync-server/master/docker-compose.yml
|
||||
```
|
||||
|
||||
And then use Docker Compose to start the servers:
|
||||
|
||||
```bash
|
||||
docker-compose up
|
||||
docker compose up
|
||||
```
|
||||
|
||||
This takes care of setting up everything including MongoDB, Minio etc.
|
||||
@@ -81,7 +76,7 @@ This takes care of setting up everything including MongoDB, Minio etc.
|
||||
- [x] Open source the SSE Messaging infrastructure
|
||||
- [x] Fully Dockerize all services
|
||||
- [x] Use self-hosted Minio for S3 storage
|
||||
- [ ] Publish on DockerHub
|
||||
- [x] Publish on DockerHub
|
||||
- [ ] Write self hosting docs
|
||||
- [ ] Add settings to change server URLs in Notesnook client apps
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Streetwriters.Common
|
||||
public class Constants
|
||||
{
|
||||
public static bool IS_SELF_HOSTED => Environment.GetEnvironmentVariable("SELF_HOSTED") == "1";
|
||||
public static bool DISABLE_ACCOUNT_CREATION => Environment.GetEnvironmentVariable("DISABLE_ACCOUNT_CREATION") == "1";
|
||||
public static string INSTANCE_NAME => Environment.GetEnvironmentVariable("INSTANCE_NAME") ?? "default";
|
||||
|
||||
// S3 related
|
||||
public static string S3_ACCESS_KEY => Environment.GetEnvironmentVariable("S3_ACCESS_KEY");
|
||||
|
||||
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -30,13 +32,20 @@ namespace Streetwriters.Common.Extensions
|
||||
{
|
||||
public static class AppBuilderExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseVersion(this IApplicationBuilder app)
|
||||
public static IApplicationBuilder UseVersion(this IApplicationBuilder app, Server server)
|
||||
{
|
||||
app.Map("/version", (app) =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
await context.Response.WriteAsync(Version.AsString());
|
||||
context.Response.ContentType = "application/json";
|
||||
var data = new Dictionary<string, string>
|
||||
{
|
||||
{ "version", Version.AsString() },
|
||||
{ "id", server.Id },
|
||||
{ "instance", Constants.INSTANCE_NAME }
|
||||
};
|
||||
await context.Response.WriteAsync(JsonSerializer.Serialize(data));
|
||||
});
|
||||
});
|
||||
return app;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Streetwriters.Common
|
||||
if (!string.IsNullOrEmpty(originCertPath) && !string.IsNullOrEmpty(originCertKeyPath))
|
||||
this.SSLCertificate = X509Certificate2.CreateFromPemFile(originCertPath, originCertKeyPath);
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Hostname { get; set; }
|
||||
public string Domain { get; set; }
|
||||
@@ -95,6 +95,7 @@ namespace Streetwriters.Common
|
||||
Domain = Constants.NOTESNOOK_SERVER_DOMAIN,
|
||||
Port = Constants.NOTESNOOK_SERVER_PORT,
|
||||
Hostname = Constants.NOTESNOOK_SERVER_HOST,
|
||||
Id = "notesnook-sync"
|
||||
};
|
||||
|
||||
public static Server MessengerServer { get; } = new(Constants.SSE_CERT_PATH, Constants.SSE_CERT_KEY_PATH)
|
||||
@@ -102,6 +103,7 @@ namespace Streetwriters.Common
|
||||
Domain = Constants.SSE_SERVER_DOMAIN,
|
||||
Port = Constants.SSE_SERVER_PORT,
|
||||
Hostname = Constants.SSE_SERVER_HOST,
|
||||
Id = "sse"
|
||||
};
|
||||
|
||||
public static Server IdentityServer { get; } = new(Constants.IDENTITY_CERT_PATH, Constants.IDENTITY_CERT_KEY_PATH)
|
||||
@@ -109,6 +111,7 @@ namespace Streetwriters.Common
|
||||
Domain = Constants.IDENTITY_SERVER_DOMAIN,
|
||||
Port = Constants.IDENTITY_SERVER_PORT,
|
||||
Hostname = Constants.IDENTITY_SERVER_HOST,
|
||||
Id = "auth"
|
||||
};
|
||||
|
||||
public static Server SubscriptionServer { get; } = new(Constants.SUBSCRIPTIONS_CERT_PATH, Constants.SUBSCRIPTIONS_CERT_KEY_PATH)
|
||||
@@ -116,6 +119,7 @@ namespace Streetwriters.Common
|
||||
Domain = Constants.SUBSCRIPTIONS_SERVER_DOMAIN,
|
||||
Port = Constants.SUBSCRIPTIONS_SERVER_PORT,
|
||||
Hostname = Constants.SUBSCRIPTIONS_SERVER_HOST,
|
||||
Id = "subscription"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace Streetwriters.Common
|
||||
{
|
||||
public class Version
|
||||
{
|
||||
public const int MAJOR = 2;
|
||||
public const int MINOR = 3;
|
||||
public const int MAJOR = 1;
|
||||
public const int MINOR = 0;
|
||||
public const int PATCH = 0;
|
||||
public static string AsString()
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Streetwriters.Common;
|
||||
using Streetwriters.Common.Enums;
|
||||
using Streetwriters.Common.Models;
|
||||
using Streetwriters.Identity.Enums;
|
||||
using Streetwriters.Identity.Interfaces;
|
||||
@@ -52,6 +53,8 @@ namespace Streetwriters.Identity.Controllers
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> Signup([FromForm] SignupForm form)
|
||||
{
|
||||
if (Constants.DISABLE_ACCOUNT_CREATION)
|
||||
return BadRequest(new string[] { "Creating new accounts is not allowed." });
|
||||
try
|
||||
{
|
||||
var client = Clients.FindClientById(form.ClientId);
|
||||
@@ -68,7 +71,7 @@ namespace Streetwriters.Identity.Controllers
|
||||
var result = await UserManager.CreateAsync(new User
|
||||
{
|
||||
Email = form.Email,
|
||||
EmailConfirmed = false,
|
||||
EmailConfirmed = Constants.IS_SELF_HOSTED,
|
||||
UserName = form.Username ?? form.Email,
|
||||
}, form.Password);
|
||||
|
||||
@@ -101,15 +104,18 @@ namespace Streetwriters.Identity.Controllers
|
||||
if (result.Succeeded)
|
||||
{
|
||||
var user = await UserManager.FindByEmailAsync(form.Email);
|
||||
|
||||
await UserManager.AddToRoleAsync(user, client.Id);
|
||||
if (Constants.IS_SELF_HOSTED)
|
||||
{
|
||||
await UserManager.AddClaimAsync(user, UserService.SubscriptionTypeToClaim(client.Id, Common.Enums.SubscriptionType.PREMIUM));
|
||||
await UserManager.AddClaimAsync(user, new Claim("platform", PlatformFromUserAgent(base.HttpContext.Request.Headers.UserAgent)));
|
||||
|
||||
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
var callbackUrl = Url.TokenLink(user.Id.ToString(), code, client.Id, TokenType.CONFRIM_EMAIL, Request.Scheme);
|
||||
await EmailSender.SendConfirmationEmailAsync(user.Email, callbackUrl, client);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UserManager.AddClaimAsync(user, new Claim("platform", PlatformFromUserAgent(base.HttpContext.Request.Headers.UserAgent)));
|
||||
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
var callbackUrl = Url.TokenLink(user.Id.ToString(), code, client.Id, TokenType.CONFRIM_EMAIL, Request.Scheme);
|
||||
await EmailSender.SendConfirmationEmailAsync(user.Email, callbackUrl, client);
|
||||
}
|
||||
return Ok(new
|
||||
{
|
||||
userId = user.Id.ToString()
|
||||
|
||||
@@ -32,6 +32,7 @@ RUN dotnet publish -c Release -o /app/publish \
|
||||
/p:TrimMode=partial \
|
||||
/p:PublishTrimmed=true \
|
||||
/p:PublishSingleFile=true \
|
||||
/p:JsonSerializerIsReflectionEnabledByDefault=true \
|
||||
-a $TARGETARCH
|
||||
|
||||
FROM --platform=$BUILDPLATFORM base AS final
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace Streetwriters.Identity
|
||||
}
|
||||
|
||||
app.UseCors("notesnook");
|
||||
app.UseVersion();
|
||||
app.UseVersion(Servers.IdentityServer);
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ RUN dotnet publish -c Release -o /app/publish \
|
||||
/p:TrimMode=partial \
|
||||
/p:PublishTrimmed=true \
|
||||
/p:PublishSingleFile=true \
|
||||
/p:JsonSerializerIsReflectionEnabledByDefault=true \
|
||||
-a $TARGETARCH
|
||||
|
||||
FROM --platform=$BUILDPLATFORM base AS final
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Streetwriters.Messenger
|
||||
}
|
||||
|
||||
app.UseCors("notesnook");
|
||||
app.UseVersion();
|
||||
app.UseVersion(Servers.MessengerServer);
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
version: "3.4"
|
||||
|
||||
x-server-discovery: &server-discovery
|
||||
NOTESNOOK_SERVER_PORT: 80
|
||||
NOTESNOOK_SERVER_HOST: notesnook-server
|
||||
@@ -72,9 +70,7 @@ services:
|
||||
mc mb minio/$$S3_BUCKET_NAME -p
|
||||
|
||||
identity-server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Streetwriters.Identity/Dockerfile
|
||||
image: streetwriters/identity:latest
|
||||
ports:
|
||||
- "8264:80"
|
||||
networks:
|
||||
@@ -94,9 +90,7 @@ services:
|
||||
MONGODB_DATABASE_NAME: identity
|
||||
|
||||
notesnook-server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Notesnook.API/Dockerfile
|
||||
image: streetwriters/notesnook-sync:latest
|
||||
ports:
|
||||
- "5264:80"
|
||||
networks:
|
||||
@@ -114,7 +108,7 @@ services:
|
||||
start_period: 60s
|
||||
environment:
|
||||
<<: *server-discovery
|
||||
MONGODB_CONNECTION_STRING: mongodb://notesnook-db:27017/notesnook?replSet=rs0
|
||||
MONGODB_CONNECTION_STRING: mongodb://notesnook-db:27017/?replSet=rs0
|
||||
MONGODB_DATABASE_NAME: notesnook
|
||||
S3_INTERNAL_SERVICE_URL: "${S3_SERVICE_URL:-http://notesnook-s3:9000}"
|
||||
S3_ACCESS_KEY_ID: "${S3_ACCESS_KEY_ID:-${MINIO_ROOT_USER:-minioadmin}}"
|
||||
@@ -124,9 +118,7 @@ services:
|
||||
S3_BUCKET_NAME: "${S3_BUCKET_NAME}"
|
||||
|
||||
sse-server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Streetwriters.Messenger/Dockerfile
|
||||
image: streetwriters/sse:latest
|
||||
ports:
|
||||
- "7264:80"
|
||||
env_file: *env-files
|
||||
|
||||
Reference in New Issue
Block a user