n8n-nodes-lightrag
Version:
Custom node for querying LightRAG inside n8n workflows or AI Chatflows
61 lines (60 loc) • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LightRagApi = void 0;
class LightRagApi {
constructor() {
this.name = 'lightRagApi';
this.displayName = 'LightRAG API';
this.properties = [
{
displayName: 'API Base URL',
name: 'url',
type: 'string',
default: 'http://localhost:9621',
placeholder: 'http://your-lightRag-server:9621',
description: 'Base URL of your LightRAG instance',
},
{
displayName: 'API Key (Optional)',
name: 'apiKey',
type: 'string',
default: '',
description: 'Optional API key if secured',
},
];
this.test = {
request: {
baseURL: '={{$credentials.url}}',
// Adiciona api_key_header_value como query parameter se existir
url: '=/health{{$credentials.apiKey ? `?api_key_header_value=${$credentials.apiKey}` : ``}}',
method: 'GET',
headers: {
accept: 'application/json',
'X-API-Key': '={{$credentials.apiKey}}',
},
timeout: 10000,
},
};
}
// Autenticação para todos os requests do node - adiciona header X-API-Key
authenticate(credentials, requestOptions) {
const apiKey = credentials.apiKey;
if (apiKey === null || apiKey === void 0 ? void 0 : apiKey.trim()) {
// Garante o header accept e adiciona X-API-Key
requestOptions.headers = {
accept: 'application/json',
'X-API-Key': apiKey.trim(), // Adiciona o apiKey como header
...requestOptions.headers,
};
}
else {
// Garante o header accept apenas se não houver apiKey
requestOptions.headers = {
accept: 'application/json',
...requestOptions.headers,
};
}
return Promise.resolve(requestOptions);
}
}
exports.LightRagApi = LightRagApi;