Documentation
¶
Index ¶
- Constants
- type BanDomainRequest
- type BannedResponse
- type EmailDomainRequest
- type EmbedImagePathRequest
- type EmbedTextRequest
- type EmbedTextResponse
- type GalleryResponseCursor
- type GalleryResponseV3
- type Invoice
- type InvoiceBillingReason
- type InvoiceLine
- type InvoiceLineList
- type InvoiceStatus
- type ListMeta
- type MilvusData
- type MilvusResponse
- type PaymentIntent
- type Period
- type Plan
- type Price
- type RestAPI
- func (c *RestAPI) GetApiToken(w http.ResponseWriter, r *http.Request) (token *ent.ApiToken)
- func (c *RestAPI) GetUserIDAndEmailIfAuthenticated(w http.ResponseWriter, r *http.Request) (id *uuid.UUID, email string)
- func (c *RestAPI) GetUserIfAuthenticated(w http.ResponseWriter, r *http.Request) (user *ent.User)
- func (c *RestAPI) GetUserIfAuthenticatedOnly(w http.ResponseWriter, r *http.Request) (user *ent.User, err error)
- func (c *RestAPI) HandleAddCreditsToUser(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleAuthorizeDiscord(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleBanDomains(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleBanUser(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleCreateCheckoutSession(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleCreateGeneration(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleCreateGenerationToken(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleCreatePortalSession(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleCreateUpscaleToken(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleCreateVoiceoverToken(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleDeactivateAPIToken(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleDeleteGenerationOutput(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleDeleteGenerationOutputForUser(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleDeleteVoiceoverOutputForUser(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleEmbedImagePath(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleEmbedText(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleFavoriteGenerationOutputsForUser(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetAPITokens(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetDisposableDomains(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetGenerationDefaults(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetGenerationModels(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetStats(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetUpscaleDefaults(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetUpscaleModels(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetUser(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetUserProfileMetadata(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetVoiceoverDefaults(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleGetVoiceoverModels(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleHealth(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleLikeGenerationOutputsForUser(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleMakeGenerationOutputsPrivate(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleMakeGenerationOutputsPublic(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleNewAPIToken(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleQueryCreditTypes(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleQueryCredits(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleQueryGenerations(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleQueryGenerationsForAdmin(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleQueryOperations(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleQueryUsers(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleQueryVoiceovers(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleReviewGallerySubmission(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleSCWorkerHealth(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleSCWorkerWebhook(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleSemanticSearchGallery(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleStripeWebhook(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleSubmitGenerationToGallery(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleSubscriptionDowngrade(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleUpdateEmailPreferences(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleUpdateUsername(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleUpscale(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleUserProfileSemanticSearch(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleVerifyEmailDomain(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) HandleVoiceover(w http.ResponseWriter, r *http.Request)
- func (c *RestAPI) RevertCreditsInvoice(invoice *Invoice, w http.ResponseWriter, r *http.Request)
- type Subscription
- type SubscriptionItem
- type SubscriptionItemList
- type UserProfileMetadata
Constants ¶
const DEFAULT_PER_PAGE = 50
Shared pagination defaults
const GALLERY_PER_PAGE = 50
const MAX_PER_PAGE = 300
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BanDomainRequest ¶
type BannedResponse ¶
type BannedResponse struct {
AffectedUsers int `json:"affected_users"`
}
type EmailDomainRequest ¶
type EmailDomainRequest struct {
Email string `json:"email"`
}
type EmbedImagePathRequest ¶
type EmbedTextRequest ¶
Embed text
type EmbedTextResponse ¶
type EmbedTextResponse struct {
Embedding []float32 `json:"embedding"`
}
type GalleryResponseCursor ¶
type GalleryResponseV3 ¶
type GalleryResponseV3[T GalleryResponseCursor] struct { Total *uint `json:"total,omitempty"` Next T `json:"next,omitempty"` Outputs []repository.V3GenerationOutputResult `json:"outputs"` Metadata *UserProfileMetadata `json:"metadata,omitempty"` }
type Invoice ¶
type Invoice struct { ID string `json:"id"` BillingReason InvoiceBillingReason `json:"billing_reason"` Lines *InvoiceLineList `json:"lines"` Customer string `json:"customer"` PaymentIntent string `json:"payment_intent"` Status InvoiceStatus `json:"status"` Currency string `json:"currency"` }
type InvoiceBillingReason ¶
type InvoiceBillingReason string
! Stripe types are busted so we modify the ones included in their lib InvoiceBillingReason is the reason why a given invoice was created
const ( InvoiceBillingReasonSubscription InvoiceBillingReason = "subscription" InvoiceBillingReasonSubscriptionCreate InvoiceBillingReason = "subscription_create" InvoiceBillingReasonSubscriptionCycle InvoiceBillingReason = "subscription_cycle" InvoiceBillingReasonSubscriptionThreshold InvoiceBillingReason = "subscription_threshold" InvoiceBillingReasonSubscriptionUpdate InvoiceBillingReason = "subscription_update" InvoiceBillingReasonUpcoming InvoiceBillingReason = "upcoming" )
List of values that InvoiceBillingReason can take.
type InvoiceLine ¶
type InvoiceLine struct { ID string `json:"id"` Period *Period `json:"period"` Plan *Plan `json:"plan"` Price *Price `json:"price"` }
InvoiceLine is the resource representing a Stripe invoice line item. For more details see https://stripe.com/docs/api#invoice_line_item_object.
type InvoiceLineList ¶
type InvoiceLineList struct { ListMeta Data []*InvoiceLine `json:"data"` }
type InvoiceStatus ¶
type InvoiceStatus string
const ( InvoiceStatusDraft InvoiceStatus = "draft" InvoiceStatusOpen InvoiceStatus = "open" InvoiceStatusPaid InvoiceStatus = "paid" InvoiceStatusUncollectible InvoiceStatus = "uncollectible" InvoiceStatusVoid InvoiceStatus = "void" )
type ListMeta ¶
type ListMeta struct { HasMore bool `json:"has_more"` TotalCount uint32 `json:"total_count"` URL string `json:"url"` }
ListMeta is the structure that contains the common properties of List iterators. The Count property is only populated if the total_count include option is passed in (see tests for example).
type MilvusData ¶
type MilvusData struct { Image string `json:"image"` Prompt string `json:"prompt"` UpscaledImagePath string `json:"upscaled_image_path,omitempty"` GalleryStatus generationoutput.GalleryStatus `json:"gallery_status"` IsFavorited bool `json:"is_favorited"` }
type MilvusResponse ¶
type MilvusResponse struct { Data []MilvusData `json:"data"` TranslatedText string `json:"translated_text,omitempty"` InputText string `json:"input_text"` }
type PaymentIntent ¶
type PaymentIntent struct { ID string `json:"id"` Invoice *string `json:"invoice,omitempty"` Metadata map[string]string `json:"metadata"` Customer string `json:"customer"` }
PaymentIntent is also broken
type RestAPI ¶
type RestAPI struct { Repo *repository.Repository Redis *database.RedisWrapper Hub *sse.Hub StripeClient *stripe.API Track *analytics.AnalyticsService QueueThrottler *shared.UserQueueThrottlerMap S3 *s3.S3 Qdrant *qdrant.QdrantClient Clip *clip.ClipService SafetyChecker *translator.TranslatorSafetyChecker SCWorker *scworker.SCWorker // For API key requests to track them SMap *shared.SyncMap[chan requests.CogWebhookMessage] }
func (*RestAPI) GetApiToken ¶
func (*RestAPI) GetUserIDAndEmailIfAuthenticated ¶
func (*RestAPI) GetUserIfAuthenticated ¶
func (*RestAPI) GetUserIfAuthenticatedOnly ¶
func (c *RestAPI) GetUserIfAuthenticatedOnly(w http.ResponseWriter, r *http.Request) (user *ent.User, err error)
Does not write to response, only returns user
func (*RestAPI) HandleAddCreditsToUser ¶
func (c *RestAPI) HandleAddCreditsToUser(w http.ResponseWriter, r *http.Request)
Add credits to user
func (*RestAPI) HandleAuthorizeDiscord ¶
func (c *RestAPI) HandleAuthorizeDiscord(w http.ResponseWriter, r *http.Request)
POST Discord Verification Handles linking a discord account to a Stablecog account
func (*RestAPI) HandleBanDomains ¶
func (c *RestAPI) HandleBanDomains(w http.ResponseWriter, r *http.Request)
Bulk ban email domains
func (*RestAPI) HandleBanUser ¶
func (c *RestAPI) HandleBanUser(w http.ResponseWriter, r *http.Request)
Admin-related routes, these must be behind admin middleware and auth middleware HTTP POST - admin ban user
func (*RestAPI) HandleCreateCheckoutSession ¶
func (c *RestAPI) HandleCreateCheckoutSession(w http.ResponseWriter, r *http.Request)
For creating a new subscription or upgrading one Rejects, if they have a subscription that is at a higher level than the target priceID
func (*RestAPI) HandleCreateGeneration ¶
func (c *RestAPI) HandleCreateGeneration(w http.ResponseWriter, r *http.Request)
POST generate endpoint Adds generate to queue, if authenticated, returns the ID of the generation
func (*RestAPI) HandleCreateGenerationToken ¶
func (c *RestAPI) HandleCreateGenerationToken(w http.ResponseWriter, r *http.Request)
POST generate endpoint Handles creating a generation with API token
func (*RestAPI) HandleCreatePortalSession ¶
func (c *RestAPI) HandleCreatePortalSession(w http.ResponseWriter, r *http.Request)
For creating customer portal session
func (*RestAPI) HandleCreateUpscaleToken ¶
func (c *RestAPI) HandleCreateUpscaleToken(w http.ResponseWriter, r *http.Request)
POST upscale endpoint Handles creating a upscale with API token
func (*RestAPI) HandleCreateVoiceoverToken ¶
func (c *RestAPI) HandleCreateVoiceoverToken(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleDeactivateAPIToken ¶
func (c *RestAPI) HandleDeactivateAPIToken(w http.ResponseWriter, r *http.Request)
POST - Create a new API token for the user
func (*RestAPI) HandleDeleteGenerationOutput ¶
func (c *RestAPI) HandleDeleteGenerationOutput(w http.ResponseWriter, r *http.Request)
HTTP DELETE - admin delete generation
func (*RestAPI) HandleDeleteGenerationOutputForUser ¶
func (c *RestAPI) HandleDeleteGenerationOutputForUser(w http.ResponseWriter, r *http.Request)
HTTP DELETE - delete generation
func (*RestAPI) HandleDeleteVoiceoverOutputForUser ¶
func (c *RestAPI) HandleDeleteVoiceoverOutputForUser(w http.ResponseWriter, r *http.Request)
HTTP DELETE - delete voiceover
func (*RestAPI) HandleEmbedImagePath ¶
func (c *RestAPI) HandleEmbedImagePath(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleEmbedText ¶
func (c *RestAPI) HandleEmbedText(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleFavoriteGenerationOutputsForUser ¶
func (c *RestAPI) HandleFavoriteGenerationOutputsForUser(w http.ResponseWriter, r *http.Request)
HTTP POST - favorite generation
func (*RestAPI) HandleGetAPITokens ¶
func (c *RestAPI) HandleGetAPITokens(w http.ResponseWriter, r *http.Request)
GET - Get active API tokens for user
func (*RestAPI) HandleGetDisposableDomains ¶
func (c *RestAPI) HandleGetDisposableDomains(w http.ResponseWriter, r *http.Request)
Get disposable domains
func (*RestAPI) HandleGetGenerationDefaults ¶
func (c *RestAPI) HandleGetGenerationDefaults(w http.ResponseWriter, r *http.Request)
Generation defaults and models
func (*RestAPI) HandleGetGenerationModels ¶
func (c *RestAPI) HandleGetGenerationModels(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleGetStats ¶
func (c *RestAPI) HandleGetStats(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleGetUpscaleDefaults ¶
func (c *RestAPI) HandleGetUpscaleDefaults(w http.ResponseWriter, r *http.Request)
Upscale defaults and models
func (*RestAPI) HandleGetUpscaleModels ¶
func (c *RestAPI) HandleGetUpscaleModels(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleGetUser ¶
func (c *RestAPI) HandleGetUser(w http.ResponseWriter, r *http.Request)
HTTP Get - user info
func (*RestAPI) HandleGetUserProfileMetadata ¶
func (c *RestAPI) HandleGetUserProfileMetadata(w http.ResponseWriter, r *http.Request)
For v1/profile/{username}/metadata
func (*RestAPI) HandleGetVoiceoverDefaults ¶
func (c *RestAPI) HandleGetVoiceoverDefaults(w http.ResponseWriter, r *http.Request)
Voiceover defaults and models
func (*RestAPI) HandleGetVoiceoverModels ¶
func (c *RestAPI) HandleGetVoiceoverModels(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleHealth ¶
func (c *RestAPI) HandleHealth(w http.ResponseWriter, r *http.Request)
GET health endpoint
func (*RestAPI) HandleLikeGenerationOutputsForUser ¶
func (c *RestAPI) HandleLikeGenerationOutputsForUser(w http.ResponseWriter, r *http.Request)
HTTP POST - like/unlike generation
func (*RestAPI) HandleMakeGenerationOutputsPrivate ¶
func (c *RestAPI) HandleMakeGenerationOutputsPrivate(w http.ResponseWriter, r *http.Request)
HTTP PUT make generation output public - for user Only allow submitting user's own gallery items.
func (*RestAPI) HandleMakeGenerationOutputsPublic ¶
func (c *RestAPI) HandleMakeGenerationOutputsPublic(w http.ResponseWriter, r *http.Request)
HTTP PUT make generation output public - for user Only allow submitting user's own gallery items.
func (*RestAPI) HandleNewAPIToken ¶
func (c *RestAPI) HandleNewAPIToken(w http.ResponseWriter, r *http.Request)
POST - Create a new API token for the user
func (*RestAPI) HandleQueryCreditTypes ¶
func (c *RestAPI) HandleQueryCreditTypes(w http.ResponseWriter, r *http.Request)
Get available credit types admin can gift to user
func (*RestAPI) HandleQueryCredits ¶
func (c *RestAPI) HandleQueryCredits(w http.ResponseWriter, r *http.Request)
HTTP Get - credits for user
func (*RestAPI) HandleQueryGenerations ¶
func (c *RestAPI) HandleQueryGenerations(w http.ResponseWriter, r *http.Request)
HTTP Get - generations for user Takes query paramers for pagination per_page: number of generations to return cursor: cursor for pagination, it is an iso time string in UTC
func (*RestAPI) HandleQueryGenerationsForAdmin ¶
func (c *RestAPI) HandleQueryGenerationsForAdmin(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleQueryOperations ¶
func (c *RestAPI) HandleQueryOperations(w http.ResponseWriter, r *http.Request)
HTTP Get - all operations for user Takes query paramers for pagination per_page: number of generations to return cursor: cursor for pagination, it is an iso time string in UTC
func (*RestAPI) HandleQueryUsers ¶
func (c *RestAPI) HandleQueryUsers(w http.ResponseWriter, r *http.Request)
HTTP Get - users for admin
func (*RestAPI) HandleQueryVoiceovers ¶
func (c *RestAPI) HandleQueryVoiceovers(w http.ResponseWriter, r *http.Request)
HTTP Get - voiceovers for user Takes query paramers for pagination per_page: number of generations to return cursor: cursor for pagination, it is an iso time string in UTC
func (*RestAPI) HandleReviewGallerySubmission ¶
func (c *RestAPI) HandleReviewGallerySubmission(w http.ResponseWriter, r *http.Request)
HTTP POST - admin approve/reject image in gallery
func (*RestAPI) HandleSCWorkerHealth ¶
func (c *RestAPI) HandleSCWorkerHealth(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleSCWorkerWebhook ¶
func (c *RestAPI) HandleSCWorkerWebhook(w http.ResponseWriter, r *http.Request)
Webhook for worker results
func (*RestAPI) HandleSemanticSearchGallery ¶
func (c *RestAPI) HandleSemanticSearchGallery(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleStripeWebhook ¶
func (c *RestAPI) HandleStripeWebhook(w http.ResponseWriter, r *http.Request)
Handle stripe webhooks in the following ways: invoice.payment_succeeded
- Apply credits to user depending on type (subscription, adhoc)
- For subscriptions, set active_product_id
customer.subscription.deleted"
- For an immediate cancellation, we set active_product_id to nil if this is a cancellation of the product ID we currently have set for them. (In case they upgraded, it won't unset their upgrade)
customer.subscription.created
- For a subscription upgrade, we cancel all old subscriptions
payment_intent.succeeded
- For adhoc payments, we apply credits to the user
func (*RestAPI) HandleSubmitGenerationToGallery ¶
func (c *RestAPI) HandleSubmitGenerationToGallery(w http.ResponseWriter, r *http.Request)
HTTP PUT submit a generation to gallery - for user Only allow submitting user's own gallery items.
func (*RestAPI) HandleSubscriptionDowngrade ¶
func (c *RestAPI) HandleSubscriptionDowngrade(w http.ResponseWriter, r *http.Request)
HTTP Post - handle stripe subscription downgrade Rejects if they don't have a subscription, or if they are not downgrading
func (*RestAPI) HandleUpdateEmailPreferences ¶
func (c *RestAPI) HandleUpdateEmailPreferences(w http.ResponseWriter, r *http.Request)
HTTP POST - set email preferences
func (*RestAPI) HandleUpdateUsername ¶
func (c *RestAPI) HandleUpdateUsername(w http.ResponseWriter, r *http.Request)
HTTP POST - set email preferences
func (*RestAPI) HandleUpscale ¶
func (c *RestAPI) HandleUpscale(w http.ResponseWriter, r *http.Request)
func (*RestAPI) HandleUserProfileSemanticSearch ¶
func (c *RestAPI) HandleUserProfileSemanticSearch(w http.ResponseWriter, r *http.Request)
For v1/profile/{username}/outputs
func (*RestAPI) HandleVerifyEmailDomain ¶
func (c *RestAPI) HandleVerifyEmailDomain(w http.ResponseWriter, r *http.Request)
POST verify email or email domain
func (*RestAPI) HandleVoiceover ¶
func (c *RestAPI) HandleVoiceover(w http.ResponseWriter, r *http.Request)
func (*RestAPI) RevertCreditsInvoice ¶
type Subscription ¶
type Subscription struct { Items *SubscriptionItemList `json:"items"` Customer string `json:"customer"` }
type SubscriptionItem ¶
type SubscriptionItem struct {
Price *Price `json:"price"`
}
Subscription object is also pbroken in stripe
type SubscriptionItemList ¶
type SubscriptionItemList struct {
Data []*SubscriptionItem `json:"data"`
}