Documentation
¶
Index ¶
- Variables
- func AddQueryParam(rawURL string, queryParam ...QueryParam) (string, error)
- func CalculateVoiceoverCredits(prompt string) int32
- func EnsureTrailingSlash(s string) string
- func ExtractAmountsFromString(str string) (int, error)
- func FormatPrompt(s string) string
- func GenerateRandomHex(rand io.Reader, nBytes int) (string, error)
- func GenerateUsername(randReader RandReader) string
- func GetCountryCode(r *http.Request) string
- func GetIPAddress(r *http.Request) string
- func GetImageSizeFromUrl(imageUrl string) (bytes int64, err error)
- func GetImageWidthHeightFromUrl(imageUrl string, headUrl string, maxSizeBytes int64) (width, height int32, err error)
- func GetPathFromS3URL(s3UrlStr string) (string, error)
- func GetThumbmarkID(r *http.Request) string
- func IsSha256Hash(str string) bool
- func IsValidHTTPURL(urlStr string) bool
- func IsValidUsername(username string) error
- func Max[T constraints.Ordered](a, b T) T
- func NormalizeEmail(email string) string
- func ParseIsoTime(isoTime string) (time.Time, error)
- func RelativeTimeStr(t time.Time) string
- func RemoveLineBreaks(s string) string
- func RemovePlusFromEmail(email string) string
- func RemoveRedundantSpaces(s string) string
- func RootDir() string
- func SecondsSinceEpochToTime(seconds int64) time.Time
- func Sha256(s string) string
- func TimeToIsoString(ts time.Time) string
- func ToPtr[T interface{}](value T) *T
- type AESCrypt
- type ClientDeviceInfo
- type ClientDeviceType
- type CryptoRandReader
- type QueryParam
- type RandReader
- type SCEnv
Constants ¶
This section is empty.
Variables ¶
var ( UsernameLengthError = errors.New("username_length_error") UsernameStartsWithLetterError = errors.New("username_must_start_with_a_letter") UsernameCharError = errors.New("username_can_only_contain_letters_numbers_hyphens") UsernameProfaneError = errors.New("username_profanity") UsernameBlacklistedError = errors.New("username_blacklisted") )
Validate username
var AmountAmbiguousError = fmt.Errorf("amount_ambiguous")
Extract integer from a string (ie. !tip 500 @bbedward -> 500)
var AmountMissingError = fmt.Errorf("amount_not_found")
var AmountNotIntegerError = fmt.Errorf("amount_not_integer")
var RuntimeCaller = runtime.Caller
Functions ¶
func AddQueryParam ¶
func AddQueryParam(rawURL string, queryParam ...QueryParam) (string, error)
func EnsureTrailingSlash ¶
Ensure trailing slash in string
func ExtractAmountsFromString ¶
Not actually using regex here, but it's a good place to put this function
func FormatPrompt ¶
FormatPrompt applies formatting to a prompt string e.g. " hello world " -> "hello world"
func GenerateRandomHex ¶
Generates random N bytes and returns them as a hex string
func GenerateUsername ¶
func GenerateUsername(randReader RandReader) string
func GetCountryCode ¶
Retrieves a country code via request header, prefer cloudflare, then vercel
func GetImageSizeFromUrl ¶
Retrieves the download size of an image via headers
func GetPathFromS3URL ¶
func GetThumbmarkID ¶
func IsSha256Hash ¶
func IsValidHTTPURL ¶
Validates that a URL is valid with http or https scheme
func IsValidUsername ¶
func Max ¶
func Max[T constraints.Ordered](a, b T) T
Define the Max function that works for any type T that is comparable.
func NormalizeEmail ¶
func ParseIsoTime ¶
Parse an iso string into a time.Time e.g. 2023-01-27T14:40:53.858Z represents javascript toISOString()
func RelativeTimeStr ¶
Create a relative time string from now to past (e.g., "1h ago")
func RemoveLineBreaks ¶
RemoveLineBreaks removes all line breaks from a string e.g. "hello\nworld" -> "hello world"
func RemovePlusFromEmail ¶
Remove + from email addresses
func RemoveRedundantSpaces ¶
RemoveRedundantSpaces removes all redundant spaces from a string e.g. " hello world " -> " hello world "
func SecondsSinceEpochToTime ¶
func TimeToIsoString ¶
Types ¶
type ClientDeviceInfo ¶
type ClientDeviceInfo struct {
DeviceType ClientDeviceType `json:"device_type"`
DeviceOs string `json:"device_os"`
DeviceBrowser string `json:"device_browser"`
DeviceBrowserVersion string `json:"device_browser_version"`
}
func GetClientDeviceInfo ¶
func GetClientDeviceInfo(r *http.Request) ClientDeviceInfo
type ClientDeviceType ¶
type ClientDeviceType string
Parses user agent to return device type, os, and browser
const ( Desktop ClientDeviceType = "desktop" Mobile ClientDeviceType = "mobile" Tablet ClientDeviceType = "tablet" Bot ClientDeviceType = "bot" Unknown ClientDeviceType = "unknown" )
type CryptoRandReader ¶
type CryptoRandReader struct{}
type QueryParam ¶
type RandReader ¶
type SCEnv ¶
type SCEnv struct {
Production bool `env:"PRODUCTION" envDefault:"false"`
Port int `env:"PORT" envDefault:"8000"`
PublicApiUrl string `env:"PUBLIC_API_URL" envDefault:"http://localhost:8000"` // Used for thing such as, building the webhook URL for sc-worker to send results to
PrivateApiUrl string `env:"PRIVATE_API_URL" envDefault:"http://localhost:13337"`
// Content moderation and translator
OpenAIApiKey string `env:"OPENAI_API_KEY"`
PrivateLinguaAPIUrl string `env:"PRIVATE_LINGUA_API_URL"` // Corresponds to sc-go/language server
// Shared secret between sc-worker and sc-server
ScWorkerWebhookSecret string `env:"SC_WORKER_WEBHOOK_SECRET" envDefault:"invalid"`
// Whether to run DB migrations on startup, can only be done in the local environment (not on a supabase database)
RunMigrations bool `env:"RUN_MIGRATIONS" envDefault:"false"`
// CDN URLs for assets
BucketBaseUrl string `env:"BUCKET_BASE_URL" envDefault:"https://b.stablecog.com/"` // Public CDN URL
BucketVoiceverUrl string `env:"BUCKET_VOICEOVER_URL" envDefault:"https://bvoi.stablecog.com/"`
// Stripe
StripeSecretKey string `env:"STRIPE_SECRET_KEY"` // required
StripeEndpointSecret string `env:"STRIPE_ENDPOINT_SECRET"` // Required for stripe webhooks
StripeWebhookSubscriptionSecret string `env:"STRIPE_WEBHOOK_SUBSCRIPTION_SECRET"` // Required for stripe webhooks
// Stripe subscription price + product IDs
StripeUltimatePriceID string `env:"STRIPE_ULTIMATE_PRICE_ID" envDefault:"price_1Mf591ATa0ehBYTA6ggpEEkA"`
StripeProPriceID string `env:"STRIPE_PRO_PRICE_ID" envDefault:"price_1Mf50bATa0ehBYTAPOcfnOjG"`
StripeStarterPriceID string `env:"STRIPE_STARTER_PRICE_ID" envDefault:"price_1Mf56NATa0ehBYTAHkCUablG"`
StripeUltimateProductID string `env:"STRIPE_ULTIMATE_PRODUCT_ID" envDefault:"prod_NTzE0C8bEuIv6F"`
StripeProProductID string `env:"STRIPE_PRO_PRODUCT_ID" envDefault:"prod_NTzCojAHPw6tbX"`
StripeStarterProductID string `env:"STRIPE_STARTER_PRODUCT_ID" envDefault:"prod_NPuwbni7ZNkHDO"`
// Annual price IDss
StripeUltimateAnnualPriceID string `env:"STRIPE_ULTIMATE_ANNUAL_PRICE_ID" envDefault:"price_1Mf5BjATa0ehBYTA5Z3Z2Z6v"`
StripeProAnnualPriceID string `env:"STRIPE_PRO_ANNUAL_PRICE_ID" envDefault:"price_1Mf5BjATa0ehBYTA5Z3Z2Z6v"`
StripeStarterAnnualPriceID string `env:"STRIPE_STARTER_ANNUAL_PRICE_ID" envDefault:"price_1Mf5BjATa0ehBYTA5Z3Z2Z6v"`
// Stripe ad-hoc purchase price + product IDs
StripeLargePackPriceID string `env:"STRIPE_LARGE_PACK_PRICE_ID" envDefault:"1"`
StripeMediumPackPriceID string `env:"STRIPE_MEDIUM_PACK_PRICE_ID" envDefault:"2"`
StripeMegaPackPriceID string `env:"STRIPE_MEGA_PACK_PRICE_ID" envDefault:"3"`
StripeLargePackProductID string `env:"STRIPE_LARGE_PACK_PRODUCT_ID" envDefault:"1"`
StripeMediumPackProductID string `env:"STRIPE_MEDIUM_PACK_PRODUCT_ID" envDefault:"2"`
StripeMegaPackProductID string `env:"STRIPE_MEGA_PACK_PRODUCT_ID" envDefault:"3"`
// Discord webhooks
DiscordWebhookUrl string `env:"DISCORD_WEBHOOK_URL"` // For health notifications in cron, Optional
DiscordWebhookUrlDeploy string `env:"DISCORD_WEBHOOK_URL_DEPLOY"` // For deploy notifications in server, Optional
DiscordWebhookUrlNewSub string `env:"DISCORD_WEBHOOK_URL_NEWSUB"` // For new sub notifications in server, Optional
DiscordWebhookUrlUserclean string `env:"DISCORD_WEBHOOK_URL_USERCLEAN"` // Sent when cron wipes users or has an error
GeoIpWebhook string `env:"GEOIP_WEBHOOK"` // For geoip notifications in server, Optional
// Whether running in github actions, basically whether to use Postgres or not in tests (will use SQLite if false)
GithubActions bool `env:"GITHUB_ACTIONS" envDefault:"false"` // Whether we're running in Github Actions
// PostgreSQL
PostgresDB string `env:"POSTGRES_DB" envDefault:"postgres"` // Postgres DB Name
PostgresUser string `env:"POSTGRES_USER" envDefault:"postgres"` // Postgres DB User
PostgresPassword string `env:"POSTGRES_PASSWORD"` // Postgres DB Password, required
PostgresHost string `env:"POSTGRES_HOST" envDefault:"127.0.0.1"` // Postgres DB Host
PostgresPort int `env:"POSTGRES_PORT" envDefault:"5432"` // Postgres DB Port
// Redis
RedisConnectionString string `env:"REDIS_CONNECTION_STRING" envDefault:"redis://localhost:6379/0"` // Redis connection string, required
MockRedis bool `env:"MOCK_REDIS" envDefault:"false"` // Whether to mock redis for tests
// Qdrant
QdrantUrl string `env:"QDRANT_URL"` // Qdrant URL, required
QdrantUsername string `env:"QDRANT_USERNAME"` // Qdrant Username, Optional
QdrantPassword string `env:"QDRANT_PASSWORD"` // Qdrant Password, Optional
QdrantCollectionName string `env:"QDRANT_COLLECTION_NAME" envDefault:"stablecog"` // Qdrant Collection Name
// Supabase
PublicSupabaseReferenceID string `env:"PUBLIC_SUPABASE_REFERENCE_ID"` // Supabase reference ID, required
SupabaseAdminKey string `env:"SUPABASE_ADMIN_KEY"` // Supabase admin key, required
GotrueURL string `env:"GOTRUE_URL"` // Gotrue URL, Optional (Only for self-hosted supabase)
// RabbitMQ
RabbitMQQueueName string `env:"RABBITMQ_QUEUE_NAME" envDefault:"TEST.Q"` // RabbitMQ queue name
RabbitMQAMQPUrl string `env:"RABBITMQ_AMQP_URL" envDefault:"amqp://guest:guest@localhost:5672/"` // RabbitMQ AMQP URL
// S3 img2img bucket, for user-uploaded images
S3Img2ImgRegion string `env:"S3_IMG2IMG_REGION" envDefault:"us-east-1"` // S3 region
S3Img2ImgBucketName string `env:"S3_IMG2IMG_BUCKET_NAME" envDefault:"img2img"` // S3 bucket
S3Img2ImgAccessKey string `env:"S3_IMG2IMG_ACCESS_KEY" envDefault:""` // S3 access key
S3Img2ImgSecretKey string `env:"S3_IMG2IMG_SECRET_KEY" envDefault:""` // S3 secret key
S3Img2ImgEndpoint string `env:"S3_IMG2IMG_ENDPOINT" envDefault:""` // S3 endpoint
// S3 bucket, for all sc-worker uploaded assets. Primarily used for deleting user data in cron CLI
S3Region string `env:"S3_REGION" envDefault:"us-east-1"` // S3 region
S3BucketName string `env:"S3_BUCKET_NAME" envDefault:"stablecog"` // S3 bucket
S3AccessKey string `env:"S3_ACCESS_KEY"` // S3 access key
S3SecretKey string `env:"S3_SECRET_KEY"`
S3Endpoint string `env:"S3_ENDPOINT"` // S3 endpoint
// Analytics (Optional group)
PosthogApiKey string `env:"POSTHOG_API_KEY"` // Posthog API Key, Optional
PosthogEndpoint string `env:"POSTHOG_ENDPOINT"` // Posthog Endpoint, Optional
// Discord bot
DiscordBotToken string `env:"DISCORD_BOT_TOKEN"` // Discord bot token, only required for discobot
DiscordUserIdsToNotify string `env:"DISCORD_USER_IDS_TO_NOTIFY" envDefault:""` // Discord user IDs to notify
// Oauth service, used by services such as Raycast
DataEncryptionPassword string `env:"DATA_ENCRYPTION_PASSWORD" envDefault:"insecurePassword"` // Data encryption password
OauthRedirectBase string `env:"OAUTH_REDIRECT_BASE" envDefault:"http://localhost:3000"` // Oauth redirect base
// Og Service Token for bypassing rate limits
OgPreviewServiceToken string `env:"OG_PREVIEW_SERVICE_TOKEN" envDefault:""` // Og Service Token for preview service
// Vast.ai API Key
VastAiKey string `env:"VASTAI_KEY"` // Vast.ai Key
// SC Worker Tester API Key
ScWorkerTesterApiKey string `env:"SC_WORKER_TESTER_API_KEY" envDefault:""` // SC Worker Tester API Key
ClipApiUrl string `env:"CLIP_API_URL"` // Clip API URL
ClipApiAuthToken string `env:"CLIP_API_AUTH_TOKEN"` // Clip API Auth Token
// Runpod Serverless
RunpodApiToken string `env:"RUNPOD_API_TOKEN"` // Runpod API Token
}