UNPKG

n8n-nodes-nextcloud-deck

Version:

n8n Node für die Integration mit Nextcloud Deck - AI Agent Tool Support

281 lines (280 loc) 12.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.nextcloudWebDavCommentsApiRequest = exports.nextcloudOcsUsersApiRequest = exports.nextcloudShareeApiRequest = exports.nextcloudDeckOcsApiRequest = exports.nextcloudDeckFileUploadRequest = exports.nextcloudDeckApiRequest = void 0; const n8n_workflow_1 = require("n8n-workflow"); const axios_1 = __importDefault(require("axios")); async function nextcloudDeckApiRequest(method, endpoint, body = {}) { const credentials = await this.getCredentials('nextcloudDeckApi'); const serverUrl = credentials.serverUrl.replace(/\/$/, ''); const username = credentials.username; const password = credentials.password; const url = `${serverUrl}/index.php/apps/deck/api/v1.0${endpoint}`; const config = { method, url, headers: { 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', }, auth: { username, password, }, }; if (Object.keys(body).length > 0) { config.data = body; } try { const response = await (0, axios_1.default)(config); return response.data; } catch (error) { const axiosError = error; if (axiosError.response?.status === 401) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Authentifizierung fehlgeschlagen. Überprüfen Sie Ihre Anmeldedaten oder erstellen Sie ein App-Passwort.'); } if (axiosError.response?.status === 403) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zugriff verweigert. Sie haben keine Berechtigung für diese Aktion.'); } if (axiosError.response?.status === 404) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Ressource nicht gefunden. Überprüfen Sie die angegebenen IDs.'); } if (axiosError.response?.data?.message) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), axiosError.response.data.message); } const errorMessage = error instanceof Error ? error.message : 'Unbekannter API-Fehler'; throw new n8n_workflow_1.NodeOperationError(this.getNode(), `API-Fehler: ${errorMessage}`); } } exports.nextcloudDeckApiRequest = nextcloudDeckApiRequest; async function nextcloudDeckFileUploadRequest(method, endpoint, formData) { const credentials = await this.getCredentials('nextcloudDeckApi'); const serverUrl = credentials.serverUrl.replace(/\/$/, ''); const username = credentials.username; const password = credentials.password; const url = `${serverUrl}/index.php/apps/deck/api/v1.0${endpoint}`; const config = { method, url, headers: { 'OCS-APIRequest': 'true', ...formData.getHeaders(), }, auth: { username, password, }, data: formData, }; try { const response = await (0, axios_1.default)(config); return response.data; } catch (error) { const axiosError = error; if (axiosError.response?.status === 401) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Authentifizierung fehlgeschlagen. Überprüfen Sie Ihre Anmeldedaten oder erstellen Sie ein App-Passwort.'); } if (axiosError.response?.status === 403) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zugriff verweigert. Sie haben keine Berechtigung für diese Aktion.'); } if (axiosError.response?.status === 404) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Ressource nicht gefunden. Überprüfen Sie die angegebenen IDs.'); } if (axiosError.response?.data?.message) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), axiosError.response.data.message); } const errorMessage = error instanceof Error ? error.message : 'Unbekannter API-Fehler'; throw new n8n_workflow_1.NodeOperationError(this.getNode(), `API-Fehler: ${errorMessage}`); } } exports.nextcloudDeckFileUploadRequest = nextcloudDeckFileUploadRequest; async function nextcloudDeckOcsApiRequest(method, endpoint, body = {}) { const credentials = await this.getCredentials('nextcloudDeckApi'); const serverUrl = credentials.serverUrl.replace(/\/$/, ''); const username = credentials.username; const password = credentials.password; const url = `${serverUrl}/ocs/v2.php/apps/deck/api/v1.0${endpoint}`; const config = { method, url, headers: { 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', 'Accept': 'application/json', }, auth: { username, password, }, }; if (Object.keys(body).length > 0) { config.data = body; } try { const response = await (0, axios_1.default)(config); const data = response.data; return data?.ocs?.data || response.data; } catch (error) { const axiosError = error; if (axiosError.response?.status === 401) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Authentifizierung fehlgeschlagen. Überprüfen Sie Ihre Anmeldedaten oder erstellen Sie ein App-Passwort.'); } if (axiosError.response?.status === 403) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zugriff verweigert. Sie haben keine Berechtigung für diese Aktion.'); } if (axiosError.response?.status === 404) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Ressource nicht gefunden. Überprüfen Sie die angegebenen IDs.'); } if (axiosError.response?.data?.ocs?.meta?.message) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), axiosError.response.data.ocs.meta.message); } const errorMessage = error instanceof Error ? error.message : 'Unbekannter API-Fehler'; throw new n8n_workflow_1.NodeOperationError(this.getNode(), `API-Fehler: ${errorMessage}`); } } exports.nextcloudDeckOcsApiRequest = nextcloudDeckOcsApiRequest; async function nextcloudShareeApiRequest(method, endpoint, body = {}) { const credentials = await this.getCredentials('nextcloudDeckApi'); const serverUrl = credentials.serverUrl.replace(/\/$/, ''); const username = credentials.username; const password = credentials.password; const url = `${serverUrl}/ocs/v2.php/apps/files_sharing/api/v1${endpoint}`; const config = { method, url, headers: { 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', 'Accept': 'application/json', }, auth: { username, password, }, }; if (Object.keys(body).length > 0) { config.data = body; } try { const response = await (0, axios_1.default)(config); const data = response.data; return data?.ocs?.data || response.data; } catch (error) { const axiosError = error; if (axiosError.response?.status === 401) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Authentifizierung fehlgeschlagen. Überprüfen Sie Ihre Anmeldedaten oder erstellen Sie ein App-Passwort.'); } if (axiosError.response?.status === 403) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zugriff verweigert. Sie haben keine Berechtigung für diese Aktion.'); } if (axiosError.response?.status === 404) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Ressource nicht gefunden. Überprüfen Sie die angegebenen IDs.'); } if (axiosError.response?.data?.ocs?.meta?.message) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), axiosError.response.data.ocs.meta.message); } const errorMessage = error instanceof Error ? error.message : 'Unbekannter API-Fehler'; throw new n8n_workflow_1.NodeOperationError(this.getNode(), `API-Fehler: ${errorMessage}`); } } exports.nextcloudShareeApiRequest = nextcloudShareeApiRequest; async function nextcloudOcsUsersApiRequest(method, endpoint, body = {}) { const credentials = await this.getCredentials('nextcloudDeckApi'); const serverUrl = credentials.serverUrl.replace(/\/$/, ''); const username = credentials.username; const password = credentials.password; const url = `${serverUrl}/ocs/v2.php/cloud${endpoint}`; const config = { method, url, headers: { 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', 'Accept': 'application/json', }, auth: { username, password, }, }; if (Object.keys(body).length > 0) { config.data = body; } try { const response = await (0, axios_1.default)(config); const data = response.data; return data?.ocs?.data || response.data; } catch (error) { const axiosError = error; if (axiosError.response?.status === 401) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Authentifizierung fehlgeschlagen. Überprüfen Sie Ihre Anmeldedaten oder erstellen Sie ein App-Passwort.'); } if (axiosError.response?.status === 403) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zugriff verweigert. Sie haben keine Berechtigung für diese Aktion.'); } if (axiosError.response?.status === 404) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Ressource nicht gefunden. Überprüfen Sie die angegebenen IDs.'); } if (axiosError.response?.data?.ocs?.meta?.message) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), axiosError.response.data.ocs.meta.message); } const errorMessage = error instanceof Error ? error.message : 'Unbekannter API-Fehler'; throw new n8n_workflow_1.NodeOperationError(this.getNode(), `API-Fehler: ${errorMessage}`); } } exports.nextcloudOcsUsersApiRequest = nextcloudOcsUsersApiRequest; async function nextcloudWebDavCommentsApiRequest(method, endpoint, body, contentType = 'application/xml') { const credentials = await this.getCredentials('nextcloudDeckApi'); const serverUrl = credentials.serverUrl.replace(/\/$/, ''); const username = credentials.username; const password = credentials.password; const url = `${serverUrl}/remote.php/dav/comments${endpoint}`; const config = { method, url, headers: { 'Content-Type': contentType, 'Accept': 'application/xml', }, auth: { username, password, }, }; if (body) { config.data = body; } try { const response = await (0, axios_1.default)(config); return { data: response.data, status: response.status, headers: response.headers }; } catch (error) { const axiosError = error; if (axiosError.response?.status === 401) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Authentifizierung fehlgeschlagen. Überprüfen Sie Ihre Anmeldedaten oder erstellen Sie ein App-Passwort.'); } if (axiosError.response?.status === 403) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zugriff verweigert. Sie haben keine Berechtigung für diese Aktion.'); } if (axiosError.response?.status === 404) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Ressource nicht gefunden. Überprüfen Sie die angegebenen IDs.'); } if (axiosError.response?.status === 415) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Nicht unterstützter Media-Type. Server erwartet anderen Content-Type als ${contentType}.`); } const errorMessage = error instanceof Error ? error.message : 'Unbekannter API-Fehler'; throw new n8n_workflow_1.NodeOperationError(this.getNode(), `WebDAV API-Fehler: ${errorMessage}`); } } exports.nextcloudWebDavCommentsApiRequest = nextcloudWebDavCommentsApiRequest;