debian-image-builder-frontend/src/api.js
regexowl 850e77eb01 API/test: Remove getVersion() Axios call
This removes `getVersion()` API call previously used in Axios.
2023-12-19 15:36:49 +01:00

45 lines
1.2 KiB
JavaScript

import axios from 'axios';
import { CONTENT_SOURCES_API, IMAGE_BUILDER_API } from './constants';
const postHeaders = { headers: { 'Content-Type': 'application/json' } };
async function getPackages(distribution, architecture, search, limit) {
const params = new URLSearchParams({
distribution,
architecture,
search,
});
limit && params.append('limit', limit);
const path = '/packages?' + params.toString();
const request = await axios.get(IMAGE_BUILDER_API.concat(path));
return request.data;
}
async function getPackagesContentSources(repoUrls, search) {
// content-sources expects an array of urls but we store the whole repo object
// so map the urls into an array to send to the content-sources api
const body = {
urls: repoUrls,
search,
};
const path = '/rpms/names';
const request = await axios.post(
CONTENT_SOURCES_API.concat(path),
body,
postHeaders
);
// map `package_name` key to just `name` since that's what we use across the UI
const packages = request.data.map(({ package_name: name, ...rest }) => ({
name,
...rest,
}));
return packages;
}
const apiCalls = {
getPackages,
getPackagesContentSources,
};
export default apiCalls;