diff options
| author | 2026-08-01 19:58:57 +0700 | |
|---|---|---|
| committer | 2026-08-01 19:58:57 +0700 | |
| commit | 684d0b6a57d2eb79730ade63baccdc6e59bebc29 (patch) | |
| tree | 956c89c81965b8c974c8497e3719d0b16d332512 /config | |
| parent | 129e48683f6fc0615b606a737f2afcd50538bb2e (diff) | |
| download | articlator-684d0b6a57d2eb79730ade63baccdc6e59bebc29.tar.gz articlator-684d0b6a57d2eb79730ade63baccdc6e59bebc29.zip | |
feat: repurpose metadata parser as article transcoder for saya.uz andmain
telegram
Diffstat (limited to 'config')
| -rw-r--r-- | config/config.go | 64 | ||||
| -rw-r--r-- | config/config.json | 20 |
2 files changed, 55 insertions, 29 deletions
diff --git a/config/config.go b/config/config.go index 543413f..64d2e76 100644 --- a/config/config.go +++ b/config/config.go @@ -10,17 +10,63 @@ import ( ) type Config struct { - LogLevel slog.Level `json:"LogLevel" validate:"required"` - MaxConcurrentJobs int `json:"MaxConcurrentJobs" validate:"required,min=1"` - DraftMode DraftModeConfig `json:"DraftMode"` - Storage StorageConfig `json:"Storage" validate:"required"` + LogLevel slog.Level `json:"LogLevel" validate:"required"` + MaxConcurrentJobs int `json:"MaxConcurrentJobs" validate:"required,min=1"` + DraftDir string `json:"DraftDir" validate:"required"` + DraftSuffix string `json:"DraftSuffix" validate:"required"` + Transcoders []TranscoderConfig `json:"Transcoders" validate:"required,min=1,dive"` } -type DraftModeConfig struct { - Enabled bool `json:"Enabled" validate:"required"` - DraftSuffix string `json:"DraftSuffix" validate:"required_if=Enabled true"` - ProdSuffix string `json:"ProdSuffix" validate:"required_if=Enabled true"` - UpdateAlways bool `json:"UpdateAlways"` +type TranscoderConfig struct { + Type string `json:"Type" validate:"required,oneof=sayauz telegram"` + Config any `json:"Config" validate:"required"` +} + +func (tc *TranscoderConfig) UnmarshalJSON(data []byte) error { + var tmp struct { + Type string `json:"Type"` + Config json.RawMessage `json:"Config"` + } + + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + + tc.Type = tmp.Type + + switch tmp.Type { + case "sayauz": + var sayauzConfig SayauzConfig + if err := json.Unmarshal(tmp.Config, &sayauzConfig); err != nil { + return fmt.Errorf("unmarshal SayauzConfig: %w", err) + } + tc.Config = &sayauzConfig + case "telegram": + var telegramConfig TelegramConfig + if err := json.Unmarshal(tmp.Config, &telegramConfig); err != nil { + return fmt.Errorf("unmarshal TelegramConfig: %w", err) + } + tc.Config = &telegramConfig + default: + return fmt.Errorf("unsupported transcoder type: %s", tmp.Type) + } + + return nil +} + +type SayauzConfig struct { + Category string `json:"Category" validate:"required,min=1"` + Storage StorageConfig `json:"Storage" validate:"required"` +} + +type TelegramConfig struct { + BotToken string `json:"BotToken" validate:"required,min=1"` + ChannelID int `json:"ChannelID" validate:"required,ne=0"` + GroupID int `json:"GroupID"` + ImageBaseURL string `json:"ImageBaseURL" validate:"required,min=1"` + PreviewBaseURL string `json:"PreviewBaseURL"` + PreviewExtension string `json:"PreviewExtension"` + StateDir string `json:"StateDir" validate:"required,min=1"` } type StorageConfig struct { diff --git a/config/config.json b/config/config.json deleted file mode 100644 index 985dd55..0000000 --- a/config/config.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "LogLevel": "debug", - "MaxConcurrentJobs": 10, - "DraftMode": { - "Enabled": true, - "DraftSuffix": ".draft.md", - "ProdSuffix": ".md", - "UpdateAlways": false - }, - "Storage": { - "Type": "b2", - "Config": { - "BucketName": "sayana-pages", - "Region": "eu-central-003", - "Prefix": "", - "KeyID": "${B2_KEY_ID}", - "ApplicationKey": "${B2_APPLICATION_KEY}" - } - } -}
\ No newline at end of file |