pinakes-server: add MAX_OFFSET/MAX_LIMIT constants; centralize pagination bounds
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ib8227feb353cbbadc7f42fa5d29618e16a6a6964
This commit is contained in:
parent
e026dcb1e0
commit
c16fcb4a9b
6 changed files with 63 additions and 47 deletions
|
|
@ -16,22 +16,23 @@ pub fn relativize_path(full_path: &Path, roots: &[PathBuf]) -> String {
|
|||
let mut best: Option<&PathBuf> = None;
|
||||
for root in roots {
|
||||
if full_path.starts_with(root) {
|
||||
let is_longer = best
|
||||
.is_none_or(|b| root.components().count() > b.components().count());
|
||||
let is_longer =
|
||||
best.is_none_or(|b| root.components().count() > b.components().count());
|
||||
if is_longer {
|
||||
best = Some(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(root) = best
|
||||
&& let Ok(rel) = full_path.strip_prefix(root) {
|
||||
// Normalise to forward slashes on all platforms.
|
||||
return rel
|
||||
.components()
|
||||
.map(|c| c.as_os_str().to_string_lossy())
|
||||
.collect::<Vec<_>>()
|
||||
.join("/");
|
||||
}
|
||||
&& let Ok(rel) = full_path.strip_prefix(root)
|
||||
{
|
||||
// Normalise to forward slashes on all platforms.
|
||||
return rel
|
||||
.components()
|
||||
.map(|c| c.as_os_str().to_string_lossy())
|
||||
.collect::<Vec<_>>()
|
||||
.join("/");
|
||||
}
|
||||
full_path.to_string_lossy().into_owned()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue