[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
|
@ -34,6 +34,7 @@ public sealed class Config {
|
||||||
public required string ListenHost { get; init; } = "localhost";
|
public required string ListenHost { get; init; } = "localhost";
|
||||||
public required string WebDomain { get; init; }
|
public required string WebDomain { get; init; }
|
||||||
public required string AccountDomain { get; init; }
|
public required string AccountDomain { get; init; }
|
||||||
|
public required int CharacterLimit { get; init; } = 8192;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class SecuritySection {
|
public sealed class SecuritySection {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
@ -11,11 +12,13 @@ using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Services;
|
namespace Iceshrimp.Backend.Core.Services;
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameterInConstructor",
|
||||||
|
Justification = "We need IOptionsSnapshot for config hot reload")]
|
||||||
public class NoteService(
|
public class NoteService(
|
||||||
ILogger<NoteService> logger,
|
ILogger<NoteService> logger,
|
||||||
DatabaseContext db,
|
DatabaseContext db,
|
||||||
UserResolver userResolver,
|
UserResolver userResolver,
|
||||||
IOptions<Config.InstanceSection> config,
|
IOptionsSnapshot<Config.InstanceSection> config,
|
||||||
UserService userSvc,
|
UserService userSvc,
|
||||||
ActivityFetcherService fetchSvc,
|
ActivityFetcherService fetchSvc,
|
||||||
ActivityDeliverService deliverSvc,
|
ActivityDeliverService deliverSvc,
|
||||||
|
@ -27,6 +30,9 @@ public class NoteService(
|
||||||
|
|
||||||
public async Task<Note> CreateNoteAsync(User user, Note.NoteVisibility visibility, string? text = null,
|
public async Task<Note> CreateNoteAsync(User user, Note.NoteVisibility visibility, string? text = null,
|
||||||
string? cw = null, Note? reply = null, Note? renote = 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 })
|
if (text is { Length: > 100000 })
|
||||||
throw GracefulException.BadRequest("Text cannot be longer than 100.000 characters");
|
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
|
;; Caution: changing these settings after initial setup *will* break federation
|
||||||
WebDomain = shrimp.example.org
|
WebDomain = shrimp.example.org
|
||||||
AccountDomain = 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]
|
[Security]
|
||||||
;; Whether to require incoming ActivityPub requests carry a valid HTTP or LD signature
|
;; Whether to require incoming ActivityPub requests carry a valid HTTP or LD signature
|
||||||
|
|
Loading…
Add table
Reference in a new issue