mirror of
https://github.com/Joxit/docker-registry-ui.git
synced 2026-05-25 04:52:45 +00:00
feat: add option for default registries when SINGLE_REGISTRY=false
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const LOCAL_STORAGE_KEY = 'registryServer';
|
||||
|
||||
export function bytesToSize(bytes) {
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
if (bytes == undefined || isNaN(bytes)) {
|
||||
@@ -152,7 +154,7 @@ export const ERROR_CAN_NOT_READ_CONTENT_DIGEST = {
|
||||
|
||||
export function getRegistryServers(i) {
|
||||
try {
|
||||
const res = JSON.parse(localStorage.getItem('registryServer'));
|
||||
const res = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY));
|
||||
if (res instanceof Array) {
|
||||
return !isNaN(i) ? res[i] : res.map((url) => url.trim().replace(/\/*$/, ''));
|
||||
}
|
||||
@@ -160,6 +162,28 @@ export function getRegistryServers(i) {
|
||||
return !isNaN(i) ? '' : [];
|
||||
}
|
||||
|
||||
export function setRegistryServers(registries) {
|
||||
if (typeof registries === 'string') {
|
||||
registries = registries.split(',');
|
||||
} else if (!Array.isArray(registries)) {
|
||||
throw new Error('setRegistries must be called with string or array parameter');
|
||||
}
|
||||
registries = registries.map((registry) => registry.replace(/\/*$/, ''));
|
||||
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(registries));
|
||||
}
|
||||
|
||||
export function addRegistryServers(registry) {
|
||||
const url = registry.trim().replace(/\/*$/, '');
|
||||
const registryServer = getRegistryServers().filter((e) => e !== url);
|
||||
setRegistryServers([url].concat(registryServer));
|
||||
return url;
|
||||
}
|
||||
|
||||
export function removeRegistryServers(registry) {
|
||||
const registryServers = getRegistryServers().filter((e) => e !== registry);
|
||||
setRegistryServers(registryServers);
|
||||
}
|
||||
|
||||
export function encodeURI(url) {
|
||||
if (!url) {
|
||||
return;
|
||||
@@ -175,5 +199,5 @@ export function decodeURI(url) {
|
||||
}
|
||||
|
||||
export function truthy(value) {
|
||||
return value === true || value === "true";
|
||||
}
|
||||
return value === true || value === 'true';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user