1
0
Fork 0
dri/src/options.js

101 lines
2.1 KiB
JavaScript

const version = process.env.VUE_APP_VERSION || '[master]';
const source = process.env.VUE_APP_SOURCE_LINK || 'https://github.com/productionwentdown/dri';
const defaultConfig = {
merged: false,
registryHost: process.env.VUE_APP_REGISTRY_HOST,
registryAPI: process.env.VUE_APP_REGISTRY_API,
deleteEnabled: process.env.VUE_APP_DELETE_ENABLED === 'true',
repositoriesPerPage: parseInt(process.env.VUE_APP_REPOSITORIES_PER_PAGE, 10),
tagsPerPage: parseInt(process.env.VUE_APP_TAGS_PER_PAGE, 10),
usePortusExplore: process.env.VUE_APP_USE_PORTUS_EXPLORE === 'true',
};
async function config() {
if (defaultConfig.merged) {
return defaultConfig;
}
try {
const response = await fetch('config.json');
const jsonConfig = await response.json();
defaultConfig.merged = true;
return Object.assign(defaultConfig, jsonConfig);
} catch (_) {
defaultConfig.merged = true;
return defaultConfig;
}
}
async function registryHost() {
const c = await config();
if (c.registryHost) {
return c.registryHost;
}
return window.location.host;
}
async function registryAPI() {
const c = await config();
if (c.registryAPI) {
return c.registryAPI;
}
const host = await registryHost();
// assume API uses the same protocol as the page
// this is because browsers don't allow mixed content
// if a HTTPS API needs to be accessed over HTTP, configure registryAPI
return `${window.location.protocol}//${host}`;
}
async function deleteEnabled() {
const c = await config();
if (c.deleteEnabled) {
return true;
}
return false;
}
async function repositoriesPerPage() {
const c = await config();
try {
const n = parseInt(c.repositoriesPerPage, 10);
if (n > 0) return n;
} catch (_) {
return 0;
}
return 0;
}
async function tagsPerPage() {
const c = await config();
try {
const n = parseInt(c.tagsPerPage, 10);
if (n > 0) return n;
} catch (_) {
return 0;
}
return 0;
}
async function usePortusExplore() {
const c = await config();
if (c.usePortusExplore) {
return true;
}
return false;
}
export {
version,
source,
registryHost,
registryAPI,
deleteEnabled,
repositoriesPerPage,
tagsPerPage,
usePortusExplore,
};