mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:27:09 -05:00 
			
		
		
		
	feat(server): Support TypeSense High-Availibility configuration (#2146)
* feat(server): Support TypeSense High-Availibility configuration. * Lint fixes * Address comments.
This commit is contained in:
		
							parent
							
								
									d6f2ca6aaa
								
							
						
					
					
						commit
						fc585bffcc
					
				@ -47,6 +47,14 @@ UPLOAD_LOCATION=absolute_location_on_your_machine_where_you_want_to_store_the_ba
 | 
				
			|||||||
###################################################################################
 | 
					###################################################################################
 | 
				
			||||||
TYPESENSE_API_KEY=some-random-text
 | 
					TYPESENSE_API_KEY=some-random-text
 | 
				
			||||||
# TYPESENSE_ENABLED=false
 | 
					# TYPESENSE_ENABLED=false
 | 
				
			||||||
 | 
					# TYPESENSE_URL uses base64 encoding for the nodes json.
 | 
				
			||||||
 | 
					# Example JSON that was used:
 | 
				
			||||||
 | 
					# [
 | 
				
			||||||
 | 
					#      { 'host': 'typesense-1.example.net', 'port': '443', 'protocol': 'https' },
 | 
				
			||||||
 | 
					#      { 'host': 'typesense-2.example.net', 'port': '443', 'protocol': 'https' },
 | 
				
			||||||
 | 
					#      { 'host': 'typesense-3.example.net', 'port': '443', 'protocol': 'https' },
 | 
				
			||||||
 | 
					#  ]
 | 
				
			||||||
 | 
					# TYPESENSE_URL=ha://WwogICAgeyAnaG9zdCc6ICd0eXBlc2Vuc2UtMS5leGFtcGxlLm5ldCcsICdwb3J0JzogJzQ0MycsICdwcm90b2NvbCc6ICdodHRwcycgfSwKICAgIHsgJ2hvc3QnOiAndHlwZXNlbnNlLTIuZXhhbXBsZS5uZXQnLCAncG9ydCc6ICc0NDMnLCAncHJvdG9jb2wnOiAnaHR0cHMnIH0sCiAgICB7ICdob3N0JzogJ3R5cGVzZW5zZS0zLmV4YW1wbGUubmV0JywgJ3BvcnQnOiAnNDQzJywgJ3Byb3RvY29sJzogJ2h0dHBzJyB9LApd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
###################################################################################
 | 
					###################################################################################
 | 
				
			||||||
# Reverse Geocoding
 | 
					# Reverse Geocoding
 | 
				
			||||||
 | 
				
			|||||||
@ -37,16 +37,35 @@ export const bullConfig: BullModuleOptions = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const bullQueues: BullModuleOptions[] = Object.values(QueueName).map((name) => ({ name }));
 | 
					export const bullQueues: BullModuleOptions[] = Object.values(QueueName).map((name) => ({ name }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const typesenseConfig: ConfigurationOptions = {
 | 
					function parseTypeSenseConfig(): ConfigurationOptions {
 | 
				
			||||||
  nodes: [
 | 
					  const typesenseURL = process.env.TYPESENSE_URL;
 | 
				
			||||||
    {
 | 
					  const common = {
 | 
				
			||||||
      host: process.env.TYPESENSE_HOST || 'typesense',
 | 
					    apiKey: process.env.TYPESENSE_API_KEY as string,
 | 
				
			||||||
      port: Number(process.env.TYPESENSE_PORT) || 8108,
 | 
					    numRetries: 15,
 | 
				
			||||||
      protocol: process.env.TYPESENSE_PROTOCOL || 'http',
 | 
					    retryIntervalSeconds: 4,
 | 
				
			||||||
    },
 | 
					    connectionTimeoutSeconds: 10,
 | 
				
			||||||
  ],
 | 
					  };
 | 
				
			||||||
  apiKey: process.env.TYPESENSE_API_KEY as string,
 | 
					  if (typesenseURL && typesenseURL.startsWith('ha://')) {
 | 
				
			||||||
  numRetries: 15,
 | 
					    try {
 | 
				
			||||||
  retryIntervalSeconds: 4,
 | 
					      const decodedString = Buffer.from(typesenseURL.slice(5), 'base64').toString();
 | 
				
			||||||
  connectionTimeoutSeconds: 10,
 | 
					      return {
 | 
				
			||||||
};
 | 
					        nodes: JSON.parse(decodedString),
 | 
				
			||||||
 | 
					        ...common,
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					    } catch (error) {
 | 
				
			||||||
 | 
					      throw new Error(`Failed to decode typesense options: ${error}`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return {
 | 
				
			||||||
 | 
					    nodes: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        host: process.env.TYPESENSE_HOST || 'typesense',
 | 
				
			||||||
 | 
					        port: Number(process.env.TYPESENSE_PORT) || 8108,
 | 
				
			||||||
 | 
					        protocol: process.env.TYPESENSE_PROTOCOL || 'http',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    ...common,
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const typesenseConfig: ConfigurationOptions = parseTypeSenseConfig();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user