From c01bd8d0c87b9ac804e347f26c12aac1c0763f10 Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Sun, 13 Nov 2022 12:24:25 +0700 Subject: [PATCH] feat: move file to storage folder (#26) * feat: add storages config * chore: update version * chore: update docs --- .gitignore | 1 + readme.md | 2 +- src/cmd/root.go | 2 +- src/config/settings.go | 21 ++++++++++----------- src/utils/whatsapp.go | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 4bb3c9e..5c7040f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ main main.exe *.jpe src/pkged.go +storages \ No newline at end of file diff --git a/readme.md b/readme.md index f3f47de..bd66f11 100644 --- a/readme.md +++ b/readme.md @@ -67,7 +67,7 @@ ### Production Mode (docker) -- `docker run --publish=3000:3000 --name=whatsapp --restart=always --detach aldinokemal2104/go-whatsapp-web-multidevice --autoreply="Dont't reply this message please"` +- `docker run --detach --publish=3000:3000 --name=whatsapp --restart=always --volume=$(docker volume create --name=whatsapp):/app/storages aldinokemal2104/go-whatsapp-web-multidevice --autoreply="Dont't reply this message please"` ### Production Mode (binary | not distributed again since v3.5.0) diff --git a/src/cmd/root.go b/src/cmd/root.go index 87f4d02..3f4c767 100644 --- a/src/cmd/root.go +++ b/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) } diff --git a/src/config/settings.go b/src/config/settings.go index 0de12b2..73c431f 100644 --- a/src/config/settings.go +++ b/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.7.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 diff --git a/src/utils/whatsapp.go b/src/utils/whatsapp.go index a2be5b4..97f06f1 100644 --- a/src/utils/whatsapp.go +++ b/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)