feature: don't create federation when there is only one target

This commit is contained in:
Jean-Baptiste Pasquier 2021-07-05 19:15:43 +02:00
parent 8c860e07aa
commit 6d52e869d1

View File

@ -113,15 +113,20 @@ for component of components
for(const [attribute, path] of Object.entries(component.parameters)) { for(const [attribute, path] of Object.entries(component.parameters)) {
if(typeof path === 'string') { if(typeof path === 'string') {
if(path.startsWith('federation://')) { if(path.startsWith('federation://')) {
let contains = generateUrl(federation, path);
if(contains.length > 1) {
federations[`store://local.${component.uniq}/${attribute}/`] = { federations[`store://local.${component.uniq}/${attribute}/`] = {
"@cache": "false", "@cache": "false",
"@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld", "@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld",
"@type": "ldp:Container", "@type": "ldp:Container",
"@id": `store://local.${component.uniq}/${attribute}/`, "@id": `store://local.${component.uniq}/${attribute}/`,
"ldp:contains": generateUrl(federation, path), "ldp:contains": contains,
"permissions": [{"mode": {"@type": "view"}}] "permissions": [{"mode": {"@type": "view"}}]
}; };
component.parameters[attribute] = `store://local.${component.uniq}/${attribute}/`; component.parameters[attribute] = `store://local.${component.uniq}/${attribute}/`;
} else {
component.parameters[attribute] = federation.values().next().value + path.replace(/federation:\//, '');
}
} }
if(path.startsWith('server://')) { if(path.startsWith('server://')) {
component.parameters[attribute] = client.server + path.replace(/server:\//, ''); component.parameters[attribute] = client.server + path.replace(/server:\//, '');
@ -163,15 +168,20 @@ for component of components
for(const [attribute, path] of Object.entries(extension.parameters)) { for(const [attribute, path] of Object.entries(extension.parameters)) {
if(typeof path === 'string') { if(typeof path === 'string') {
if(path.startsWith('federation://')) { if(path.startsWith('federation://')) {
let contains = generateUrl(federation, path);
if(contains.length > 1) {
federations[`store://local.${extension.uniq}/${attribute}/`] = { federations[`store://local.${extension.uniq}/${attribute}/`] = {
"@cache": "false", "@cache": "false",
"@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld", "@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld",
"@type": "ldp:Container", "@type": "ldp:Container",
"@id": `store://local.${extension.uniq}/${attribute}/`, "@id": `store://local.${extension.uniq}/${attribute}/`,
"ldp:contains": generateUrl(federation, path), "ldp:contains": contains,
"permissions": [{"mode": {"@type": "view"}}] "permissions": [{"mode": {"@type": "view"}}]
}; };
extension.parameters[attribute] = `store://local.${extension.uniq}/${attribute}/`; extension.parameters[attribute] = `store://local.${extension.uniq}/${attribute}/`;
} else {
component.parameters[attribute] = federation.values().next().value + path.replace(/federation:\//, '');
}
} }
if(path.startsWith('server://')) { if(path.startsWith('server://')) {
extension.parameters[attribute] = client.server + path.replace(/server:\//, ''); extension.parameters[attribute] = client.server + path.replace(/server:\//, '');