falling-fruit / falling-fruit-web

Mobile-friendly website for Falling Fruit
https://beta.fallingfruit.org
GNU General Public License v3.0
29 stars 7 forks source link

Can't update a review with a photo added from the old website #408

Closed wbazant closed 5 days ago

wbazant commented 2 weeks ago

Found during testing something else. I wanted to change the number of stars in a review with a photo, and got served a red toast. Doing the same to another review without the photo works fine.

Request copied as cURL:

curl 'https://beta.fallingfruit.org/api/0.3/reviews/65871?api_key=AKDJGHSD' -X PUT -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-GB,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NTcxODIsInJvbGVzIjpbInVzZXIiXSwianRpIjoiNzlhMjQ0ODQxZGUxIiwiaWF0IjoxNzE4ODkwMTA4LCJleHAiOjE3MTg4OTEwMDh9.KL9WC2DS2mLOglw-Iw3K5osnT5gUxrSSuLGCzzfeFl8' -H 'Origin: http://beta.fallingfruit.org' -H 'Connection: keep-alive' -H 'Referer: http://beta.fallingfruit.org/' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: cross-site' -H 'DNT: 1' -H 'Sec-GPC: 1' -H 'TE: trailers' --data-raw '{"comment":null,"observed_on":"2024-05-21","fruiting":null,"yield_rating":2,"quality_rating":2,"photo_ids":[76444]}'

Error received back:

{
  "data": {
    "error": "Photo URL not formatted as expected: https://s3.us-west-2.amazonaws.com/ff-production/observations/photos/000/065/871/thumb/upload.jpg"
  },
  "status": 400,
  "statusText": "Bad Request",
  "headers": {
    "content-length": "146",
    "content-type": "application/json; charset=utf-8"
  },
  "config": {
    "url": "/reviews/65871",
    "method": "put",
    "data": "{\"comment\":null,\"observed_on\":\"2024-05-21\",\"fruiting\":null,\"yield_rating\":2,\"quality_rating\":2,\"photo_ids\":[76444]}",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json",
      "Authorization": "(removed)"
    },
    "params": {
      "api_key": "(removed)"
    },
    "baseURL": "https://beta.fallingfruit.org/api/0.3",
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 0,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "maxBodyLength": -1,
    "transitional": {
      "silentJSONParsing": true,
      "forcedJSONParsing": true,
      "clarifyTimeoutError": false
    }
  },
  "request": {}
}
ezwelty commented 5 days ago

Thanks for catching this!

The reason for this issue was a bug in the horrific house of cards that makes it possible for this new website to support multiple photos per review while still using the same database as the old website. The fix was to replace the deprecated S3 "path-style" URLs generated by a database trigger with virtual-hosted-style URLs. See https://github.com/falling-fruit/falling-fruit/commit/765047d5ab6610c0cdf85ffef42997fdf89d1770.