Browse Source

feat: add storages config

pull/26/head
Aldino Kemal 3 years ago
parent
commit
e986e7dc07
  1. 1
      .gitignore
  2. 2
      src/cmd/root.go
  3. 21
      src/config/settings.go
  4. 6
      src/utils/whatsapp.go

1
.gitignore

@ -7,3 +7,4 @@ main
main.exe
*.jpe
src/pkged.go
storages

2
src/cmd/root.go

@ -47,7 +47,7 @@ func runRest(cmd *cobra.Command, args []string) {
// TODO: Init Rest App
//preparing folder if not exist
err := utils.CreateFolder(config.PathQrCode, config.PathSendItems)
err := utils.CreateFolder(config.PathQrCode, config.PathSendItems, config.PathStorages)
if err != nil {
log.Fatalln(err)
}

21
src/config/settings.go

@ -5,22 +5,21 @@ import (
waProto "go.mau.fi/whatsmeow/binary/proto"
)
type Browser string
var (
AppVersion string = "v3.6.0"
AppPort string = "3000"
AppDebug bool = false
AppOs string = fmt.Sprintf("AldinoKemal")
AppVersion = "v3.6.0"
AppPort = "3000"
AppDebug = false
AppOs = fmt.Sprintf("AldinoKemal")
AppPlatform = waProto.DeviceProps_PlatformType(1)
AppBasicAuthCredential string
AppPlatform waProto.DeviceProps_PlatformType = waProto.DeviceProps_PlatformType(1)
PathQrCode string = "statics/qrcode"
PathSendItems string = "statics/senditems"
PathQrCode = "statics/qrcode"
PathSendItems = "statics/senditems"
PathStorages = "storages"
DBName string = "hydrogenWaCli.db"
DBName = "hydrogenWaCli.db"
WhatsappLogLevel string = "ERROR"
WhatsappLogLevel = "ERROR"
WhatsappAutoReplyMessage string
WhatsappAutoReplyWebhook string
WhatsappSettingMaxFileSize int64 = 30000000 // 10MB

6
src/utils/whatsapp.go

@ -88,7 +88,7 @@ func InitWaDB() *sqlstore.Container {
// Running Whatsapp
log = waLog.Stdout("Main", config.WhatsappLogLevel, true)
dbLog := waLog.Stdout("Database", config.WhatsappLogLevel, true)
storeContainer, err := sqlstore.New("sqlite3", fmt.Sprintf("file:%s?_foreign_keys=off", config.DBName), dbLog)
storeContainer, err := sqlstore.New("sqlite3", fmt.Sprintf("file:%s/%s?_foreign_keys=off", config.PathStorages, config.DBName), dbLog)
if err != nil {
log.Errorf("Failed to connect to database: %v", err)
panic(err)
@ -171,7 +171,7 @@ func handler(rawEvt interface{}) {
return
}
exts, _ := mime.ExtensionsByType(img.GetMimetype())
path := fmt.Sprintf("%s%s", evt.Info.ID, exts[0])
path := fmt.Sprintf("%s/%s%s", config.PathStorages, evt.Info.ID, exts[0])
err = os.WriteFile(path, data, 0600)
if err != nil {
log.Errorf("Failed to save image: %v", err)
@ -207,7 +207,7 @@ func handler(rawEvt interface{}) {
}
case *events.HistorySync:
id := atomic.AddInt32(&historySyncID, 1)
fileName := fmt.Sprintf("history-%d-%d.json", startupTime, id)
fileName := fmt.Sprintf("%s/history-%d-%d.json", config.PathStorages, startupTime, id)
file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
log.Errorf("Failed to open file to write history sync: %v", err)

Loading…
Cancel
Save