Skip to content

Commit 683b5d2

Browse files
committed
2 parents b6acbbb + 7b64b9d commit 683b5d2

6 files changed

Lines changed: 162 additions & 102 deletions

File tree

env/index.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package env
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"log"
78
"os"
89
"path/filepath"
10+
"slices"
911
"strconv"
1012

1113
"github.com/joho/godotenv"
@@ -46,7 +48,9 @@ var (
4648
const ServerConfigFileName = "server.config.json"
4749

4850
func init() {
49-
godotenv.Load()
51+
CurrentDirectory = FindAndReturnCurrentDir()
52+
ServerConfig = ReadConfigFileAndReturnIt(CurrentDirectory)
53+
godotenv.Load(filepath.Join(CurrentDirectory, ".env"))
5054
PORT, err := strconv.Atoi(os.Getenv(port_KEY))
5155
if err != nil {
5256
panic("Please Pass Valid Port")
@@ -98,3 +102,43 @@ func (sc *IServerConfig) Save() {
98102
fmt.Printf("%v \n", err)
99103
}
100104
}
105+
106+
func FindAndReturnCurrentDir() string {
107+
currentDir := ""
108+
fmt.Println(len(os.Args), os.Args)
109+
if slices.Contains(os.Args, "--dev") {
110+
current, err := os.Getwd()
111+
Check(err)
112+
currentDir = current
113+
} else {
114+
exePath, err := os.Executable()
115+
currentDir = filepath.Dir(exePath)
116+
Check(err)
117+
}
118+
return currentDir
119+
}
120+
121+
func Check(e error) {
122+
if e != nil {
123+
panic(e)
124+
}
125+
}
126+
127+
func ReadConfigFileAndReturnIt(currentDir string) *IServerConfig {
128+
config := new(IServerConfig)
129+
configFilePAth := filepath.Join(currentDir, ServerConfigFileName)
130+
if _, err := os.Stat(configFilePAth); errors.Is(err, os.ErrNotExist) {
131+
panic(fmt.Errorf("CONFIG_NOT_EXIST_ON_PATH %s", configFilePAth))
132+
}
133+
dat, err := os.ReadFile(configFilePAth)
134+
Check(err)
135+
err = json.Unmarshal(dat, config)
136+
Check(err)
137+
if errs := validator.Validator.Validate(config); len(errs) > 0 {
138+
panic(fmt.Errorf("CONFIG_ERROR %#v", errs))
139+
}
140+
if config.JID == nil {
141+
config.JID = make(map[string]string)
142+
}
143+
return config
144+
}

go.mod

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@ module github.com/rpsoftech/whatsapp-http-api
33
go 1.22.1
44

55
require (
6-
github.com/gen2brain/go-fitz v1.23.7
7-
github.com/go-playground/validator/v10 v10.22.1
6+
github.com/gen2brain/go-fitz v1.24.14
7+
github.com/go-playground/validator/v10 v10.23.0
88
github.com/gofiber/fiber/v2 v2.52.5
99
github.com/google/uuid v1.6.0
1010
github.com/joho/godotenv v1.5.1
11-
github.com/mattn/go-sqlite3 v1.14.23
11+
github.com/mattn/go-sqlite3 v1.14.24
1212
github.com/mdp/qrterminal/v3 v3.2.0
1313
github.com/prplecake/go-thumbnail v0.1.6
1414
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
15-
go.mau.fi/whatsmeow v0.0.0-20240917093958-061c065cc1ee
16-
google.golang.org/protobuf v1.34.2
15+
go.mau.fi/whatsmeow v0.0.0-20241116141054-92458da42ba3
16+
google.golang.org/protobuf v1.35.2
1717
)
1818

1919
require (
2020
filippo.io/edwards25519 v1.1.0 // indirect
21-
github.com/andybalholm/brotli v1.1.0 // indirect
22-
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
21+
github.com/andybalholm/brotli v1.1.1 // indirect
22+
github.com/ebitengine/purego v0.8.0 // indirect
23+
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
2324
github.com/go-playground/locales v0.14.1 // indirect
2425
github.com/go-playground/universal-translator v0.18.1 // indirect
2526
github.com/google/go-cmp v0.5.9 // indirect
2627
github.com/gorilla/websocket v1.5.3 // indirect
27-
github.com/klauspost/compress v1.17.9 // indirect
28+
github.com/jupiterrider/ffi v0.2.0 // indirect
29+
github.com/klauspost/compress v1.17.11 // indirect
2830
github.com/leodido/go-urn v1.4.0 // indirect
2931
github.com/mattn/go-colorable v0.1.13 // indirect
3032
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -33,15 +35,15 @@ require (
3335
github.com/rivo/uniseg v0.4.7 // indirect
3436
github.com/rs/zerolog v1.33.0 // indirect
3537
github.com/valyala/bytebufferpool v1.0.0 // indirect
36-
github.com/valyala/fasthttp v1.55.0 // indirect
38+
github.com/valyala/fasthttp v1.57.0 // indirect
3739
github.com/valyala/tcplisten v1.0.0 // indirect
3840
go.mau.fi/libsignal v0.1.1 // indirect
39-
go.mau.fi/util v0.8.0 // indirect
40-
golang.org/x/crypto v0.27.0 // indirect
41-
golang.org/x/image v0.20.0 // indirect
42-
golang.org/x/net v0.29.0 // indirect
43-
golang.org/x/sys v0.25.0 // indirect
44-
golang.org/x/term v0.24.0 // indirect
45-
golang.org/x/text v0.18.0 // indirect
41+
go.mau.fi/util v0.8.2 // indirect
42+
golang.org/x/crypto v0.29.0 // indirect
43+
golang.org/x/image v0.19.0 // indirect
44+
golang.org/x/net v0.31.0 // indirect
45+
golang.org/x/sys v0.27.0 // indirect
46+
golang.org/x/term v0.26.0 // indirect
47+
golang.org/x/text v0.20.0 // indirect
4648
rsc.io/qr v0.2.0 // indirect
4749
)

go.sum

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
22
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
3-
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
4-
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
3+
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
4+
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
55
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
66
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
77
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8-
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
9-
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
10-
github.com/gen2brain/go-fitz v1.23.7 h1:HPhzEVzmOINvCKqQgB/DwMzYh4ArIgy3tMwq1eJTcbg=
11-
github.com/gen2brain/go-fitz v1.23.7/go.mod h1:HU04vc+RisUh/kvEd2pB0LAxmK1oyXdN4ftyshUr9rQ=
8+
github.com/ebitengine/purego v0.8.0 h1:JbqvnEzRvPpxhCJzJJ2y0RbiZ8nyjccVUrSM3q+GvvE=
9+
github.com/ebitengine/purego v0.8.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
10+
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
11+
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
12+
github.com/gen2brain/go-fitz v1.24.14 h1:09weRkjVtLYNGo7l0J7DyOwBExbwi8SJ9h8YPhw9WEo=
13+
github.com/gen2brain/go-fitz v1.24.14/go.mod h1:0KaZeQgASc20Yp5R/pFzyy7SmP01XcoHKNF842U2/S4=
1214
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
1315
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
1416
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
1517
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
1618
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
1719
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
18-
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
19-
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
20+
github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o=
21+
github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
2022
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
2123
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
2224
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
@@ -28,8 +30,10 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
2830
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
2931
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
3032
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
31-
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
32-
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
33+
github.com/jupiterrider/ffi v0.2.0 h1:tMM70PexgYNmV+WyaYhJgCvQAvtTCs3wXeILPutihnA=
34+
github.com/jupiterrider/ffi v0.2.0/go.mod h1:yqYqX5DdEccAsHeMn+6owkoI2llBLySVAF8dwCDZPVs=
35+
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
36+
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
3337
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
3438
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
3539
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
@@ -40,8 +44,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
4044
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
4145
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
4246
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
43-
github.com/mattn/go-sqlite3 v1.14.23 h1:gbShiuAP1W5j9UOksQ06aiiqPMxYecovVGwmTxWtuw0=
44-
github.com/mattn/go-sqlite3 v1.14.23/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
47+
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
48+
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
4549
github.com/mdp/qrterminal/v3 v3.2.0 h1:qteQMXO3oyTK4IHwj2mWsKYYRBOp1Pj2WRYFYYNTCdk=
4650
github.com/mdp/qrterminal/v3 v3.2.0/go.mod h1:XGGuua4Lefrl7TLEsSONiD+UEjQXJZ4mPzF+gWYIJkk=
4751
github.com/pdfcpu/pdfcpu v0.8.1 h1:AiWUb8uXlrXqJ73OmiYXBjDF0Qxt4OuM281eAfkAOMA=
@@ -63,36 +67,38 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
6367
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
6468
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
6569
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
66-
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
67-
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
70+
github.com/valyala/fasthttp v1.57.0 h1:Xw8SjWGEP/+wAAgyy5XTvgrWlOD1+TxbbvNADYCm1Tg=
71+
github.com/valyala/fasthttp v1.57.0/go.mod h1:h6ZBaPRlzpZ6O3H5t2gEk1Qi33+TmLvfwgLLp0t9CpE=
6872
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
6973
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
74+
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
75+
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
7076
go.mau.fi/libsignal v0.1.1 h1:m/0PGBh4QKP/I1MQ44ti4C0fMbLMuHb95cmDw01FIpI=
7177
go.mau.fi/libsignal v0.1.1/go.mod h1:QLs89F/OA3ThdSL2Wz2p+o+fi8uuQUz0e1BRa6ExdBw=
72-
go.mau.fi/util v0.8.0 h1:MiSny8jgQq4XtCLAT64gDJhZVhqiDeMVIEBDFVw+M0g=
73-
go.mau.fi/util v0.8.0/go.mod h1:1Ixb8HWoVbl3rT6nAX6nV4iMkzn7KU/KXwE0Rn5RmsQ=
74-
go.mau.fi/whatsmeow v0.0.0-20240917093958-061c065cc1ee h1:wP8wJwD9lRqEeWQsWg9z6dnW5FKMi6rU7hJO+BEfaa0=
75-
go.mau.fi/whatsmeow v0.0.0-20240917093958-061c065cc1ee/go.mod h1:BhHKalSq0qNtSCuGIUIvoJyU5KbT4a7k8DQ5yw1Ssk4=
76-
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
77-
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
78+
go.mau.fi/util v0.8.2 h1:zWbVHwdRKwI6U9AusmZ8bwgcLosikwbb4GGqLrNr1YE=
79+
go.mau.fi/util v0.8.2/go.mod h1:BHHC9R2WLMJd1bwTZfTcFxUgRFmUgUmiWcT4RbzUgiA=
80+
go.mau.fi/whatsmeow v0.0.0-20241116141054-92458da42ba3 h1:5BTCMPMvWcEJ+BIvci8S2+yqe09XIRqRYPt4SgB9y5o=
81+
go.mau.fi/whatsmeow v0.0.0-20241116141054-92458da42ba3/go.mod h1:iB+F/NVNOnyumU2p/TKTSSdBhH05GHFG36diYuFp9VQ=
82+
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
83+
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
7884
golang.org/x/image v0.0.0-20220302094943-723b81ca9867/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
79-
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
80-
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
81-
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
82-
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
85+
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
86+
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
87+
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
88+
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
8389
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8490
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
8591
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
86-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
87-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
88-
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
89-
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
92+
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
93+
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
94+
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
95+
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
9096
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
91-
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
92-
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
97+
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
98+
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
9399
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
94-
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
95-
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
100+
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
101+
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
96102
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
97103
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
98104
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=

jwelly/main.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,25 @@ func CreateLogsFile() {
3232
}
3333

3434
func main() {
35-
fmt.Println(len(os.Args), os.Args)
35+
// args := os.Args
36+
// if !slices.Contains(args, "--dev") && !slices.Contains(args, "--prod") {
37+
// cmd := exec.Command(filepath.Join(FindAndReturnCurrentDir(), os.Args[0]), "--prod")
38+
// cmd.Stdout = os.Stdout
39+
// err := cmd.Start()
40+
// if err != nil {
41+
// log.Fatal(err)
42+
// }
43+
// log.Printf("Just ran subprocess %d, exiting\n", cmd.Process.Pid)
44+
// // time.Sleep(5 * time.Second)
45+
// return
46+
// }
3647
if _, err := os.Stat("./whatsapp.config"); err == nil {
3748
// path/to/whatever exists
3849
if res, err := os.ReadFile("./whatsapp.config"); err == nil {
3950
config = ReadConfigFileAndReturnIt(FindAndReturnCurrentDir())
4051
AfterWhatsappConfigFile(string(res))
4152
}
53+
// time.Sleep(8 * time.Second)
4254
} else if errors.Is(err, os.ErrNotExist) {
4355
// path/to/whatever does *not* exist
4456
AppendToOutPutFile("File Does Not Exist")
@@ -105,6 +117,16 @@ func AfterWhatsappConfigFile(data string) {
105117

106118
reqUrl := config.ServerUrl + "/send_media_64"
107119
if _, err := os.Stat(filePathToBeSend); err != nil {
120+
for i := 0; i < 15; i++ {
121+
_, err := os.Stat(filePathToBeSend)
122+
if err == nil {
123+
break
124+
}
125+
if errors.Is(err, os.ErrNotExist) {
126+
go AppendToOutPutFile("Waiting For File")
127+
time.Sleep(1 * time.Second)
128+
}
129+
}
108130
go AppendToOutPutFile(err.Error())
109131
return
110132
}
@@ -115,6 +137,21 @@ func AfterWhatsappConfigFile(data string) {
115137
return
116138
}
117139

140+
if len(fileBytes) <= 10 {
141+
for i := 0; i < 3; i++ {
142+
fileBytes, _ = os.ReadFile(filePathToBeSend)
143+
if len(fileBytes) <= 10 {
144+
go AppendToOutPutFile("Waiting For File")
145+
time.Sleep(5 * time.Second)
146+
} else {
147+
break
148+
}
149+
}
150+
if len(fileBytes) <= 10 {
151+
go AppendToOutPutFile("File Length <= 10")
152+
return
153+
}
154+
}
118155
base64File := base64.StdEncoding.EncodeToString(fileBytes)
119156

120157
postBody := fmt.Sprintf(`{"msg":"%s","fileName":"%s","to":["%s"],"base64":"%s"}`, messageToSend,
@@ -168,7 +205,6 @@ func AppendToOutPutFile(text string) {
168205

169206
func FindAndReturnCurrentDir() string {
170207
currentDir := ""
171-
fmt.Println(len(os.Args), os.Args)
172208
if slices.Contains(os.Args, "--dev") {
173209
current, err := os.Getwd()
174210
check(err)

0 commit comments

Comments
 (0)