diff --git a/.env.sample b/.env.sample index b0118127..37048155 100644 --- a/.env.sample +++ b/.env.sample @@ -12,6 +12,7 @@ MODERATION_AUTO_APPROVE_THRESHOLD=0.7 # Limite par appel ANTHROPIC_MAX_TOKENS=256 # la modération n'a pas besoin de plus -# Choisis le bon modèle selon l'usage -# - Modération : claude-haiku-4-5 (rapide, pas cher) -# - Aide rédaction devis : claude-sonnet-4-6 (meilleur équilibre) +YAVSC_API_HOST=127.0.0.1 +YAVSC_API_PORT=6001 + +ASPNETCORE_Kestrel__Endpoints__Https__Url="https://$YAVSC_API_HOST:$YAVSC_API_PORT" diff --git a/.gitignore b/.gitignore index 8e16d9bd..c51fd390 100644 --- a/.gitignore +++ b/.gitignore @@ -47,11 +47,9 @@ generated/ *.Development.json *.log - **/AppDataDevelopment/ binaries/ build/ src/*/Blog-Dev/ *.mp4 src/Yavsc.Org/data/ - diff --git a/.vscode/settings.json b/.vscode/settings.json index e7ffe374..bbc45967 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,10 +4,17 @@ "cSpell.words": [ "appsettings", "asciidoctor", + "ASPNETCORE", "Cratie", "DESTDIR", + "dotnet", + "DOTNET", + "envsubst", "Newtonsoft", "Npgsql", + "SLNDIR", + "www-data", + "yavsc", "Yavsc" ], "cSpell.dictionaries": [ diff --git a/contrib/Makefile b/contrib/Makefile index 9eadc6f1..dfa0e8ed 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -1,36 +1,80 @@ -APP_PROJECTS=src/Org/Org.csproj src/Api/Api.csproj +APP_PROJECT_NAMES=Api Org Blogs +APP_PROJECTS=src/Yavsc.Org/Yavsc.Org.csproj src/Yavsc.Api/Yavsc.Api.csproj SLNDIR=.. +DESTDIR=/srv/www/yavsc/ +USER_AND_GROUP=www-data:www-data +CONFIGURATION=Release +DOTNET_FRAMEWORK=net10.0 -generated/%.service: template.service %.env .env - envsubst < template.service > $@ +include $(SLNDIR)/.env -copy-service-Org: $(DESTDIR)/etc/systemd/system/Org.service +generated/: + @mkdir -p $@ -$(DESTDIR)/etc/systemd/system/%.service: generated/%.service +generated/Api.service: +generated/Org.service: +generated/Blogs.service: + +generated/yavsc%.service: generated/ template.service $(SLNDIR)/.env + @cat template.service | APP_NAME="$*" \ + DESTDIR="$(DESTDIR)" \ + APP_SYSLOG_ID="yavsc$*" \ + POSTGRES_HOST="$(POSTGRES_HOST)" \ + POSTGRES_PORT="$(POSTGRES_PORT)" \ + POSTGRES_DB="$(POSTGRES_DB)" \ + POSTGRES_USER="$(POSTGRES_USER)" \ + POSTGRES_PASSWORD="$(POSTGRES_PASSWORD)" \ + ANTHROPIC_API_KEY="$(ANTHROPIC_API_KEY)" \ + ANTHROPIC_MAX_TOKENS="$(ANTHROPIC_MAX_TOKENS)" \ + envsubst > $@ + @echo Created service file: $@ + + +copy-services: copy-service-Org copy-service-Api copy-service-Blogs +copy-service-Org: /etc/systemd/system/yavscOrg.service +copy-service-Api: /etc/systemd/system/yavscApi.service +copy-service-Blogs: /etc/systemd/system/yavscBlogs.service + +copy-binaries: + for project in $(APP_PROJECT_NAMES); \ + do \ + sudo cp -a $(SLNDIR)/src/Yavsc.$${project}/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish/* $(DESTDIR) ; \ + done + sudo chown -R $(USER_AND_GROUP) $(DESTDIR) + +/etc/systemd/system/yavsc%.service: generated/yavsc%.service sudo cp $^ $@ + sudo chown root:root $@ sudo systemctl daemon-reload - + build_publish: for f in $(APP_PROJECTS); do \ ASPNETCORE_ENV=$(CONFIGURATION) dotnet publish $(SLNDIR)/$$f ; \ done -rmep: build_publish - sudo systemctl stop yavsc-api - sudo systemctl stop yavsc-org - for f in Api Org; do - pushd $(SLNDIR)/src/$$prj - SOURCE_DIR=bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish/ - sudo cp -a $(SOURCE_DIR)/* $(DESTDIR) - sudo chown -R $(USER_AND_GROUP) $(DESTDIR) - popd +install: build_publish copy-services copy-binaries + sudo systemctl daemon-reload + for project in $(APP_PROJECT_NAMES); \ + do \ + sudo systemctl enable yavsc$${project} ; \ + sudo systemctl start yavsc$${project} ; \ + done + +reinstall: build_publish copy-services copy-binaries + for project in $(APP_PROJECT_NAMES); \ + do \ + sudo systemctl stop yavsc$${project} ; \ + done + for project in $(APP_PROJECT_NAMES); \ + do \ + sudo systemctl start yavsc$${project} ; \ done - sudo sync - sudo systemctl start yavsc-org - sudo systemctl start yavsc-api showConfig: @echo CONFIGURATION: $(CONFIGURATION) @echo DESTDIR: $(DESTDIR) -reinstall: copy-service-Org copy-service-Api rmep +clean: + rm -rf generated + +.PHONY: build_publish mep showConfig copy-service-Api copy-service-Org copy-service-Blogs reinstall clean diff --git a/contrib/template.service b/contrib/template.service index 75b458bc..d55f7a00 100644 --- a/contrib/template.service +++ b/contrib/template.service @@ -12,16 +12,18 @@ Type=simple User=www-data Group=www-data WorkingDirectory=$DESTDIR -ExecStart=$DESTDIR/$APP_NAME +ExecStart=$DESTDIR/Yavsc.$APP_NAME Restart=always Environment="HOME=$DESTDIR" Environment="ASPNETCORE_ENVIRONMENT=Production" -Environment="ASPNETCORE_ConnectionStrings__YavscConnection=Server=$YAVSC_CONNECTION_HOST;Port=$YAVSC_CONNECTION_PORT;Database=$YAVSC_CONNECTION_DATABASE;Username=$YAVSC_CONNECTION_USERNAME;Password=$YAVSC_CONNECTION_PASSWORD;" +Environment="ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY" +Environment="ANTHROPIC_MAX_TOKENS=$ANTHROPIC_MAX_TOKENS" +Environment="ASPNETCORE_ConnectionStrings__YavscConnection=Server=$POSTGRES_HOST;Port=$POSTGRES_PORT;Database=$POSTGRES_DB;Username=$POSTGRES_USER;Password=$POSTGRES_PASSWORD;" CapabilityBoundingSet=CAP_NET_BIND_SERVICE AmbientCapabilities=CAP_NET_BIND_SERVICE StandardOutput=syslog StandardError=syslog -SyslogIdentifier=$APP_NAME +SyslogIdentifier=$APP_SYSLOG_ID [Install] WantedBy=multi-user.target diff --git a/src/Api/Controllers/Business/ActivityApiController.cs b/src/Yavsc.Api/Controllers/Business/ActivityApiController.cs similarity index 100% rename from src/Api/Controllers/Business/ActivityApiController.cs rename to src/Yavsc.Api/Controllers/Business/ActivityApiController.cs diff --git a/src/Api/Controllers/Business/BillingController.cs b/src/Yavsc.Api/Controllers/Business/BillingController.cs similarity index 100% rename from src/Api/Controllers/Business/BillingController.cs rename to src/Yavsc.Api/Controllers/Business/BillingController.cs diff --git a/src/Api/Controllers/Business/BookQueryApiController.cs b/src/Yavsc.Api/Controllers/Business/BookQueryApiController.cs similarity index 100% rename from src/Api/Controllers/Business/BookQueryApiController.cs rename to src/Yavsc.Api/Controllers/Business/BookQueryApiController.cs diff --git a/src/Api/Controllers/Business/EstimateApiController.cs b/src/Yavsc.Api/Controllers/Business/EstimateApiController.cs similarity index 100% rename from src/Api/Controllers/Business/EstimateApiController.cs rename to src/Yavsc.Api/Controllers/Business/EstimateApiController.cs diff --git a/src/Api/Controllers/Business/EstimateTemplatesApiController.cs b/src/Yavsc.Api/Controllers/Business/EstimateTemplatesApiController.cs similarity index 100% rename from src/Api/Controllers/Business/EstimateTemplatesApiController.cs rename to src/Yavsc.Api/Controllers/Business/EstimateTemplatesApiController.cs diff --git a/src/Api/Controllers/Business/FrontOfficeApiController.cs b/src/Yavsc.Api/Controllers/Business/FrontOfficeApiController.cs similarity index 100% rename from src/Api/Controllers/Business/FrontOfficeApiController.cs rename to src/Yavsc.Api/Controllers/Business/FrontOfficeApiController.cs diff --git a/src/Api/Controllers/Business/HyperLinkController.cs b/src/Yavsc.Api/Controllers/Business/HyperLinkController.cs similarity index 100% rename from src/Api/Controllers/Business/HyperLinkController.cs rename to src/Yavsc.Api/Controllers/Business/HyperLinkController.cs diff --git a/src/Api/Controllers/Business/PaymentApiController.cs b/src/Yavsc.Api/Controllers/Business/PaymentApiController.cs similarity index 100% rename from src/Api/Controllers/Business/PaymentApiController.cs rename to src/Yavsc.Api/Controllers/Business/PaymentApiController.cs diff --git a/src/Api/Controllers/Business/PerformersApiController.cs b/src/Yavsc.Api/Controllers/Business/PerformersApiController.cs similarity index 100% rename from src/Api/Controllers/Business/PerformersApiController.cs rename to src/Yavsc.Api/Controllers/Business/PerformersApiController.cs diff --git a/src/Api/Controllers/Business/ProductApiController.cs b/src/Yavsc.Api/Controllers/Business/ProductApiController.cs similarity index 100% rename from src/Api/Controllers/Business/ProductApiController.cs rename to src/Yavsc.Api/Controllers/Business/ProductApiController.cs diff --git a/src/Api/Controllers/HairCut/BursherProfilesApiController.cs b/src/Yavsc.Api/Controllers/HairCut/BursherProfilesApiController.cs similarity index 100% rename from src/Api/Controllers/HairCut/BursherProfilesApiController.cs rename to src/Yavsc.Api/Controllers/HairCut/BursherProfilesApiController.cs diff --git a/src/Api/Controllers/HairCut/HairCutController.cs b/src/Yavsc.Api/Controllers/HairCut/HairCutController.cs similarity index 100% rename from src/Api/Controllers/HairCut/HairCutController.cs rename to src/Yavsc.Api/Controllers/HairCut/HairCutController.cs diff --git a/src/Api/Controllers/HyperLinkApiController.cs b/src/Yavsc.Api/Controllers/HyperLinkApiController.cs similarity index 100% rename from src/Api/Controllers/HyperLinkApiController.cs rename to src/Yavsc.Api/Controllers/HyperLinkApiController.cs diff --git a/src/Api/Controllers/IT/GitRefsApiController.cs b/src/Yavsc.Api/Controllers/IT/GitRefsApiController.cs similarity index 100% rename from src/Api/Controllers/IT/GitRefsApiController.cs rename to src/Yavsc.Api/Controllers/IT/GitRefsApiController.cs diff --git a/src/Api/Controllers/MailTemplatingApiController.cs b/src/Yavsc.Api/Controllers/MailTemplatingApiController.cs similarity index 100% rename from src/Api/Controllers/MailTemplatingApiController.cs rename to src/Yavsc.Api/Controllers/MailTemplatingApiController.cs diff --git a/src/Api/Controllers/MailingTemplateApiController.cs b/src/Yavsc.Api/Controllers/MailingTemplateApiController.cs similarity index 100% rename from src/Api/Controllers/MailingTemplateApiController.cs rename to src/Yavsc.Api/Controllers/MailingTemplateApiController.cs diff --git a/src/Api/Controllers/Musical/DjProfileApiController.cs b/src/Yavsc.Api/Controllers/Musical/DjProfileApiController.cs similarity index 100% rename from src/Api/Controllers/Musical/DjProfileApiController.cs rename to src/Yavsc.Api/Controllers/Musical/DjProfileApiController.cs diff --git a/src/Api/Controllers/Musical/MusicalPreferencesApiController.cs b/src/Yavsc.Api/Controllers/Musical/MusicalPreferencesApiController.cs similarity index 100% rename from src/Api/Controllers/Musical/MusicalPreferencesApiController.cs rename to src/Yavsc.Api/Controllers/Musical/MusicalPreferencesApiController.cs diff --git a/src/Api/Controllers/Musical/MusicalTendenciesApiController.cs b/src/Yavsc.Api/Controllers/Musical/MusicalTendenciesApiController.cs similarity index 100% rename from src/Api/Controllers/Musical/MusicalTendenciesApiController.cs rename to src/Yavsc.Api/Controllers/Musical/MusicalTendenciesApiController.cs diff --git a/src/Api/Controllers/Musical/PodcastController.cs b/src/Yavsc.Api/Controllers/Musical/PodcastController.cs similarity index 100% rename from src/Api/Controllers/Musical/PodcastController.cs rename to src/Yavsc.Api/Controllers/Musical/PodcastController.cs diff --git a/src/Api/Controllers/NativeConfidentialController.cs b/src/Yavsc.Api/Controllers/NativeConfidentialController.cs similarity index 100% rename from src/Api/Controllers/NativeConfidentialController.cs rename to src/Yavsc.Api/Controllers/NativeConfidentialController.cs diff --git a/src/Api/Controllers/PostRateApiController.cs b/src/Yavsc.Api/Controllers/PostRateApiController.cs similarity index 100% rename from src/Api/Controllers/PostRateApiController.cs rename to src/Yavsc.Api/Controllers/PostRateApiController.cs diff --git a/src/Api/Controllers/ProfileApiController.cs b/src/Yavsc.Api/Controllers/ProfileApiController.cs similarity index 100% rename from src/Api/Controllers/ProfileApiController.cs rename to src/Yavsc.Api/Controllers/ProfileApiController.cs diff --git a/src/Api/Controllers/Relationship/BlackListApiController.cs b/src/Yavsc.Api/Controllers/Relationship/BlackListApiController.cs similarity index 100% rename from src/Api/Controllers/Relationship/BlackListApiController.cs rename to src/Yavsc.Api/Controllers/Relationship/BlackListApiController.cs diff --git a/src/Api/Controllers/Relationship/BlogAclApiController.cs b/src/Yavsc.Api/Controllers/Relationship/BlogAclApiController.cs similarity index 100% rename from src/Api/Controllers/Relationship/BlogAclApiController.cs rename to src/Yavsc.Api/Controllers/Relationship/BlogAclApiController.cs diff --git a/src/Api/Controllers/Relationship/ChatApiController.cs b/src/Yavsc.Api/Controllers/Relationship/ChatApiController.cs similarity index 100% rename from src/Api/Controllers/Relationship/ChatApiController.cs rename to src/Yavsc.Api/Controllers/Relationship/ChatApiController.cs diff --git a/src/Api/Controllers/Relationship/ChatRoomAccessApiController.cs b/src/Yavsc.Api/Controllers/Relationship/ChatRoomAccessApiController.cs similarity index 100% rename from src/Api/Controllers/Relationship/ChatRoomAccessApiController.cs rename to src/Yavsc.Api/Controllers/Relationship/ChatRoomAccessApiController.cs diff --git a/src/Api/Controllers/Relationship/ChatRoomApiController.cs b/src/Yavsc.Api/Controllers/Relationship/ChatRoomApiController.cs similarity index 100% rename from src/Api/Controllers/Relationship/ChatRoomApiController.cs rename to src/Yavsc.Api/Controllers/Relationship/ChatRoomApiController.cs diff --git a/src/Api/Controllers/Relationship/CircleApiController.cs b/src/Yavsc.Api/Controllers/Relationship/CircleApiController.cs similarity index 100% rename from src/Api/Controllers/Relationship/CircleApiController.cs rename to src/Yavsc.Api/Controllers/Relationship/CircleApiController.cs diff --git a/src/Api/Controllers/Relationship/ContactsApiController.cs b/src/Yavsc.Api/Controllers/Relationship/ContactsApiController.cs similarity index 100% rename from src/Api/Controllers/Relationship/ContactsApiController.cs rename to src/Yavsc.Api/Controllers/Relationship/ContactsApiController.cs diff --git a/src/Api/Controllers/ServiceApiController.cs b/src/Yavsc.Api/Controllers/ServiceApiController.cs similarity index 100% rename from src/Api/Controllers/ServiceApiController.cs rename to src/Yavsc.Api/Controllers/ServiceApiController.cs diff --git a/src/Api/Controllers/Survey/BugApiController.cs b/src/Yavsc.Api/Controllers/Survey/BugApiController.cs similarity index 100% rename from src/Api/Controllers/Survey/BugApiController.cs rename to src/Yavsc.Api/Controllers/Survey/BugApiController.cs diff --git a/src/Api/Controllers/accounting/AccountController.cs b/src/Yavsc.Api/Controllers/accounting/AccountController.cs similarity index 100% rename from src/Api/Controllers/accounting/AccountController.cs rename to src/Yavsc.Api/Controllers/accounting/AccountController.cs diff --git a/src/Api/Controllers/accounting/ApplicationUserApiController.cs b/src/Yavsc.Api/Controllers/accounting/ApplicationUserApiController.cs similarity index 100% rename from src/Api/Controllers/accounting/ApplicationUserApiController.cs rename to src/Yavsc.Api/Controllers/accounting/ApplicationUserApiController.cs diff --git a/src/Api/Controllers/accounting/ProfileApiController.cs b/src/Yavsc.Api/Controllers/accounting/ProfileApiController.cs similarity index 100% rename from src/Api/Controllers/accounting/ProfileApiController.cs rename to src/Yavsc.Api/Controllers/accounting/ProfileApiController.cs diff --git a/src/Api/Helpers/RequestHelpers.cs b/src/Yavsc.Api/Helpers/RequestHelpers.cs similarity index 100% rename from src/Api/Helpers/RequestHelpers.cs rename to src/Yavsc.Api/Helpers/RequestHelpers.cs diff --git a/src/Api/Program.cs b/src/Yavsc.Api/Program.cs similarity index 86% rename from src/Api/Program.cs rename to src/Yavsc.Api/Program.cs index 9b47aa6b..8f085a7c 100644 --- a/src/Api/Program.cs +++ b/src/Yavsc.Api/Program.cs @@ -10,10 +10,12 @@ copies or substantial portions of the Software. */ +using Anthropic.SDK; using IdentityModel; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Yavsc; +using Yavsc.Abstract.Interfaces; using Yavsc.Helpers; using Yavsc.Interface; using Yavsc.Models; @@ -28,7 +30,23 @@ internal class Program var builder = WebApplication.CreateBuilder(args); var services = builder.Services; - // builder.Services.AddDistributedMemoryCache(); + + // Anthropic client + builder.Services.AddSingleton(_ => + new AnthropicClient( + new APIAuthentication( + builder.Configuration["ANTHROPIC_API_KEY"] + ?? throw new InvalidOperationException("ANTHROPIC_API_KEY manquante") + ) + ) + ); + + // Service de modération + if (builder.Environment.IsDevelopment()) + builder.Services.AddScoped(); + else + builder.Services.AddScoped(); + // accepts any access token issued by identity server // adds an authorization policy for scope 'scope1' diff --git a/src/Api/Properties/launchSettings.json b/src/Yavsc.Api/Properties/launchSettings.json similarity index 100% rename from src/Api/Properties/launchSettings.json rename to src/Yavsc.Api/Properties/launchSettings.json diff --git a/src/Api/Api.csproj b/src/Yavsc.Api/Yavsc.Api.csproj similarity index 97% rename from src/Api/Api.csproj rename to src/Yavsc.Api/Yavsc.Api.csproj index 580b110f..f4ef5509 100644 --- a/src/Api/Api.csproj +++ b/src/Yavsc.Api/Yavsc.Api.csproj @@ -10,4 +10,4 @@ - \ No newline at end of file + diff --git a/src/Api/appsettings.json b/src/Yavsc.Api/appsettings.json similarity index 100% rename from src/Api/appsettings.json rename to src/Yavsc.Api/appsettings.json diff --git a/src/Api/tempkey.jwk b/src/Yavsc.Api/tempkey.jwk similarity index 100% rename from src/Api/tempkey.jwk rename to src/Yavsc.Api/tempkey.jwk diff --git a/src/Yavsc.Org/Program.cs b/src/Yavsc.Org/Program.cs index 0fa46dae..700221d4 100644 --- a/src/Yavsc.Org/Program.cs +++ b/src/Yavsc.Org/Program.cs @@ -10,22 +10,6 @@ namespace Yavsc { var builder = WebApplication.CreateBuilder(args); - // Anthropic client - builder.Services.AddSingleton(_ => - new AnthropicClient( - new APIAuthentication( - builder.Configuration["ANTHROPIC_API_KEY"] - ?? throw new InvalidOperationException("ANTHROPIC_API_KEY manquante") - ) - ) - ); - - // Service de modération - if (builder.Environment.IsDevelopment()) - builder.Services.AddScoped(); - else - builder.Services.AddScoped(); - var app = await builder .ConfigureWebAppServices() .ConfigurePipeline(); diff --git a/yavsc.sln b/yavsc.sln index 92489940..cd6de416 100644 --- a/yavsc.sln +++ b/yavsc.sln @@ -13,7 +13,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Org", "src\Yavsc.Org\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Web", "src\Yavsc.Web\Yavsc.Web.csproj", "{1F594222-C5CB-4D4A-94A1-C5AEB4990B59}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "src\Api\Api.csproj", "{95DAD2B5-4324-4E89-A337-5703E45CFBE8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Api", "src\Yavsc.Api\Yavsc.Api.csproj", "{95DAD2B5-4324-4E89-A337-5703E45CFBE8}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cli", "src\cli\cli.csproj", "{27DA6CEC-4266-4F78-BB32-8388F9A401D0}" EndProject