[backend] Add configurable post character limit (ISH-5)
This commit is contained in:
parent
547b385c29
commit
c8c09591f9
3 changed files with 17 additions and 6 deletions
|
@ -30,10 +30,11 @@ public sealed class Config {
|
|||
|
||||
public string UserAgent => $"Iceshrimp.NET/{Version} (https://{WebDomain})";
|
||||
|
||||
public required int ListenPort { get; init; } = 3000;
|
||||
public required string ListenHost { get; init; } = "localhost";
|
||||
public required string WebDomain { get; init; }
|
||||
public required string AccountDomain { get; init; }
|
||||
public required int ListenPort { get; init; } = 3000;
|
||||
public required string ListenHost { get; init; } = "localhost";
|
||||
public required string WebDomain { get; init; }
|
||||
public required string AccountDomain { get; init; }
|
||||
public required int CharacterLimit { get; init; } = 8192;
|
||||
}
|
||||
|
||||
public sealed class SecuritySection {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using Iceshrimp.Backend.Core.Configuration;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
|
@ -11,11 +12,13 @@ using Microsoft.Extensions.Options;
|
|||
|
||||
namespace Iceshrimp.Backend.Core.Services;
|
||||
|
||||
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor",
|
||||
Justification = "We need IOptionsSnapshot for config hot reload")]
|
||||
public class NoteService(
|
||||
ILogger<NoteService> logger,
|
||||
DatabaseContext db,
|
||||
UserResolver userResolver,
|
||||
IOptions<Config.InstanceSection> config,
|
||||
IOptionsSnapshot<Config.InstanceSection> config,
|
||||
UserService userSvc,
|
||||
ActivityFetcherService fetchSvc,
|
||||
ActivityDeliverService deliverSvc,
|
||||
|
@ -27,6 +30,9 @@ public class NoteService(
|
|||
|
||||
public async Task<Note> CreateNoteAsync(User user, Note.NoteVisibility visibility, string? text = null,
|
||||
string? cw = null, Note? reply = null, Note? renote = null) {
|
||||
if (text?.Length > config.Value.CharacterLimit)
|
||||
throw GracefulException.BadRequest($"Text cannot be longer than {config.Value.CharacterLimit} characters");
|
||||
|
||||
if (text is { Length: > 100000 })
|
||||
throw GracefulException.BadRequest("Text cannot be longer than 100.000 characters");
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@ ListenHost = localhost
|
|||
;; Caution: changing these settings after initial setup *will* break federation
|
||||
WebDomain = shrimp.example.org
|
||||
AccountDomain = example.org
|
||||
;; End of problematic settings block
|
||||
|
||||
;; Maximum number of characters allowed for local notes (must not be larger than the global limit, which is 100000 characters)
|
||||
CharacterLimit = 8192
|
||||
|
||||
[Security]
|
||||
;; Whether to require incoming ActivityPub requests carry a valid HTTP or LD signature
|
||||
|
|
Loading…
Add table
Reference in a new issue