diff options
author | 2023-11-20 12:22:28 +0000 | |
---|---|---|
committer | 2023-11-20 12:22:28 +0000 | |
commit | 16275853eb8a43e0b113d476b896de53585c1281 (patch) | |
tree | b2e0e6b4fc7cd4f1cc781e5c305ec24df38e6718 /internal/api/util/parsequery.go | |
parent | [chore]: Bump github.com/tdewolff/minify/v2 from 2.20.6 to 2.20.7 (#2370) (diff) | |
download | gotosocial-16275853eb8a43e0b113d476b896de53585c1281.tar.xz |
[bugfix] self-referencing collection pages for status replies (#2364)
Diffstat (limited to 'internal/api/util/parsequery.go')
-rw-r--r-- | internal/api/util/parsequery.go | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/internal/api/util/parsequery.go b/internal/api/util/parsequery.go index 6a9116dcf..da6320b67 100644 --- a/internal/api/util/parsequery.go +++ b/internal/api/util/parsequery.go @@ -41,6 +41,10 @@ const ( SinceIDKey = "since_id" MinIDKey = "min_id" + /* AP endpoint keys */ + + OnlyOtherAccountsKey = "only_other_accounts" + /* Search keys */ SearchExcludeUnreviewedKey = "exclude_unreviewed" @@ -66,20 +70,6 @@ const ( DomainPermissionImportKey = "import" ) -// parseError returns gtserror.WithCode set to 400 Bad Request, to indicate -// to the caller that a key was set to a value that could not be parsed. -func parseError(key string, value, defaultValue any, err error) gtserror.WithCode { - err = fmt.Errorf("error parsing key %s with value %s as %T: %w", key, value, defaultValue, err) - return gtserror.NewErrorBadRequest(err, err.Error()) -} - -// requiredError returns gtserror.WithCode set to 400 Bad Request, to indicate -// to the caller a required key value was not provided, or was empty. -func requiredError(key string) gtserror.WithCode { - err := fmt.Errorf("required key %s was not set or had empty value", key) - return gtserror.NewErrorBadRequest(err, err.Error()) -} - /* Parse functions for *OPTIONAL* parameters with default values. */ @@ -129,6 +119,10 @@ func ParseDomainPermissionImport(value string, defaultValue bool) (bool, gtserro return parseBool(value, defaultValue, DomainPermissionImportKey) } +func ParseOnlyOtherAccounts(value string, defaultValue bool) (bool, gtserror.WithCode) { + return parseBool(value, defaultValue, OnlyOtherAccountsKey) +} + /* Parse functions for *REQUIRED* parameters. */ @@ -248,3 +242,17 @@ func parseInt(value string, defaultValue int, max int, min int, key string) (int return i, nil } + +// parseError returns gtserror.WithCode set to 400 Bad Request, to indicate +// to the caller that a key was set to a value that could not be parsed. +func parseError(key string, value, defaultValue any, err error) gtserror.WithCode { + err = fmt.Errorf("error parsing key %s with value %s as %T: %w", key, value, defaultValue, err) + return gtserror.NewErrorBadRequest(err, err.Error()) +} + +// requiredError returns gtserror.WithCode set to 400 Bad Request, to indicate +// to the caller a required key value was not provided, or was empty. +func requiredError(key string) gtserror.WithCode { + err := fmt.Errorf("required key %s was not set or had empty value", key) + return gtserror.NewErrorBadRequest(err, err.Error()) +} |