diff --git a/packages/backend/src/apps/changedetection/assets/favicon.svg b/packages/backend/src/apps/changedetection/assets/favicon.svg new file mode 100644 index 00000000..378fc45c --- /dev/null +++ b/packages/backend/src/apps/changedetection/assets/favicon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/backend/src/apps/changedetection/auth/index.js b/packages/backend/src/apps/changedetection/auth/index.js new file mode 100644 index 00000000..73d7a185 --- /dev/null +++ b/packages/backend/src/apps/changedetection/auth/index.js @@ -0,0 +1,44 @@ +import verifyCredentials from './verify-credentials.js'; +import isStillVerified from './is-still-verified.js'; + +export default { + fields: [ + { + key: 'screenName', + label: 'Screen Name', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: + 'Screen name of your connection to be used on Automatisch UI.', + clickToCopy: false, + }, + { + key: 'instanceUrl', + label: 'Instance URL', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: null, + clickToCopy: false, + }, + { + key: 'apiKey', + label: 'API Key', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: 'Changedetection API key of your account.', + clickToCopy: false, + }, + ], + + verifyCredentials, + isStillVerified, +}; diff --git a/packages/backend/src/apps/changedetection/auth/is-still-verified.js b/packages/backend/src/apps/changedetection/auth/is-still-verified.js new file mode 100644 index 00000000..6663679a --- /dev/null +++ b/packages/backend/src/apps/changedetection/auth/is-still-verified.js @@ -0,0 +1,8 @@ +import verifyCredentials from './verify-credentials.js'; + +const isStillVerified = async ($) => { + await verifyCredentials($); + return true; +}; + +export default isStillVerified; diff --git a/packages/backend/src/apps/changedetection/auth/verify-credentials.js b/packages/backend/src/apps/changedetection/auth/verify-credentials.js new file mode 100644 index 00000000..78d9462a --- /dev/null +++ b/packages/backend/src/apps/changedetection/auth/verify-credentials.js @@ -0,0 +1,10 @@ +const verifyCredentials = async ($) => { + await $.http.get('/v1/systeminfo'); + + await $.auth.set({ + screenName: $.auth.data.screenName, + apiKey: $.auth.data.apiKey, + }); +}; + +export default verifyCredentials; diff --git a/packages/backend/src/apps/changedetection/common/add-auth-header.js b/packages/backend/src/apps/changedetection/common/add-auth-header.js new file mode 100644 index 00000000..01bcae10 --- /dev/null +++ b/packages/backend/src/apps/changedetection/common/add-auth-header.js @@ -0,0 +1,9 @@ +const addAuthHeader = ($, requestConfig) => { + if ($.auth.data?.apiKey) { + requestConfig.headers['x-api-key'] = $.auth.data.apiKey; + } + + return requestConfig; +}; + +export default addAuthHeader; diff --git a/packages/backend/src/apps/changedetection/common/set-base-url.js b/packages/backend/src/apps/changedetection/common/set-base-url.js new file mode 100644 index 00000000..b5119288 --- /dev/null +++ b/packages/backend/src/apps/changedetection/common/set-base-url.js @@ -0,0 +1,10 @@ +const setBaseUrl = ($, requestConfig) => { + const instanceUrl = $.auth.data.instanceUrl; + if (instanceUrl) { + requestConfig.baseURL = `${instanceUrl}/api`; + } + + return requestConfig; +}; + +export default setBaseUrl; diff --git a/packages/backend/src/apps/changedetection/index.js b/packages/backend/src/apps/changedetection/index.js new file mode 100644 index 00000000..89fbe8b4 --- /dev/null +++ b/packages/backend/src/apps/changedetection/index.js @@ -0,0 +1,17 @@ +import defineApp from '../../helpers/define-app.js'; +import addAuthHeader from './common/add-auth-header.js'; +import auth from './auth/index.js'; +import setBaseUrl from './common/set-base-url.js'; + +export default defineApp({ + name: 'Changedetection', + key: 'changedetection', + iconUrl: '{BASE_URL}/apps/changedetection/assets/favicon.svg', + authDocUrl: '{DOCS_URL}/apps/changedetection/connection', + supportsConnections: true, + baseUrl: 'https://changedetection.io', + apiBaseUrl: '', + primaryColor: '3056d3', + beforeRequest: [setBaseUrl, addAuthHeader], + auth, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 7d49637e..64ae87e6 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -41,6 +41,14 @@ export default defineConfig({ { text: 'Connection', link: '/apps/carbone/connection' }, ], }, + { + text: 'Changedetection', + collapsible: true, + collapsed: true, + items: [ + { text: 'Connection', link: '/apps/changedetection/connection' }, + ], + }, { text: 'Datastore', collapsible: true, diff --git a/packages/docs/pages/apps/changedetection/connection.md b/packages/docs/pages/apps/changedetection/connection.md new file mode 100644 index 00000000..bc61ac31 --- /dev/null +++ b/packages/docs/pages/apps/changedetection/connection.md @@ -0,0 +1,14 @@ +# Changedetection + +:::info +This page explains the steps you need to follow to set up the Changedetection +connection in Automatisch. If any of the steps are outdated, please let us know! +::: + +1. Go to your Changedetection admin panel. +2. Click on the **Settings** button. +3. Click on the **API** tab. +4. Copy **API key** from the page to the `API Key` field on Automatisch. +5. Add your Instance URL in the **Instance URL** field on Automatisch. +6. Write any screen name to be displayed in Automatisch. +7. Now, you can start using the Changedetection connection with Automatisch. diff --git a/packages/docs/pages/public/favicons/changedetection.svg b/packages/docs/pages/public/favicons/changedetection.svg new file mode 100644 index 00000000..378fc45c --- /dev/null +++ b/packages/docs/pages/public/favicons/changedetection.svg @@ -0,0 +1 @@ + \ No newline at end of file