Skip to content

feat: add item type to /list endpoint#587

Open
Bit38 wants to merge 12 commits into
orhun:masterfrom
Bit38:feat/list-item-type
Open

feat: add item type to /list endpoint#587
Bit38 wants to merge 12 commits into
orhun:masterfrom
Bit38:feat/list-item-type

Conversation

@Bit38

@Bit38 Bit38 commented Jul 9, 2026

Copy link
Copy Markdown

Description

The /list endpoint returned only normal files (PasteType::File and PasteType::RemoteFile). Now it returns also every other supported type and reports it using item_type field. 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?

  • Added test server::tests::test_list_item_type
  • Manual testing on running instance

Changelog Entry

Added

  • Included item/file type in /list endpoint
    • /list endpoint now returns json with field item_type (possible values: file, oneshot, url, oneshot_url) indicating type of uploaded content.
    • All types of uploads are now included in the response.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Bit38 Bit38 requested review from orhun and tessus as code owners July 9, 2026 16:33
Comment thread src/server.rs Outdated
};
Some(ListItem {
file_name,
// NOTE: For urls this will return url length. Not sure if desired behaviour

@tessus tessus Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/server.rs
.collect())
};

let entries: Vec<ListItem> = PASTE_VARIANTS_LIST

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

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.

Comment thread src/server.rs
Comment on lines +873 to +878
// 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@tessus tessus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a bunch for the PR. I will test it in the coming days, especially in combination with #505.

I've added a few inline comments. Maybe Orhun has some comments as well.

@codecov-commenter

codecov-commenter commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.09%. Comparing base (a9c081d) to head (542bba4).

Files with missing lines Patch % Lines
src/server.rs 92.85% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@orhun

orhun commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Looks good generally, let me know when this is ready for an additional review @tessus

@tessus

tessus commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

I have to wait until #589 is merged before I can fix the errors.

Edit: fixed the PR number.

@tessus

tessus commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

I have been testing it and it looks fine so far. Protected files are not listed.
But I ran into another issue that has nothing to do with this PR: while the protected file tests pass in the code and the fixtures, I cannot retrieve any protected files. I have to run a few tests to figure out what the problem is.

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 file_size field for urls: 0, null, or the length of the link (as it is currently).

@orhun

orhun commented Jul 12, 2026

Copy link
Copy Markdown
Owner

I think file_size should probably be null for URLs - that's the option that makes sense to me most.

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.

4 participants