ajayyy / SponsorBlock

Skip YouTube video sponsors (browser extension)
https://sponsor.ajay.app
GNU General Public License v3.0
9.76k stars 315 forks source link

Handle cases where userID was never generated on install: Error code 400 #466

Open andrKonan opened 3 years ago

andrKonan commented 3 years ago

Browser: Firefox 80.0.1 Add-ons: there is no any difference with or without

For any of api requests from add-on server gives me an error 400. But when I use, as an example, python to request (requests.get('https://sponsor.ajay.app/api/getTopUsers', params={'sortType':0})) it response with code 200.

ajayyy commented 3 years ago

Could you go to about:debugging and click inspect on the extension. Can you email me the error message? It should show the request that was sent.

andrKonan commented 3 years ago

GET https://sponsor.ajay.app/api/getViewsForUser?userID=JVQiQ [HTTP/1.1 404 Not Found 242ms] GET https://sponsor.ajay.app/api/getSavedTimeForUser?userID=JVQiQ [HTTP/1.1 404 Not Found 334ms] POST https://sponsor.ajay.app/api/setUsername?userID=JVQiQ&username=a10db4eaace [HTTP/1.1 400 Bad Request 213ms]

andrKonan commented 3 years ago

@ajayyy It seems that my id isn't in your server

ErikPrantare commented 3 years ago

I have the same issue when I try to submit segment. I use the official plugin on firefox. Looking in about:debugging shows that this is the request payload:

{"videoID":"suyGWHqG3YM","userID":null,"segments":[{"segment":[56.622727,99],"UUID":null,"category":"selfpromo"}]}

Is it the null arguments causing issues?

ajayyy commented 3 years ago

Ah, that would make sense. Maybe this occurs when the browser storage sync is not fast enough and loads userID as null. UUID being null is fine.

ErikPrantare commented 3 years ago

I generated a fresh UUID by using uuidgen. Setting this new user id in options solved the issue for me :)

Edit: So I guess the user id somehow never got set to begin with?

ajayyy commented 3 years ago

Possibly. By the way, it should be a long randomly generated string instead of a UUID as it is used like a password.

ajayyy commented 3 years ago

Right now, it only generates it on install. Maybe it should try when submitting as well?

https://github.com/ajayyy/SponsorBlock/blob/master/src/background.ts#L68

ErikPrantare commented 3 years ago

uuidgen creates a random UUID, so should work just as well.

Perhaps giving the user the choice to generate is a good idea, don't want to silently switch the id if something else has gone wrong

ajayyy commented 3 years ago

Yea, that would be my worry, but a warning should help with that.

ajayyy commented 3 years ago

Generating a new userID is scary since it might just be missing from the storage temporarily, and generating a new one will overwrite that.

Possible solutions: