feat: support output
This commit is contained in:
@@ -4,5 +4,6 @@ app_hash: bc7a2f7b8893889ffa6115f5f0eac278
|
|||||||
bot_token:
|
bot_token:
|
||||||
session_file: ./session.json
|
session_file: ./session.json
|
||||||
log_file: ./log.json
|
log_file: ./log.json
|
||||||
max_size: 50M
|
output: /share/telegram/outputs
|
||||||
|
max_size: 50MB
|
||||||
dsn: "postgresql://postgres:xixi0202@10.1.1.3:5432/telegram_resource?sslmode=disable"
|
dsn: "postgresql://postgres:xixi0202@10.1.1.3:5432/telegram_resource?sslmode=disable"
|
||||||
@@ -16,12 +16,13 @@ type Config struct {
|
|||||||
LogFile string `mapstructure:"log_file"`
|
LogFile string `mapstructure:"log_file"`
|
||||||
MaxSize string `mapstructure:"max_size"`
|
MaxSize string `mapstructure:"max_size"`
|
||||||
DSN string `mapstructure:"dsn"`
|
DSN string `mapstructure:"dsn"`
|
||||||
|
Outputs string `mapstructure:"outputs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMaxSize
|
// GetMaxSize
|
||||||
func (c *Config) GetMaxSize() uint {
|
func (c *Config) GetMaxSize() uint {
|
||||||
// parse 50m to 50 * 1024 * 1024
|
// parse 50mb to 50 * 1024 * 1024
|
||||||
return viper.GetSizeInBytes(c.MaxSize)
|
return viper.GetSizeInBytes("max_size")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(path string) error {
|
func Load(path string) error {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"exporter/config"
|
||||||
"exporter/database/telegram_resource/public/model"
|
"exporter/database/telegram_resource/public/model"
|
||||||
"exporter/database/telegram_resource/public/table"
|
"exporter/database/telegram_resource/public/table"
|
||||||
|
|
||||||
@@ -38,7 +39,8 @@ func NewDBChannel(uuid int64, username, title string) *DBChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *DBChannel) Asset(assetID int64, ext string) string {
|
func (c *DBChannel) Asset(assetID int64, ext string) string {
|
||||||
assetFile := fmt.Sprintf("outputs/%d/%d.%s", c.UUID, assetID, strings.Trim(ext, "."))
|
assetFile := fmt.Sprintf("%d/%d.%s", c.UUID, assetID, strings.Trim(ext, "."))
|
||||||
|
assetFile = filepath.Join(config.C.Outputs, assetFile)
|
||||||
|
|
||||||
// if file dir not exists then create it
|
// if file dir not exists then create it
|
||||||
if _, err := os.Stat(filepath.Dir(assetFile)); os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Dir(assetFile)); os.IsNotExist(err) {
|
||||||
|
|||||||
15
main_test.go
15
main_test.go
@@ -3,6 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"mime"
|
"mime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/dustin/go-humanize"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Mime(t *testing.T) {
|
func Test_Mime(t *testing.T) {
|
||||||
@@ -12,3 +15,15 @@ func Test_Mime(t *testing.T) {
|
|||||||
|
|
||||||
t.Log(mime.ExtensionsByType(m))
|
t.Log(mime.ExtensionsByType(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Size(t *testing.T) {
|
||||||
|
// Test code here
|
||||||
|
s := 6456390
|
||||||
|
t.Logf("Size: %d", s)
|
||||||
|
t.Logf("Human: %s", humanize.Bytes(uint64(s)))
|
||||||
|
|
||||||
|
viper.Set("size", "20MB")
|
||||||
|
b := viper.GetSizeInBytes("size")
|
||||||
|
t.Logf("Size: %d", s)
|
||||||
|
t.Logf("Vize: %d", b)
|
||||||
|
}
|
||||||
|
|||||||
2
outputs/.gitignore
vendored
2
outputs/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
*
|
|
||||||
!.gitignore
|
|
||||||
Reference in New Issue
Block a user