Api/v1/statuses (#11)
This PR adds:
Statuses
New status creation.
View existing status
Delete a status
Fave a status
Unfave a status
See who's faved a status
Media
Upload media attachment and store/retrieve it
Upload custom emoji and store/retrieve it
Fileserver
Serve files from storage
Testing
Test models, testrig -- run a GTS test instance and play around with it.
This commit is contained in:
@ -36,6 +36,7 @@ type Config struct {
|
||||
AccountsConfig *AccountsConfig `yaml:"accounts"`
|
||||
MediaConfig *MediaConfig `yaml:"media"`
|
||||
StorageConfig *StorageConfig `yaml:"storage"`
|
||||
StatusesConfig *StatusesConfig `yaml:"statuses"`
|
||||
}
|
||||
|
||||
// FromFile returns a new config from a file, or an error if something goes amiss.
|
||||
@ -50,7 +51,7 @@ func FromFile(path string) (*Config, error) {
|
||||
return Empty(), nil
|
||||
}
|
||||
|
||||
// Empty just returns an empty config
|
||||
// Empty just returns a new empty config
|
||||
func Empty() *Config {
|
||||
return &Config{
|
||||
DBConfig: &DBConfig{},
|
||||
@ -58,6 +59,7 @@ func Empty() *Config {
|
||||
AccountsConfig: &AccountsConfig{},
|
||||
MediaConfig: &MediaConfig{},
|
||||
StorageConfig: &StorageConfig{},
|
||||
StatusesConfig: &StatusesConfig{},
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,8 +142,8 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) {
|
||||
c.AccountsConfig.OpenRegistration = f.Bool(fn.AccountsOpenRegistration)
|
||||
}
|
||||
|
||||
if f.IsSet(fn.AccountsRequireApproval) {
|
||||
c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsRequireApproval)
|
||||
if f.IsSet(fn.AccountsApprovalRequired) {
|
||||
c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsApprovalRequired)
|
||||
}
|
||||
|
||||
// media flags
|
||||
@ -153,6 +155,14 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) {
|
||||
c.MediaConfig.MaxVideoSize = f.Int(fn.MediaMaxVideoSize)
|
||||
}
|
||||
|
||||
if c.MediaConfig.MinDescriptionChars == 0 || f.IsSet(fn.MediaMinDescriptionChars) {
|
||||
c.MediaConfig.MinDescriptionChars = f.Int(fn.MediaMinDescriptionChars)
|
||||
}
|
||||
|
||||
if c.MediaConfig.MaxDescriptionChars == 0 || f.IsSet(fn.MediaMaxDescriptionChars) {
|
||||
c.MediaConfig.MaxDescriptionChars = f.Int(fn.MediaMaxDescriptionChars)
|
||||
}
|
||||
|
||||
// storage flags
|
||||
if c.StorageConfig.Backend == "" || f.IsSet(fn.StorageBackend) {
|
||||
c.StorageConfig.Backend = f.String(fn.StorageBackend)
|
||||
@ -173,6 +183,23 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) {
|
||||
if c.StorageConfig.ServeBasePath == "" || f.IsSet(fn.StorageServeBasePath) {
|
||||
c.StorageConfig.ServeBasePath = f.String(fn.StorageServeBasePath)
|
||||
}
|
||||
|
||||
// statuses flags
|
||||
if c.StatusesConfig.MaxChars == 0 || f.IsSet(fn.StatusesMaxChars) {
|
||||
c.StatusesConfig.MaxChars = f.Int(fn.StatusesMaxChars)
|
||||
}
|
||||
if c.StatusesConfig.CWMaxChars == 0 || f.IsSet(fn.StatusesCWMaxChars) {
|
||||
c.StatusesConfig.CWMaxChars = f.Int(fn.StatusesCWMaxChars)
|
||||
}
|
||||
if c.StatusesConfig.PollMaxOptions == 0 || f.IsSet(fn.StatusesPollMaxOptions) {
|
||||
c.StatusesConfig.PollMaxOptions = f.Int(fn.StatusesPollMaxOptions)
|
||||
}
|
||||
if c.StatusesConfig.PollOptionMaxChars == 0 || f.IsSet(fn.StatusesPollOptionMaxChars) {
|
||||
c.StatusesConfig.PollOptionMaxChars = f.Int(fn.StatusesPollOptionMaxChars)
|
||||
}
|
||||
if c.StatusesConfig.MaxMediaFiles == 0 || f.IsSet(fn.StatusesMaxMediaFiles) {
|
||||
c.StatusesConfig.MaxMediaFiles = f.Int(fn.StatusesMaxMediaFiles)
|
||||
}
|
||||
}
|
||||
|
||||
// KeyedFlags is a wrapper for any type that can store keyed flags and give them back.
|
||||
@ -203,16 +230,63 @@ type Flags struct {
|
||||
TemplateBaseDir string
|
||||
|
||||
AccountsOpenRegistration string
|
||||
AccountsRequireApproval string
|
||||
AccountsApprovalRequired string
|
||||
AccountsReasonRequired string
|
||||
|
||||
MediaMaxImageSize string
|
||||
MediaMaxVideoSize string
|
||||
MediaMaxImageSize string
|
||||
MediaMaxVideoSize string
|
||||
MediaMinDescriptionChars string
|
||||
MediaMaxDescriptionChars string
|
||||
|
||||
StorageBackend string
|
||||
StorageBasePath string
|
||||
StorageServeProtocol string
|
||||
StorageServeHost string
|
||||
StorageServeBasePath string
|
||||
|
||||
StatusesMaxChars string
|
||||
StatusesCWMaxChars string
|
||||
StatusesPollMaxOptions string
|
||||
StatusesPollOptionMaxChars string
|
||||
StatusesMaxMediaFiles string
|
||||
}
|
||||
|
||||
type Defaults struct {
|
||||
LogLevel string
|
||||
ApplicationName string
|
||||
ConfigPath string
|
||||
Host string
|
||||
Protocol string
|
||||
|
||||
DbType string
|
||||
DbAddress string
|
||||
DbPort int
|
||||
DbUser string
|
||||
DbPassword string
|
||||
DbDatabase string
|
||||
|
||||
TemplateBaseDir string
|
||||
|
||||
AccountsOpenRegistration bool
|
||||
AccountsRequireApproval bool
|
||||
AccountsReasonRequired bool
|
||||
|
||||
MediaMaxImageSize int
|
||||
MediaMaxVideoSize int
|
||||
MediaMinDescriptionChars int
|
||||
MediaMaxDescriptionChars int
|
||||
|
||||
StorageBackend string
|
||||
StorageBasePath string
|
||||
StorageServeProtocol string
|
||||
StorageServeHost string
|
||||
StorageServeBasePath string
|
||||
|
||||
StatusesMaxChars int
|
||||
StatusesCWMaxChars int
|
||||
StatusesPollMaxOptions int
|
||||
StatusesPollOptionMaxChars int
|
||||
StatusesMaxMediaFiles int
|
||||
}
|
||||
|
||||
// GetFlagNames returns a struct containing the names of the various flags used for
|
||||
@ -235,16 +309,25 @@ func GetFlagNames() Flags {
|
||||
TemplateBaseDir: "template-basedir",
|
||||
|
||||
AccountsOpenRegistration: "accounts-open-registration",
|
||||
AccountsRequireApproval: "accounts-require-approval",
|
||||
AccountsApprovalRequired: "accounts-approval-required",
|
||||
AccountsReasonRequired: "accounts-reason-required",
|
||||
|
||||
MediaMaxImageSize: "media-max-image-size",
|
||||
MediaMaxVideoSize: "media-max-video-size",
|
||||
MediaMaxImageSize: "media-max-image-size",
|
||||
MediaMaxVideoSize: "media-max-video-size",
|
||||
MediaMinDescriptionChars: "media-min-description-chars",
|
||||
MediaMaxDescriptionChars: "media-max-description-chars",
|
||||
|
||||
StorageBackend: "storage-backend",
|
||||
StorageBasePath: "storage-base-path",
|
||||
StorageServeProtocol: "storage-serve-protocol",
|
||||
StorageServeHost: "storage-serve-host",
|
||||
StorageServeBasePath: "storage-serve-base-path",
|
||||
|
||||
StatusesMaxChars: "statuses-max-chars",
|
||||
StatusesCWMaxChars: "statuses-cw-max-chars",
|
||||
StatusesPollMaxOptions: "statuses-poll-max-options",
|
||||
StatusesPollOptionMaxChars: "statuses-poll-option-max-chars",
|
||||
StatusesMaxMediaFiles: "statuses-max-media-files",
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,15 +351,24 @@ func GetEnvNames() Flags {
|
||||
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
|
||||
|
||||
AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
|
||||
AccountsRequireApproval: "GTS_ACCOUNTS_REQUIRE_APPROVAL",
|
||||
AccountsApprovalRequired: "GTS_ACCOUNTS_APPROVAL_REQUIRED",
|
||||
AccountsReasonRequired: "GTS_ACCOUNTS_REASON_REQUIRED",
|
||||
|
||||
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
||||
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
||||
MediaMaxImageSize: "GTS_MEDIA_MAX_IMAGE_SIZE",
|
||||
MediaMaxVideoSize: "GTS_MEDIA_MAX_VIDEO_SIZE",
|
||||
MediaMinDescriptionChars: "GTS_MEDIA_MIN_DESCRIPTION_CHARS",
|
||||
MediaMaxDescriptionChars: "GTS_MEDIA_MAX_DESCRIPTION_CHARS",
|
||||
|
||||
StorageBackend: "GTS_STORAGE_BACKEND",
|
||||
StorageBasePath: "GTS_STORAGE_BASE_PATH",
|
||||
StorageServeProtocol: "GTS_STORAGE_SERVE_PROTOCOL",
|
||||
StorageServeHost: "GTS_STORAGE_SERVE_HOST",
|
||||
StorageServeBasePath: "GTS_STORAGE_SERVE_BASE_PATH",
|
||||
|
||||
StatusesMaxChars: "GTS_STATUSES_MAX_CHARS",
|
||||
StatusesCWMaxChars: "GTS_STATUSES_CW_MAX_CHARS",
|
||||
StatusesPollMaxOptions: "GTS_STATUSES_POLL_MAX_OPTIONS",
|
||||
StatusesPollOptionMaxChars: "GTS_STATUSES_POLL_OPTION_MAX_CHARS",
|
||||
StatusesMaxMediaFiles: "GTS_STATUSES_MAX_MEDIA_FILES",
|
||||
}
|
||||
}
|
||||
|
||||
177
internal/config/default.go
Normal file
177
internal/config/default.go
Normal file
@ -0,0 +1,177 @@
|
||||
package config
|
||||
|
||||
// TestDefault returns a default config for testing
|
||||
func TestDefault() *Config {
|
||||
defaults := GetTestDefaults()
|
||||
return &Config{
|
||||
LogLevel: defaults.LogLevel,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
Host: defaults.Host,
|
||||
Protocol: defaults.Protocol,
|
||||
DBConfig: &DBConfig{
|
||||
Type: defaults.DbType,
|
||||
Address: defaults.DbAddress,
|
||||
Port: defaults.DbPort,
|
||||
User: defaults.DbUser,
|
||||
Password: defaults.DbPassword,
|
||||
Database: defaults.DbDatabase,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
},
|
||||
TemplateConfig: &TemplateConfig{
|
||||
BaseDir: defaults.TemplateBaseDir,
|
||||
},
|
||||
AccountsConfig: &AccountsConfig{
|
||||
OpenRegistration: defaults.AccountsOpenRegistration,
|
||||
RequireApproval: defaults.AccountsRequireApproval,
|
||||
ReasonRequired: defaults.AccountsReasonRequired,
|
||||
},
|
||||
MediaConfig: &MediaConfig{
|
||||
MaxImageSize: defaults.MediaMaxImageSize,
|
||||
MaxVideoSize: defaults.MediaMaxVideoSize,
|
||||
MinDescriptionChars: defaults.MediaMinDescriptionChars,
|
||||
MaxDescriptionChars: defaults.MediaMaxDescriptionChars,
|
||||
},
|
||||
StorageConfig: &StorageConfig{
|
||||
Backend: defaults.StorageBackend,
|
||||
BasePath: defaults.StorageBasePath,
|
||||
ServeProtocol: defaults.StorageServeProtocol,
|
||||
ServeHost: defaults.StorageServeHost,
|
||||
ServeBasePath: defaults.StorageServeBasePath,
|
||||
},
|
||||
StatusesConfig: &StatusesConfig{
|
||||
MaxChars: defaults.StatusesMaxChars,
|
||||
CWMaxChars: defaults.StatusesCWMaxChars,
|
||||
PollMaxOptions: defaults.StatusesPollMaxOptions,
|
||||
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
|
||||
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Default returns a config with all default values set
|
||||
func Default() *Config {
|
||||
defaults := GetDefaults()
|
||||
return &Config{
|
||||
LogLevel: defaults.LogLevel,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
Host: defaults.Host,
|
||||
Protocol: defaults.Protocol,
|
||||
DBConfig: &DBConfig{
|
||||
Type: defaults.DbType,
|
||||
Address: defaults.DbAddress,
|
||||
Port: defaults.DbPort,
|
||||
User: defaults.DbUser,
|
||||
Password: defaults.DbPassword,
|
||||
Database: defaults.DbDatabase,
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
},
|
||||
TemplateConfig: &TemplateConfig{
|
||||
BaseDir: defaults.TemplateBaseDir,
|
||||
},
|
||||
AccountsConfig: &AccountsConfig{
|
||||
OpenRegistration: defaults.AccountsOpenRegistration,
|
||||
RequireApproval: defaults.AccountsRequireApproval,
|
||||
ReasonRequired: defaults.AccountsReasonRequired,
|
||||
},
|
||||
MediaConfig: &MediaConfig{
|
||||
MaxImageSize: defaults.MediaMaxImageSize,
|
||||
MaxVideoSize: defaults.MediaMaxVideoSize,
|
||||
MinDescriptionChars: defaults.MediaMinDescriptionChars,
|
||||
MaxDescriptionChars: defaults.MediaMaxDescriptionChars,
|
||||
},
|
||||
StorageConfig: &StorageConfig{
|
||||
Backend: defaults.StorageBackend,
|
||||
BasePath: defaults.StorageBasePath,
|
||||
ServeProtocol: defaults.StorageServeProtocol,
|
||||
ServeHost: defaults.StorageServeHost,
|
||||
ServeBasePath: defaults.StorageServeBasePath,
|
||||
},
|
||||
StatusesConfig: &StatusesConfig{
|
||||
MaxChars: defaults.StatusesMaxChars,
|
||||
CWMaxChars: defaults.StatusesCWMaxChars,
|
||||
PollMaxOptions: defaults.StatusesPollMaxOptions,
|
||||
PollOptionMaxChars: defaults.StatusesPollOptionMaxChars,
|
||||
MaxMediaFiles: defaults.StatusesMaxMediaFiles,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func GetDefaults() Defaults {
|
||||
return Defaults{
|
||||
LogLevel: "info",
|
||||
ApplicationName: "gotosocial",
|
||||
ConfigPath: "",
|
||||
Host: "",
|
||||
Protocol: "https",
|
||||
|
||||
DbType: "postgres",
|
||||
DbAddress: "localhost",
|
||||
DbPort: 5432,
|
||||
DbUser: "postgres",
|
||||
DbPassword: "postgres",
|
||||
DbDatabase: "postgres",
|
||||
|
||||
TemplateBaseDir: "./web/template/",
|
||||
|
||||
AccountsOpenRegistration: true,
|
||||
AccountsRequireApproval: true,
|
||||
AccountsReasonRequired: true,
|
||||
|
||||
MediaMaxImageSize: 2097152, //2mb
|
||||
MediaMaxVideoSize: 10485760, //10mb
|
||||
MediaMinDescriptionChars: 0,
|
||||
MediaMaxDescriptionChars: 500,
|
||||
|
||||
StorageBackend: "local",
|
||||
StorageBasePath: "/gotosocial/storage",
|
||||
StorageServeProtocol: "https",
|
||||
StorageServeHost: "localhost",
|
||||
StorageServeBasePath: "/fileserver",
|
||||
|
||||
StatusesMaxChars: 5000,
|
||||
StatusesCWMaxChars: 100,
|
||||
StatusesPollMaxOptions: 6,
|
||||
StatusesPollOptionMaxChars: 50,
|
||||
StatusesMaxMediaFiles: 6,
|
||||
}
|
||||
}
|
||||
|
||||
func GetTestDefaults() Defaults {
|
||||
return Defaults{
|
||||
LogLevel: "trace",
|
||||
ApplicationName: "gotosocial",
|
||||
ConfigPath: "",
|
||||
Host: "localhost:8080",
|
||||
Protocol: "http",
|
||||
|
||||
DbType: "postgres",
|
||||
DbAddress: "localhost",
|
||||
DbPort: 5432,
|
||||
DbUser: "postgres",
|
||||
DbPassword: "postgres",
|
||||
DbDatabase: "postgres",
|
||||
|
||||
TemplateBaseDir: "./web/template/",
|
||||
|
||||
AccountsOpenRegistration: true,
|
||||
AccountsRequireApproval: true,
|
||||
AccountsReasonRequired: true,
|
||||
|
||||
MediaMaxImageSize: 1048576, //1mb
|
||||
MediaMaxVideoSize: 5242880, //5mb
|
||||
MediaMinDescriptionChars: 0,
|
||||
MediaMaxDescriptionChars: 500,
|
||||
|
||||
StorageBackend: "local",
|
||||
StorageBasePath: "/gotosocial/storage",
|
||||
StorageServeProtocol: "http",
|
||||
StorageServeHost: "localhost:8080",
|
||||
StorageServeBasePath: "/fileserver",
|
||||
|
||||
StatusesMaxChars: 5000,
|
||||
StatusesCWMaxChars: 100,
|
||||
StatusesPollMaxOptions: 6,
|
||||
StatusesPollOptionMaxChars: 50,
|
||||
StatusesMaxMediaFiles: 6,
|
||||
}
|
||||
}
|
||||
@ -24,4 +24,8 @@ type MediaConfig struct {
|
||||
MaxImageSize int `yaml:"maxImageSize"`
|
||||
// Max size of uploaded video in bytes
|
||||
MaxVideoSize int `yaml:"maxVideoSize"`
|
||||
// Minimum amount of chars required in an image description
|
||||
MinDescriptionChars int `yaml:"minDescriptionChars"`
|
||||
// Max amount of chars allowed in an image description
|
||||
MaxDescriptionChars int `yaml:"maxDescriptionChars"`
|
||||
}
|
||||
|
||||
33
internal/config/statuses.go
Normal file
33
internal/config/statuses.go
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
GoToSocial
|
||||
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
// StatusesConfig pertains to posting/deleting/interacting with statuses
|
||||
type StatusesConfig struct {
|
||||
// Maximum amount of characters allowed in a status, excluding CW
|
||||
MaxChars int `yaml:"max_chars"`
|
||||
// Maximum amount of characters allowed in a content-warning/spoiler field
|
||||
CWMaxChars int `yaml:"cw_max_chars"`
|
||||
// Maximum number of options allowed in a poll
|
||||
PollMaxOptions int `yaml:"poll_max_options"`
|
||||
// Maximum characters allowed per poll option
|
||||
PollOptionMaxChars int `yaml:"poll_option_max_chars"`
|
||||
// Maximum amount of media files allowed to be attached to one status
|
||||
MaxMediaFiles int `yaml:"max_media_files"`
|
||||
}
|
||||
Reference in New Issue
Block a user