feat: support output

This commit is contained in:
Rogee
2024-09-02 23:55:40 +08:00
parent e953d41e7a
commit 3f1197e5d4
5 changed files with 23 additions and 6 deletions

View File

@@ -4,5 +4,6 @@ app_hash: bc7a2f7b8893889ffa6115f5f0eac278
bot_token:
session_file: ./session.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"

View File

@@ -16,12 +16,13 @@ type Config struct {
LogFile string `mapstructure:"log_file"`
MaxSize string `mapstructure:"max_size"`
DSN string `mapstructure:"dsn"`
Outputs string `mapstructure:"outputs"`
}
// GetMaxSize
func (c *Config) GetMaxSize() uint {
// parse 50m to 50 * 1024 * 1024
return viper.GetSizeInBytes(c.MaxSize)
// parse 50mb to 50 * 1024 * 1024
return viper.GetSizeInBytes("max_size")
}
func Load(path string) error {

View File

@@ -8,6 +8,7 @@ import (
"strings"
"time"
"exporter/config"
"exporter/database/telegram_resource/public/model"
"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 {
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 _, err := os.Stat(filepath.Dir(assetFile)); os.IsNotExist(err) {

View File

@@ -3,6 +3,9 @@ package main
import (
"mime"
"testing"
"github.com/dustin/go-humanize"
"github.com/spf13/viper"
)
func Test_Mime(t *testing.T) {
@@ -12,3 +15,15 @@ func Test_Mime(t *testing.T) {
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
View File

@@ -1,2 +0,0 @@
*
!.gitignore