diff options
author | 2023-01-10 15:19:05 +0100 | |
---|---|---|
committer | 2023-01-10 14:19:05 +0000 | |
commit | d6487933c758be647bff7a568d6a33e6155e6599 (patch) | |
tree | fbc2d466dc2d0833a7ceec1200643e78dae4f916 /internal/uris/uri.go | |
parent | [chore] Bump json5 from 1.0.1 to 1.0.2 in /web/source (#1308) (diff) | |
download | gotosocial-d6487933c758be647bff7a568d6a33e6155e6599.tar.xz |
[feature] Implement Report database model and utility functions (#1310)
* implement report database model
* implement report cache + config changes
* implement report database functions
* report uri / regex functions
* update envparsing test
* remove unnecessary uri index
* remove unused function + cache lookup
* process error when storing report
Diffstat (limited to 'internal/uris/uri.go')
-rw-r--r-- | internal/uris/uri.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/internal/uris/uri.go b/internal/uris/uri.go index 287e66439..f6e06ca25 100644 --- a/internal/uris/uri.go +++ b/internal/uris/uri.go @@ -28,7 +28,6 @@ import ( const ( UsersPath = "users" // UsersPath is for serving users info - ActorsPath = "actors" // ActorsPath is for serving actors info StatusesPath = "statuses" // StatusesPath is for serving statuses InboxPath = "inbox" // InboxPath represents the activitypub inbox location OutboxPath = "outbox" // OutboxPath represents the activitypub outbox location @@ -41,6 +40,7 @@ const ( FollowPath = "follow" // FollowPath used to generate the URI for an individual follow or follow request UpdatePath = "updates" // UpdatePath is used to generate the URI for an account update BlocksPath = "blocks" // BlocksPath is used to generate the URI for a block + ReportsPath = "reports" // ReportsPath is used to generate the URI for a report/flag ConfirmEmailPath = "confirm_email" // ConfirmEmailPath is used to generate the URI for an email confirmation link FileserverPath = "fileserver" // FileserverPath is a path component for serving attachments + media EmojiPath = "emoji" // EmojiPath represents the activitypub emoji location @@ -107,6 +107,17 @@ func GenerateURIForBlock(username string, thisBlockID string) string { return fmt.Sprintf("%s://%s/%s/%s/%s/%s", protocol, host, UsersPath, username, BlocksPath, thisBlockID) } +// GenerateURIForReport returns the API URI for a new Flag activity -- something like: +// https://example.org/reports/01GP3AWY4CRDVRNZKW0TEAMB5R +// +// This path specifically doesn't contain any info about the user who did the reporting, +// to protect their privacy. +func GenerateURIForReport(thisReportID string) string { + protocol := config.GetProtocol() + host := config.GetHost() + return fmt.Sprintf("%s://%s/%s/%s", protocol, host, ReportsPath, thisReportID) +} + // GenerateURIForEmailConfirm returns a link for email confirmation -- something like: // https://example.org/confirm_email?token=490e337c-0162-454f-ac48-4b22bb92a205 func GenerateURIForEmailConfirm(token string) string { @@ -228,6 +239,11 @@ func IsBlockPath(id *url.URL) bool { return regexes.BlockPath.MatchString(id.Path) } +// IsReportPath returns true if the given URL path corresponds to eg /reports/SOME_ULID_OF_A_REPORT +func IsReportPath(id *url.URL) bool { + return regexes.ReportPath.MatchString(id.Path) +} + // ParseStatusesPath returns the username and ulid from a path such as /users/example_username/statuses/SOME_ULID_OF_A_STATUS func ParseStatusesPath(id *url.URL) (username string, ulid string, err error) { matches := regexes.StatusesPath.FindStringSubmatch(id.Path) @@ -318,3 +334,14 @@ func ParseBlockPath(id *url.URL) (username string, ulid string, err error) { ulid = matches[2] return } + +// ParseReportPath returns the ulid from a path such as /reports/SOME_ULID_OF_A_REPORT +func ParseReportPath(id *url.URL) (ulid string, err error) { + matches := regexes.ReportPath.FindStringSubmatch(id.Path) + if len(matches) != 2 { + err = fmt.Errorf("expected 2 matches but matches length was %d", len(matches)) + return + } + ulid = matches[1] + return +} |