From a04b882b827566b42f850fa5ee49383821c0d6b1 Mon Sep 17 00:00:00 2001 From: Alex Hoyau Date: Fri, 11 Oct 2024 12:33:25 +0300 Subject: [PATCH] puter plugin --- .silex.js | 166 ++-------------------------------------------- README.md | 26 +++----- client-config.js | 46 +++++++------ package-lock.json | 4 +- package.json | 11 +-- 5 files changed, 47 insertions(+), 206 deletions(-) diff --git a/.silex.js b/.silex.js index 21cd454..aaf23a7 100644 --- a/.silex.js +++ b/.silex.js @@ -1,181 +1,27 @@ -const { ConnectorType } = require('@silexlabs/silex/dist/server/types') -const FtpConnector = require('@silexlabs/silex/dist/plugins/server/plugins/server/FtpConnector').default -const DownloadConnector = require('@silexlabs/silex/dist/plugins/server/plugins/server/DownloadConnector').default -const GitlabConnector = require('@silexlabs/silex/dist/plugins/server/plugins/server/GitlabConnector').default -const GitlabHostingConnector = require('@silexlabs/silex/dist/plugins/server/plugins/server/GitlabHostingConnector').default -const { FsStorage } = require('@silexlabs/silex/dist/server/server/connectors/FsStorage') -const { FsHosting } = require('@silexlabs/silex/dist/server/server/connectors/FsHosting') -const dash = require('@silexlabs/silex-dashboard') +const onboarding = require(__dirname + '/server-plugins/onboarding.js') const StaticPlugin = require('@silexlabs/silex/dist/plugins/server/plugins/server/StaticPlugin').default const node_modules = require('node_modules-path') -const onboarding = require(__dirname + '/server-plugins/onboarding.js') const { join } = require('path') module.exports = async function (config) { - await config.addPlugin(dash) await config.addPlugin(onboarding) initConnectors(config) - //config.setHostingConnectors([ - // new FtpConnector(config, { - // type: ConnectorType.HOSTING, - // }), - // new DownloadPlugin(config), - //]) - //config.setStorageConnectors([ - // new FtpConnector(config, { - // type: ConnectorType.STORAGE, - // }), - // new GitlabConnector(config, { - // clientId: process.env.GITLAB_CLIENT_ID, - // clientSecret: process.env.GITLAB_CLIENT_SECRET, - // domain: process.env.GITLAB_DOMAIN, - // }), - // new FramagitConnector(config, { - // clientId: process.env.FRAMAGIT_CLIENT_ID, - // clientSecret: process.env.FRAMAGIT_CLIENT_SECRET, - // domain: process.env.FRAMAGIT_DOMAIN, - // }), - //]) - - // CMS Plugin config.addPlugin(StaticPlugin, { routes: [ { route: '/js/client-plugins/', path: './client-plugins/', + }, { + route: '/js/silex-puter/', + path: join(node_modules('@silexlabs/silex-puter'), '@silexlabs/silex-puter/dist/'), }, ], }) } -const env = { - STORAGE_CONNECTORS: process.env.STORAGE_CONNECTORS || 'ftp', - HOSTING_CONNECTORS: process.env.HOSTING_CONNECTORS || 'ftp,download', - SILEX_FS_ROOT: process.env.SILEX_FS_ROOT || join(process.cwd(), '/silex/storage'), - SILEX_FS_HOSTING_ROOT: process.env.SILEX_FS_HOSTING_ROOT || join(process.cwd(), '/silex/hosting'), - GITLAB_DISPLAY_NAME: process.env.GITLAB_DISPLAY_NAME || 'Gitlab', - GITLAB_CLIENT_ID: process.env.GITLAB_CLIENT_ID, - GITLAB_CLIENT_SECRET: process.env.GITLAB_CLIENT_SECRET, - GITLAB_DOMAIN: process.env.GITLAB_DOMAIN, - GITLAB2_DISPLAY_NAME: process.env.GITLAB2_DISPLAY_NAME || 'Gitlab', - GITLAB2_CLIENT_ID: process.env.GITLAB2_CLIENT_ID, - GITLAB2_CLIENT_SECRET: process.env.GITLAB2_CLIENT_SECRET, - GITLAB2_DOMAIN: process.env.GITLAB2_DOMAIN, - FTP_STORAGE_PATH: process.env.FTP_STORAGE_PATH || '', - FTP_HOSTING_PATH: process.env.FTP_HOSTING_PATH || '', -} - -// Create alternate versions of the the Gitlab connector -class GitlabConnector1 extends GitlabConnector { - displayName = env.GITLAB_DISPLAY_NAME - constructor(config, options) { - super(config, options) - } -} - -class GitlabConnector2 extends GitlabConnector { - connectorId = 'gitlab2' - displayName = env.GITLAB2_DISPLAY_NAME - constructor(config, options) { - super(config, options) - } -} - -class GitlabHostingConnector1 extends GitlabHostingConnector { - displayName = env.GITLAB_DISPLAY_NAME - constructor(config, options) { - super(config, options) - } -} - -class GitlabHostingConnector2 extends GitlabHostingConnector { - connectorId = 'gitlab2' - displayName = env.GITLAB2_DISPLAY_NAME - constructor(config, options) { - super(config, options) - } -} - function initConnectors(config) { - // Add storage and hosting connectors from env vars - if (env.STORAGE_CONNECTORS) { - config.setStorageConnectors([]) - const connectors = env.STORAGE_CONNECTORS.split(',') - connectors.forEach((connector) => { - console.info('> Add storage connector from env var:', connector) - switch (connector) { - case 'fs': - config.addStorageConnector(new FsStorage(config, { - path: env.SILEX_FS_ROOT, - })) - break - case 'gitlab': - config.addStorageConnector(new GitlabConnector1(config, { - clientId: env.GITLAB_CLIENT_ID, - clientSecret: env.GITLAB_CLIENT_SECRET, - domain: env.GITLAB_DOMAIN, - })) - break - case 'gitlab2': - config.addStorageConnector(new GitlabConnector2(config, { - clientId: env.GITLAB2_CLIENT_ID, - clientSecret: env.GITLAB2_CLIENT_SECRET, - domain: env.GITLAB2_DOMAIN, - })) - break - case 'ftp': - config.addStorageConnector(new FtpConnector(config, { - type: ConnectorType.STORAGE, - path: env.FTP_STORAGE_PATH, - })) - break - default: - console.error('Unknown storage connector', connector) - throw new Error(`Unknown storage connector ${connector}`) - } - }) - } - - if (env.HOSTING_CONNECTORS) { - config.setHostingConnectors([]) - const connectors = env.HOSTING_CONNECTORS.split(',') - connectors.forEach((connector) => { - console.info('> Add hosting connector from env var:', connector) - switch (connector) { - case 'fs': - config.addHostingConnector(new FsHosting(config, { - path: env.SILEX_FS_HOSTING_ROOT, - })) - break - case 'gitlab': - config.addHostingConnector(new GitlabHostingConnector1(config, { - clientId: env.GITLAB_CLIENT_ID, - clientSecret: env.GITLAB_CLIENT_SECRET, - domain: env.GITLAB_DOMAIN, - })) - break - case 'gitlab2': - config.addHostingConnector(new GitlabHostingConnector2(config, { - clientId: env.GITLAB2_CLIENT_ID, - clientSecret: env.GITLAB2_CLIENT_SECRET, - domain: env.GITLAB2_DOMAIN, - })) - break - case 'ftp': - config.addHostingConnector(new FtpConnector(config, { - type: ConnectorType.HOSTING, - path: env.FTP_HOSTING_PATH, - })) - break - case 'download': - config.addHostingConnector(new DownloadConnector(config)) - break - default: - console.error('Unknown hosting connector', connector) - throw new Error(`Unknown hosting connector ${connector}`) - } - }) - } + config.setStorageConnectors([]) + config.setHostingConnectors([]) } diff --git a/README.md b/README.md index c189ac4..f685860 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ## Silex instances by Silex Labs -This repo holds the code for the [public Silex instance hosted for free by Silex Labs foundation](https://editor.silex.me) and [The v3 instance too](https://v3.silex.me). +This instance is a fork of the [Silex editor](https://github.com/silexlabs/editor.silex.me) wich implements [`silex-puter` plugin](https://github.com/silexlabs/silex-puter) in order to serve Silex to puter users with the puter integration. + +This repo holds the code for the [public Silex instance hosted for free by Silex Labs foundation](https://puter.silex.me) and [The v3 instance too](https://v3.silex.me). This is also a good example on how to customize Silex. And it has a Dockerfile for easy deployment @@ -8,10 +10,11 @@ This is also a good example on how to customize Silex. And it has a Dockerfile f This code adds features to the editor specific to our instance (in `index.js` and `index.pug`): -* [x] Multi-site with the Dashboard plugin +* [x] Puter plugin * [x] Automatic deployment to [CapRover](https://caprover.com/) (see the captain-definition file and the file `.github/workflows/caprover.yml`) * [x] Onboarding: Send an email with [brevo the 1st time we see a user](https://brevo.co/) + use Silex notification system to guide users through the first steps -* [x] Enable or disable cloud services and hosting providers with env vars +* [x] Disable cloud services and hosting providers with env vars +* [ ] Silex CMS plugin * [ ] Analytics: add a tag in Silex editor ## Environment variables @@ -20,20 +23,9 @@ You can set the following environment variables to customize the instance: | Name | Description | Type | Default value | |------|-------------| ---- |---------------| -| `STORAGE_CONNECTORS` | List of storage connectors to enable | `ftp` or `gitlab` or `gitlab2` or `fs` | `ftp` | -| `HOSTING_CONNECTORS` | List of hosting connectors to enable | `ftp` or `gitlab` or `gitlab2` or `fs` or `download` | `ftp,download` | -| `SILEX_FS_ROOT` | Root folder for the file system storage | string | current directory + `/silex/storage/` | -| `SILEX_FS_HOSTING_ROOT` | Root folder for the file system hosting | string | current directory + `/silex/hosting/` | -| `FTP_STORAGE_PATH` | Path to the FTP storage | string | `` | -| `FTP_HOSTING_PATH` | Path to the FTP hosting | string | `` | -| `GITLAB_DISPLAY_NAME` | Display name for the Gitlab storage | string | `Gitlab` | -| `GITLAB_DOMAIN` | Domain of the Gitlab server, e.g `https://gitlab.com` | string | required with gitlab connector | -| `GITLAB_CLIENT_ID` | Client ID for the Gitlab OAuth | string | required with gitlab connector | -| `GITLAB_CLIENT_SECRET` | Client secret for the Gitlab OAuth | string | required with gitlab connector | -| `GITLAB2_DISPLAY_NAME` | Display name for the 2nd Gitlab storage | string | `Gitlab2` | -| `GITLAB2_DOMAIN` | Domain of the 2nd Gitlab server, e.g `https://gitlab.com` | string | required | -| `GITLAB2_CLIENT_ID` | Client ID for the 2nd Gitlab OAuth | string | required | -| `GITLAB2_CLIENT_SECRET` | Client secret for the 2nd Gitlab OAuth | string | required | +| `BREVO_API_KEY` | The API key for the Brevo service (onboarding, optional) | string | - | +| `BREVO_API_URL` | The API URL for the Brevo service (onboarding, optional) | string | - | +| `BREVO_LIST_ID` | The list ID for the Brevo service (onboarding, optional) | string | - | ## Support diff --git a/client-config.js b/client-config.js index 50d1608..722b0f1 100644 --- a/client-config.js +++ b/client-config.js @@ -1,31 +1,33 @@ -import SilexCms from './js/silex-cms/client.js' -import onboarding from './js/client-plugins/onboarding.js' - // This file is loaded by Silex when the user opens the editor // Its path is set in the environment variable SILEX_CLIENT_CONFIG in index.js + +//import SilexCms from './js/silex-cms/client.js' +import onboarding from './js/client-plugins/onboarding.js' import websiteInfoPlugin from './plugins/client/website-info.js' +import puter from './js/silex-puter/client.js' export default async function (config) { config.addPlugin(websiteInfoPlugin, {}) config.addPlugin(onboarding, {}) - config.addPublicationTransformers({ - transformPermalink: (path, type) => { - // Replace /index.html with / - return type === 'html' && path.endsWith('/index.html') ? path.replace(/index\.html$/, '') : path - }, - }) - // CMS Plugin - config.addPlugin(SilexCms, { - dataSources: [], - imagePlugin: false, - i18nPlugin: false, - fetchPlugin: false, - // enable11ty: false, - view: { - // disableStates: true, - // disableAttributes: false, - // disableProperties: true, - }, - }) + config.addPlugin(puter, {}) + //config.addPublicationTransformers({ + // transformPermalink: (path, type) => { + // // Replace /index.html with / + // return type === 'html' && path.endsWith('/index.html') ? path.replace(/index\.html$/, '') : path + // }, + //}) + //// CMS Plugin + //config.addPlugin(SilexCms, { + // dataSources: [], + // imagePlugin: false, + // i18nPlugin: false, + // fetchPlugin: false, + // // enable11ty: false, + // view: { + // // disableStates: true, + // // disableAttributes: false, + // // disableProperties: true, + // }, + //}) return {} } diff --git a/package-lock.json b/package-lock.json index 4c71039..c225579 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "editor.silex.me", + "name": "puter.silex.me", "version": "1.0.158", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "editor.silex.me", + "name": "puter.silex.me", "version": "1.0.158", "license": "AGPL-3.0-or-later", "dependencies": { diff --git a/package.json b/package.json index 0922614..748748d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "editor.silex.me", + "name": "puter.silex.me", "version": "1.0.158", "description": "This repo holds the code for the free public Silex instance hosted by Silex Labs foundation", "scripts": { @@ -13,16 +13,17 @@ "author": "lexoyo", "license": "AGPL-3.0-or-later", "dependencies": { - "@silexlabs/silex": "^3.0.0-alpha.179", - "@silexlabs/silex-cms": "^0.0.157", - "@silexlabs/silex-dashboard": "^1.0.73" + "@silexlabs/silex": "*", + "@silexlabs/silex-puter": "*", + "node_modules-path": "^2.0.8" }, "repository": { "type": "git", - "url": "git@github.com:silexlabs/editor.silex.me.git" + "url": "git@github.com:silexlabs/puter.silex.me.git" }, "keywords": [ "silex", + "puter", "website", "builder", "free",