feat(ui): direct-download links for downloadable local repo files (#106)
## Why The local-repo object browser renders every file name as inert text, so there is no way to grab a file from the UI even though local rpm repos already serve their contents as real yum repos. Users have to hand-construct URLs. This adds one-click downloads, built as a modular per-repo-type capability so other types can be switched on later with a single map entry. ## Changes - Adds a `downloadableTypes` capability map (`ui/src/components/downloads.ts`) keyed by `package_type`; each entry builds the direct-download URL for a file. - Enables `rpm`, pointing at the yum files route `/api/v2/remotes/<repo>/files/<path>` (path-segment-encoded). - Renders file names in the object browser as `<a href download>` links when the repo's type is downloadable, and as plain text otherwise. - Fetches the repo's `package_type` on the Objects page as the modularity hook and threads it through the tree rows. ## Notes Download links are same-origin unauthenticated GETs (the API serves local repos with no token on reads, matching how yum clients fetch), so a bare `href` carries no credentials. Adding a future type is one entry in `downloadableTypes`. --------- Co-authored-by: Ben Vin <neotheo@gmail.com> Reviewed-on: #106 Co-authored-by: Ben Vincent <ben@unkin.net> Co-committed-by: Ben Vincent <ben@unkin.net>
This commit was merged in pull request #106.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// Per-repo-type "downloadable" capability map.
|
||||
//
|
||||
// When a repo's package_type has an entry here, file entries in the object
|
||||
// browser render as direct-download links pointing at the URL the entry
|
||||
// builds. Types absent from the map render as plain text. Enabling a new
|
||||
// type is a one-line addition below.
|
||||
//
|
||||
// Download routes are same-origin, unauthenticated GETs (the API serves local
|
||||
// repos as real registries with no token on reads), so a bare <a href download>
|
||||
// works and carries no credentials.
|
||||
|
||||
// buildUrl receives the repo name and the artifact's full path (may contain
|
||||
// slashes) and returns the direct-download URL for that file.
|
||||
type DownloadUrlBuilder = (repo: string, path: string) => string;
|
||||
|
||||
export const downloadableTypes: Record<string, DownloadUrlBuilder> = {
|
||||
// rpm locals are real yum repos; files are served at
|
||||
// /api/v2/remotes/<repo>/files/<path>.
|
||||
rpm: (repo, path) =>
|
||||
`/api/v2/remotes/${encodeURIComponent(repo)}/files/${path
|
||||
.split('/')
|
||||
.map(encodeURIComponent)
|
||||
.join('/')}`,
|
||||
};
|
||||
|
||||
// downloadUrlFor returns the direct-download URL for a file when its repo type
|
||||
// is downloadable, or null otherwise (render as plain text).
|
||||
export function downloadUrlFor(
|
||||
packageType: string | undefined,
|
||||
repo: string,
|
||||
path: string,
|
||||
): string | null {
|
||||
if (!packageType) return null;
|
||||
const build = downloadableTypes[packageType];
|
||||
return build ? build(repo, path) : null;
|
||||
}
|
||||
Reference in New Issue
Block a user