diff --git a/packages/backend/package.json b/packages/backend/package.json index b59b7e0f..d265ae02 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -31,6 +31,7 @@ "accounting": "^0.4.1", "ajv-formats": "^2.1.1", "axios": "1.6.0", + "basic-ftp": "^5.0.5", "bcrypt": "^5.0.1", "bullmq": "^3.0.0", "cors": "^2.8.5", diff --git a/packages/backend/src/apps/ftp/assets/favicon.svg b/packages/backend/src/apps/ftp/assets/favicon.svg new file mode 100644 index 00000000..5d240d3b --- /dev/null +++ b/packages/backend/src/apps/ftp/assets/favicon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/backend/src/apps/ftp/auth/index.js b/packages/backend/src/apps/ftp/auth/index.js new file mode 100644 index 00000000..5af7baa2 --- /dev/null +++ b/packages/backend/src/apps/ftp/auth/index.js @@ -0,0 +1,91 @@ +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: 'host', + label: 'Host', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: 'The host information Automatisch will connect to.', + docUrl: 'https://automatisch.io/docs/ftp#host', + clickToCopy: false, + }, + { + key: 'username', + label: 'Email/Username', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: 'Your FTP login credentials.', + docUrl: 'https://automatisch.io/docs/ftp#username', + clickToCopy: false, + }, + { + key: 'password', + label: 'Password', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: null, + docUrl: 'https://automatisch.io/docs/ftp#password', + clickToCopy: false, + }, + { + key: 'secure', + label: 'Secure', + type: 'dropdown', + required: false, + readOnly: false, + value: false, + placeholder: null, + description: null, + docUrl: 'https://automatisch.io/docs/ftp#secure', + clickToCopy: false, + options: [ + { + label: 'Yes', + value: true, + }, + { + label: 'No', + value: false, + }, + ], + }, + { + key: 'port', + label: 'Port', + type: 'string', + required: false, + readOnly: false, + value: '21', + placeholder: null, + description: null, + docUrl: 'https://automatisch.io/docs/ftp#port', + clickToCopy: false, + }, + ], + verifyCredentials, + isStillVerified, +}; diff --git a/packages/backend/src/apps/ftp/auth/is-still-verified.js b/packages/backend/src/apps/ftp/auth/is-still-verified.js new file mode 100644 index 00000000..6663679a --- /dev/null +++ b/packages/backend/src/apps/ftp/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/ftp/auth/verify-credentials.js b/packages/backend/src/apps/ftp/auth/verify-credentials.js new file mode 100644 index 00000000..c9d92836 --- /dev/null +++ b/packages/backend/src/apps/ftp/auth/verify-credentials.js @@ -0,0 +1,19 @@ +import { Client } from 'basic-ftp'; + +const verifyCredentials = async ($) => { + const client = new Client(); + client.ftp.verbose = true; + + await client.access({ + host: $.auth.data.host, + user: $.auth.data.username, + password: $.auth.data.password, + secure: $.auth.data.secure, + }); + + await $.auth.set({ + screenName: $.auth.data.screenName, + }); +}; + +export default verifyCredentials; diff --git a/packages/backend/src/apps/ftp/index.js b/packages/backend/src/apps/ftp/index.js new file mode 100644 index 00000000..55d84412 --- /dev/null +++ b/packages/backend/src/apps/ftp/index.js @@ -0,0 +1,14 @@ +import defineApp from '../../helpers/define-app.js'; +import auth from './auth/index.js'; + +export default defineApp({ + name: 'FTP', + key: 'ftp', + iconUrl: '{BASE_URL}/apps/ftp/assets/favicon.svg', + authDocUrl: 'https://automatisch.io/docs/apps/ftp/connection', + supportsConnections: true, + baseUrl: '', + apiBaseUrl: '', + primaryColor: '000000', + auth, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 6e9d171f..f434ba7d 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -113,6 +113,12 @@ export default defineConfig({ { text: 'Connection', link: '/apps/formatter/connection' }, ], }, + { + text: 'FTP', + collapsible: true, + collapsed: true, + items: [{ text: 'Connection', link: '/apps/ftp/connection' }], + }, { text: 'Ghost', collapsible: true, diff --git a/packages/docs/pages/apps/ftp/connection.md b/packages/docs/pages/apps/ftp/connection.md new file mode 100644 index 00000000..fe86858f --- /dev/null +++ b/packages/docs/pages/apps/ftp/connection.md @@ -0,0 +1,16 @@ +# FTP + +:::info +This page explains the steps you need to follow to set up the FTP connection in Automatisch. If any of the steps are outdated, please let us know! +::: + +FTP, which stands for File Transfer Protocol, is a standard network protocol used for the transfer of computer files between a client and server on a computer network. t's commonly used to download files from a server or upload files to a server.. You need to provide the following information from Automatisch by using FTP connection. + +1. Write any screen name to be displayed in Automatisch. +1. Fill host address field with the FTP host address. +1. Fill username field with the FTP username. +1. Fill password field with the FTP password. +1. Select the Secure field. +1. Fill port field with the FTP port. Default is 21. +1. Click **Submit** button on Automatisch. +1. Now, you can start using the FTP connection with Automatisch. diff --git a/packages/docs/pages/public/favicons/ftp.svg b/packages/docs/pages/public/favicons/ftp.svg new file mode 100644 index 00000000..5d240d3b --- /dev/null +++ b/packages/docs/pages/public/favicons/ftp.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index b3ab9154..eb27a478 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5471,6 +5471,11 @@ basic-auth@^2.0.1, basic-auth@~2.0.1: dependencies: safe-buffer "5.1.2" +basic-ftp@^5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/basic-ftp/-/basic-ftp-5.0.5.tgz#14a474f5fffecca1f4f406f1c26b18f800225ac0" + integrity sha512-4Bcg1P8xhUuqcii/S0Z9wiHIrQVPMermM1any+MX5GeGD7faD3/msQUDGLol9wOcz4/jbg/WJnGqoJF6LiBdtg== + batch@0.6.1: version "0.6.1" resolved "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz"