feat: add item type to /list endpoint#587
Conversation
…es in /list response
| }; | ||
| Some(ListItem { | ||
| file_name, | ||
| // NOTE: For urls this will return url length. Not sure if desired behaviour |
There was a problem hiding this comment.
It is intended behavior. Otherwise what would you use for an url? Even if you were to grab the size of the retrieved webpage, what exactly would you add to it? html, css, js, ... Also, that value could change during the lifetime of that link.
Thus the only number that makes sense is either 0, null, or the length of the link.
| .collect()) | ||
| }; | ||
|
|
||
| let entries: Vec<ListItem> = PASTE_VARIANTS_LIST |
There was a problem hiding this comment.
Am I correct that all files are first added and then filtered based on PASTE_VARIANTS_LIST?
Because there's a PR open to add another type ProtectedFile that is purposely not returned by the list endpoint.
There was a problem hiding this comment.
I iterate over PASTE_VARIANTS_LIST, read each variant's directory, collect its top-level files into a Vec<ListItem>, and flatten the result. The rest of the original logic is the same - I only added the item_type field and moved it into a closure.
From my understanding from glancing at the other PR, the ProtectedFile type should not be included in the response by default, as they are stored in their own subfolder.
There was a problem hiding this comment.
From my understanding from glancing at the other PR, the
ProtectedFiletype should not be included in the response by default, as they are stored in their own subfolder.
Yep, I had the same impression. I should be able to test it soon. I am travelling and my time's a bit limited, but I'll try my best.
| // Items returned from `/list` endpoint should be returned in this order: | ||
| // 1. PasteType::File | ||
| // 2. PasteType::Oneshot | ||
| // 3. PasteType::Url | ||
| // 4. PasteType::OneshotUrl | ||
| // NOTE: The test won't pass if order in `PASTE_VARIANTS_LIST` changes |
There was a problem hiding this comment.
I have to get back and check the code (unless Orhun beats me to it), but I can't recall whether we sort at all. e.g. by expiry.
By default I would not expect the /list endpoint to do any sorting at all (that can be done with jq afterwards), but if you need sorting I don't mind either. In that case we should agree on a default sorting. I am not saying the current one is not ok. I just wanted to put it out there.
Please ignore the following:
IDEA tessus /feat: add sorting to list endpoint
For future reference for myself: sorting the list endpoint might be a cool feature. e.g. /list/expiry/desc
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #587 +/- ##
==========================================
+ Coverage 83.93% 84.09% +0.15%
==========================================
Files 12 12
Lines 1631 1647 +16
==========================================
+ Hits 1369 1385 +16
Misses 262 262 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Looks good generally, let me know when this is ready for an additional review @tessus |
|
I have to wait until #589 is merged before I can fix the errors. Edit: fixed the PR number. |
|
I have been testing it and it looks fine so far. Protected files are not listed. I am a bit exhausted today so I will run the rest of my tests for this PR tomorrow (e.g. testing the cli app, ...). In the meantime, maybe @orhun can decide what we should use in the |
|
I think file_size should probably be null for URLs - that's the option that makes sense to me most. |
Description
The
/listendpoint returned only normal files (PasteType::FileandPasteType::RemoteFile). Now it returns also every other supported type and reports it usingitem_typefield. Example response:[ { "file_name": "crunchiest-cristiano.toml", "file_size": 1956, "item_type": "file", "creation_date_utc": "2026-07-09 16:16:56", "expires_at_utc": "2026-07-09 16:26:56" } ]Motivation and Context
Solves #578
How Has This Been Tested?
server::tests::test_list_item_typeChangelog Entry
Added
/listendpoint/listendpoint now returns json with fielditem_type(possible values:file,oneshot,url,oneshot_url) indicating type of uploaded content.Types of Changes
Checklist: