Compare commits

...

6 Commits

Author SHA1 Message Date
Bel LaPointe
5174a876ef maybe cookies are lowkey one header but delimited 2022-01-27 16:59:42 -07:00
bel
2ef92d25db Merge branch 'master' of http://gogs.scratch.com:59515/bel/truckstop 2022-01-27 16:35:08 -07:00
Bel LaPointe
d456de12e8 logs but no changes 2022-01-27 16:34:53 -07:00
Bel LaPointe
c56acbc120 Merge branch 'master' of http://gogs.scratch.com:59515/bel/truckstop 2022-01-27 16:24:21 -07:00
Bel LaPointe
ae4c5bd886 backward compatible from ID to uid for sent_jobs 2022-01-27 16:22:58 -07:00
bel
bee6fcfc8d log because i think i deploy bad 2022-01-27 16:05:17 -07:00
5 changed files with 34 additions and 23 deletions

View File

@@ -42,9 +42,14 @@ func _do(db storage.DB, r *http.Request) (*http.Response, error) {
logtr.Errorf("failed to get cookies: %v", err) logtr.Errorf("failed to get cookies: %v", err)
} else { } else {
logtr.Verbosef("got cookies for %s: %+v", cookieJarKey, cookies) logtr.Verbosef("got cookies for %s: %+v", cookieJarKey, cookies)
cookieV := strings.Join(r.Header["Cookie"], "; ")
for _, cookie := range cookies { for _, cookie := range cookies {
r.Header.Add("Cookie", cookie) if len(cookieV) > 0 {
cookieV += "; "
}
cookieV += cookie
} }
r.Header.Set("Cookie", cookieV)
} }
logtr.Verbosef("_do: %+v", r) logtr.Verbosef("_do: %+v", r)
resp, err := client.Do(r) resp, err := client.Do(r)
@@ -75,13 +80,15 @@ func setCookies(db storage.DB, host string, resp *http.Response) error {
continue continue
} }
name := strings.Split(value, "=")[0] name := strings.Split(value, "=")[0]
value := strings.Split(value, ";")[0]
nameValues = append(nameValues, [2]string{name, value}) nameValues = append(nameValues, [2]string{name, value})
} }
for _, value := range resp.Header["Set-Cookie"] { for _, cookie := range resp.Header["Set-Cookie"] {
if len(value) == 0 { if len(cookie) == 0 {
continue continue
} }
name := strings.Split(value, "=")[0] name := strings.Split(cookie, "=")[0]
value := strings.Split(cookie, ";")[0]
found := false found := false
for i := range nameValues { for i := range nameValues {
if nameValues[i][0] == name { if nameValues[i][0] == name {

View File

@@ -32,9 +32,9 @@ func TestDoCookies(t *testing.T) {
if calls != 1 { if calls != 1 {
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value"+strconv.Itoa(calls-1)) { if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value"+strconv.Itoa(calls-1)) {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
t.Error("cookie not set as latest") t.Error("cookie not set as latest: " + fmt.Sprint(r.Header["Cookie"]))
} }
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "Expires") { if strings.Contains(fmt.Sprint(r.Header["Cookie"]), "Expires") {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
t.Error("cookie not expiration: ", r.Header["Cookie"]) t.Error("cookie not expiration: ", r.Header["Cookie"])
} }

View File

@@ -34,7 +34,7 @@
"Pickup": false, "Pickup": false,
"Dropoff": false, "Dropoff": false,
"Pathed": { "Pathed": {
"Enabled": true, "Enabled": false,
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg", "DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s", "PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s",
"Zoom": { "Zoom": {
@@ -69,17 +69,17 @@
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top" "Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
} }
}, },
"Once": true, "Once": false,
"Brokers": { "Brokers": {
"FastExact": { "FastExact": {
"RadiusMiles": 100, "RadiusMiles": 100,
"Enabled": true, "Enabled": true,
"Mock": true, "Mock": true,
"Username": "u", "Username": "birdman",
"Password": "p" "Password": "166647"
}, },
"NTG": { "NTG": {
"Enabled": true, "Enabled": false,
"JobInfo": true, "JobInfo": true,
"Mock": true, "Mock": true,
"LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d", "LoadPageURIFormat": "https://ntgvision.com/LoadDetails?loadId=%d",

17
main.go
View File

@@ -303,7 +303,7 @@ func once() error {
if ok, err := sendJob(jobs[i]); err != nil { if ok, err := sendJob(jobs[i]); err != nil {
return err return err
} else if ok { } else if ok {
logtr.Debugf("sent job", jobs[i]) logtr.Debugf("sent job %+v", jobs[i])
if err := db.Set(jobs[i].UID(), []byte(`sent`)); err != nil { if err := db.Set(jobs[i].UID(), []byte(`sent`)); err != nil {
return err return err
} }
@@ -316,11 +316,14 @@ func getJobs() ([]broker.Job, error) {
states := config.AllStates() states := config.AllStates()
brokers := []broker.Broker{} brokers := []broker.Broker{}
if config.Get().Brokers.NTG.Enabled { if config.Get().Brokers.NTG.Enabled {
logtr.Debugf("NTG enabled")
brokers = append(brokers, broker.NewNTGVision()) brokers = append(brokers, broker.NewNTGVision())
} }
if config.Get().Brokers.FastExact.Enabled { if config.Get().Brokers.FastExact.Enabled {
logtr.Debugf("FastExact enabled")
brokers = append(brokers, broker.NewFastExact()) brokers = append(brokers, broker.NewFastExact())
} }
logtr.Debugf("brokers=%+v", brokers)
jobs := []broker.Job{} jobs := []broker.Job{}
for _, broker := range brokers { for _, broker := range brokers {
somejobs, err := broker.Search(states) somejobs, err := broker.Search(states)
@@ -349,7 +352,7 @@ func updateDeadJobs(jobs []broker.Job) error {
wouldBe := strings.TrimPrefix(listEntry, "sent_job_") wouldBe := strings.TrimPrefix(listEntry, "sent_job_")
found := false found := false
for i := range jobs { for i := range jobs {
found = found || jobs[i].ID == wouldBe found = found || jobs[i].UID() == wouldBe || jobs[i].ID == wouldBe
} }
logtr.Debugf("found job %s to be still alive==%v", wouldBe, found) logtr.Debugf("found job %s to be still alive==%v", wouldBe, found)
if !found { if !found {
@@ -368,14 +371,14 @@ func updateDeadJobs(jobs []broker.Job) error {
} }
*/ */
if err := message.NewMatrix().Remove(recorded.MatrixID); err != nil { if err := message.NewMatrix().Remove(recorded.MatrixID); err != nil {
return err logtr.Debugf("failed to remove matrix: %v: %v", recorded.MatrixID, err)
} }
if err := db.Set(listEntry, nil); err != nil { if err := db.Set(listEntry, nil); err != nil {
return err logtr.Debugf("failed to remove db: %v: %v", listEntry, err)
} }
for _, imageid := range recorded.MatrixImageIDs { for _, imageid := range recorded.MatrixImageIDs {
if err := message.NewMatrix().Remove(imageid); err != nil { if err := message.NewMatrix().Remove(imageid); err != nil {
return err logtr.Debugf("failed to remove matrix image: %v: %v", imageid, err)
} }
} }
} }
@@ -404,7 +407,7 @@ func dropBanlistJobs(jobs []broker.Job) ([]broker.Job, error) {
func sendJob(job broker.Job) (bool, error) { func sendJob(job broker.Job) (bool, error) {
sender := message.NewMatrix() sender := message.NewMatrix()
payload := job.FormatMultilineText() payload := job.FormatMultilineText()
logtr.Debugf("once: send job %s if nonzero: %s", job.String(), payload) logtr.Debugf("once: send job %s if nonzero: %q", job.String(), payload)
if len(payload) == 0 { if len(payload) == 0 {
return false, nil return false, nil
} }
@@ -424,7 +427,7 @@ func sendJob(job broker.Job) (bool, error) {
logtr.Errorf("failed to marshal recorded job: %v", err) logtr.Errorf("failed to marshal recorded job: %v", err)
return return
} }
if err := db.Set("sent_job_"+job.ID, b); err != nil { if err := db.Set("sent_job_"+job.UID(), b); err != nil {
logtr.Errorf("failed to set recorded job: %v", err) logtr.Errorf("failed to set recorded job: %v", err)
return return
} }

View File

@@ -1,20 +1,21 @@
todo: todo:
- !states emits current state - fast exact is dumb or...?
- TEST. Just like, refactor and test to shit. - modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
- try search ntg by autoinc? - more than NTG; blue one
- !states emits current state
- test each !command callbacks to matrix - test each !command callbacks to matrix
- recv-as for clients so pa receives mas commands as writes - recv-as for clients so pa receives mas commands as writes
- continuation is garbo, but I can still do better client side to avoid get-set high level - continuation is garbo, but I can still do better client side to avoid get-set high level
- no hard code jpeg or have it in multiple places - no hard code jpeg or have it in multiple places
- change matrix so I test my custom logic even if I dont fetch remote - change matrix so I test my custom logic even if I dont fetch remote
- warn/err/etc. on clobbering ids.matrix since clients can mess with one another - warn/err/etc. on clobbering ids.matrix since clients can mess with one another
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
- more than NTG
- todo: filter out jobs like CA - todo: filter out jobs like CA
subtasks: subtasks:
- banlist criteria like vendors, brokers, metadata - banlist criteria like vendors, brokers, metadata
- set up copy for caleb, broc - set up copy for caleb, broc
done: done:
- try search ntg by autoinc?
- TEST. Just like, refactor and test to shit.
- mark jobs no longer avail by modifying in matrix;; save matrix ID over dummy payload - mark jobs no longer avail by modifying in matrix;; save matrix ID over dummy payload
- TEST its falling apart - TEST its falling apart
- help() log on truckstop for stuff like perma 403 - help() log on truckstop for stuff like perma 403