Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: Create a couple additional API endpoints #14

Merged
merged 4 commits into from
Jul 21, 2022
Merged

Conversation

victorges
Copy link
Member

This is to create a couple of additional API endpoints that were needed for writing
a script to unpin items from IPFS created by our VOD tests.

@victorges victorges requested a review from a team as a code owner July 12, 2022 20:19
Copy link
Member

@gioelecerati gioelecerati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

api.go Outdated

func (lapi *Client) GetAssetByPlaybackID(pid string, includeDeleted bool) (*Asset, error) {
var assets []*Asset
url := fmt.Sprintf(`%s/api/asset?limit=2&allUsers=true&filters=[{"id":"playbackId","value":%q}]`, lapi.chosenServer, pid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious on why specifically limit 2? When is it possible that there are multiple assets with the same playbackId? I see this is also contemplated as a possible error later on line 1008

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only care about 3 scenarios:
a. no results, which means we should 404
b. 1 result, meaning we found the asset we want
c. more than 1 result, which means there is an unexpected playback ID conflict

On the last case, we also don't care if we get 2 or 473263672 results, it only matters that there is more than 1.

In such case, we can limit the list to 2 elements in the response, which gives us only 3 possibilites of responses:

  • 0 elements (a)
  • 1 element (b)
  • 2 elements (c)

We also avoid some data bandwidth in case there is this bug of more than 1 asset with the same playbackId, transferring only 2 elements over the internet (doesn't matter how much there really are).

I don't know how that case could happen, but it is a safeguard since we're using a List function for what is actually a Get. If we get more than 1 asset, it's an internal server error and we should treat it as such.

@victorges victorges merged commit 95e2bb1 into main Jul 21, 2022
@victorges victorges deleted the vg/feat/more-vod-apis branch July 21, 2022 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants