versia-go/internal/utils/urls.go

95 lines
2.9 KiB
Go
Raw Normal View History

2024-08-11 03:51:22 +02:00
package utils
import (
"fmt"
"github.com/google/uuid"
"github.com/lysand-org/versia-go/config"
2024-08-22 23:03:38 +02:00
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
"net/url"
2024-08-11 03:51:22 +02:00
)
var dicebearURL = &url.URL{
Scheme: "https",
Host: "api.dicebear.com",
Path: "9.x/adventurer/svg",
}
2024-08-22 23:03:38 +02:00
func UserAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: fmt.Sprintf("/api/users/%s/", uuid.String())}
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
2024-08-11 03:51:22 +02:00
}
2024-08-22 23:03:38 +02:00
func DefaultAvatarURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
u := &url.URL{}
q := u.Query()
q.Set("seed", uuid.String())
u.RawQuery = q.Encode()
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(dicebearURL.ResolveReference(u))
2024-08-11 03:51:22 +02:00
}
2024-08-22 23:03:38 +02:00
func UserInboxAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: "./inbox"}
return UserAPIURL(uuid).ResolveReference(newPath)
}
2024-08-22 23:03:38 +02:00
func UserOutboxAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: "./outbox"}
return UserAPIURL(uuid).ResolveReference(newPath)
}
2024-08-22 23:03:38 +02:00
func UserFollowersAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: "./followers"}
return UserAPIURL(uuid).ResolveReference(newPath)
}
2024-08-22 23:03:38 +02:00
func UserFollowingAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: "./following"}
return UserAPIURL(uuid).ResolveReference(newPath)
}
2024-08-22 23:03:38 +02:00
func UserFeaturedAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: "./featured"}
return UserAPIURL(uuid).ResolveReference(newPath)
}
2024-08-22 23:03:38 +02:00
func UserLikesAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: "./likes"}
return UserAPIURL(uuid).ResolveReference(newPath)
}
2024-08-22 23:03:38 +02:00
func UserDislikesAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: "./dislikes"}
return UserAPIURL(uuid).ResolveReference(newPath)
}
2024-08-22 23:03:38 +02:00
func FollowAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: fmt.Sprintf("/api/follows/%s/", uuid.String())}
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
2024-08-11 03:51:22 +02:00
}
2024-08-22 23:03:38 +02:00
func NoteAPIURL(uuid uuid.UUID) *versiautils.URL {
2024-08-11 03:51:22 +02:00
newPath := &url.URL{Path: fmt.Sprintf("/api/notes/%s/", uuid.String())}
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
2024-08-11 03:51:22 +02:00
}
2024-08-20 22:43:26 +02:00
2024-08-22 23:03:38 +02:00
func InstanceMetadataAPIURL() *versiautils.URL {
2024-08-20 22:43:26 +02:00
newPath := &url.URL{Path: "/.well-known/versia/"}
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
2024-08-20 22:43:26 +02:00
}
2024-08-22 23:03:38 +02:00
func InstanceMetadataAdminsAPIURL() *versiautils.URL {
2024-08-20 22:43:26 +02:00
newPath := &url.URL{Path: "/.well-known/versia/admins/"}
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
2024-08-20 22:43:26 +02:00
}
2024-08-22 23:03:38 +02:00
func InstanceMetadataModeratorsAPIURL() *versiautils.URL {
2024-08-20 22:43:26 +02:00
newPath := &url.URL{Path: "/.well-known/versia/moderators/"}
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
2024-08-20 22:43:26 +02:00
}
2024-08-22 23:03:38 +02:00
func SharedInboxAPIURL() *versiautils.URL {
2024-08-20 22:43:26 +02:00
newPath := &url.URL{Path: "/api/inbox/"}
2024-08-22 23:03:38 +02:00
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
2024-08-20 22:43:26 +02:00
}