mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 00:10:57 +00:00 
			
		
		
		
	Change to server-side implementation
This commit is contained in:
		
							parent
							
								
									82c69ff68d
								
							
						
					
					
						commit
						3740426bb5
					
				@ -177,20 +177,6 @@ function Home({ initialSettings }) {
 | 
			
		||||
  
 | 
			
		||||
  const servicesAndBookmarks = [...services.map(sg => sg.services).flat(), ...bookmarks.map(bg => bg.bookmarks).flat()]
 | 
			
		||||
 | 
			
		||||
  // sort layout
 | 
			
		||||
  const layouts = Object.keys(initialSettings.layout);
 | 
			
		||||
  let sortedServices = [];
 | 
			
		||||
  const copiedServices = services.slice();
 | 
			
		||||
  layouts.forEach((currentServer) => {
 | 
			
		||||
    if (initialSettings.layout[currentServer]?.sort) {
 | 
			
		||||
      const idx = copiedServices.findIndex((service) => service.name === currentServer);
 | 
			
		||||
      sortedServices.push(...copiedServices.splice(idx, 1));
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  if (copiedServices.length) {
 | 
			
		||||
    sortedServices = sortedServices.concat(copiedServices);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    if (settings.language) {
 | 
			
		||||
@ -278,9 +264,9 @@ function Home({ initialSettings }) {
 | 
			
		||||
          )}
 | 
			
		||||
        </div>
 | 
			
		||||
 | 
			
		||||
        {sortedServices && (
 | 
			
		||||
        {services && (
 | 
			
		||||
          <div className="flex flex-wrap p-4 sm:p-8 sm:pt-4 items-start pb-2">
 | 
			
		||||
            {sortedServices.map((group) => (
 | 
			
		||||
            {services.map((group) => (
 | 
			
		||||
              <ServicesGroup key={group.name} services={group} layout={initialSettings.layout?.[group.name]} />
 | 
			
		||||
            ))}
 | 
			
		||||
          </div>
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@ import path from "path";
 | 
			
		||||
 | 
			
		||||
import yaml from "js-yaml";
 | 
			
		||||
 | 
			
		||||
import checkAndCopyConfig from "utils/config/config";
 | 
			
		||||
import checkAndCopyConfig, { getSettings } from "utils/config/config";
 | 
			
		||||
import { servicesFromConfig, servicesFromDocker, cleanServiceGroups } from "utils/config/service-helpers";
 | 
			
		||||
import { cleanWidgetGroups, widgetsFromConfig } from "utils/config/widget-helpers";
 | 
			
		||||
 | 
			
		||||
@ -46,6 +46,7 @@ export async function widgetsResponse() {
 | 
			
		||||
export async function servicesResponse() {
 | 
			
		||||
  let discoveredServices;
 | 
			
		||||
  let configuredServices;
 | 
			
		||||
  let initialSettings;
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    discoveredServices = cleanServiceGroups(await servicesFromDocker());
 | 
			
		||||
@ -63,6 +64,14 @@ export async function servicesResponse() {
 | 
			
		||||
    configuredServices = [];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    initialSettings = await getSettings();
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    console.error("Failed to load settings.yaml, please check for errors");
 | 
			
		||||
    if (e) console.error(e);
 | 
			
		||||
    initialSettings = {};
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const mergedGroupsNames = [
 | 
			
		||||
    ...new Set([discoveredServices.map((group) => group.name), configuredServices.map((group) => group.name)].flat()),
 | 
			
		||||
  ];
 | 
			
		||||
@ -81,5 +90,18 @@ export async function servicesResponse() {
 | 
			
		||||
    mergedGroups.push(mergedGroup);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return mergedGroups;
 | 
			
		||||
  let sortedServices = [];
 | 
			
		||||
 | 
			
		||||
  const layouts = Object.keys(initialSettings.layout);
 | 
			
		||||
  layouts.forEach((currentServer) => {
 | 
			
		||||
    if (initialSettings.layout[currentServer]?.sort) {
 | 
			
		||||
      const idx = mergedGroups.findIndex((service) => service.name === currentServer);
 | 
			
		||||
      sortedServices.push(...mergedGroups.splice(idx, 1));
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
  if (mergedGroups.length) {
 | 
			
		||||
    sortedServices = sortedServices.concat(mergedGroups);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return sortedServices;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user