@silexlabs/silex 3.0.0-alpha.41 → 3.0.0-alpha.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.silex.js +2 -11
- package/dist/client/client/api.d.ts +83 -0
- package/dist/client/client/config.d.ts +3 -3
- package/dist/client/client/events.d.ts +12 -0
- package/dist/client/client/expose.d.ts +6 -0
- package/dist/client/client/grapesjs/LoginDialog.d.ts +3 -2
- package/dist/client/client/grapesjs/PublicationManager.d.ts +9 -3
- package/dist/client/client/grapesjs/PublicationUi.d.ts +9 -6
- package/dist/client/client/grapesjs/index.d.ts +4 -4
- package/dist/client/client/grapesjs/openImport.d.ts +5 -0
- package/dist/client/constants.d.ts +23 -14
- package/dist/client/css/admin.css +5 -0
- package/dist/client/js/main.js +90 -111
- package/dist/client/js/main.js.LICENSE.txt +0 -6
- package/dist/client/page.d.ts +1 -1
- package/dist/client/types.d.ts +125 -86
- package/dist/plugins/client/client/events.d.ts +12 -0
- package/dist/plugins/client/client/events.js +30 -0
- package/dist/plugins/client/client/events.js.map +1 -0
- package/dist/plugins/client/client/utils.d.ts +1 -0
- package/{src/ts/events.ts → dist/plugins/client/client/utils.js} +9 -3
- package/dist/plugins/client/client/utils.js.map +1 -0
- package/dist/plugins/client/constants.d.ts +30 -0
- package/dist/plugins/client/constants.js +47 -0
- package/dist/plugins/client/constants.js.map +1 -0
- package/dist/plugins/client/page.d.ts +2 -0
- package/dist/plugins/client/page.js +31 -0
- package/dist/plugins/client/page.js.map +1 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.d.ts +2 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js +128 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js.map +1 -0
- package/dist/plugins/client/plugins/client/template.d.ts +2 -0
- package/dist/plugins/client/plugins/client/template.js +186 -0
- package/dist/plugins/client/plugins/client/template.js.map +1 -0
- package/dist/plugins/client/server/config.d.ts +59 -0
- package/dist/plugins/client/server/config.js +178 -0
- package/dist/plugins/client/server/config.js.map +1 -0
- package/dist/plugins/client/server/connectors/FsHosting.d.ts +13 -0
- package/dist/plugins/client/server/connectors/FsHosting.js +51 -0
- package/dist/plugins/client/server/connectors/FsHosting.js.map +1 -0
- package/dist/plugins/client/server/connectors/FsStorage.d.ts +41 -0
- package/dist/plugins/client/server/connectors/FsStorage.js +220 -0
- package/dist/plugins/client/server/connectors/FsStorage.js.map +1 -0
- package/dist/plugins/client/server/connectors/connectors.d.ts +83 -0
- package/dist/plugins/client/server/connectors/connectors.js +91 -0
- package/dist/plugins/client/server/connectors/connectors.js.map +1 -0
- package/dist/plugins/client/server/events.d.ts +26 -0
- package/dist/plugins/client/server/events.js +12 -0
- package/dist/plugins/client/server/events.js.map +1 -0
- package/dist/plugins/client/server/jobs.js +67 -0
- package/dist/plugins/client/server/jobs.js.map +1 -0
- package/dist/plugins/client/server/utils/validation.js +34 -0
- package/dist/plugins/client/server/utils/validation.js.map +1 -0
- package/dist/plugins/client/types.d.ts +309 -0
- package/dist/plugins/client/types.js +49 -0
- package/dist/plugins/client/types.js.map +1 -0
- package/dist/plugins/server/constants.d.ts +30 -0
- package/dist/plugins/server/constants.js +50 -0
- package/dist/plugins/server/constants.js.map +1 -0
- package/dist/plugins/server/plugins/server/AuthPlugin.js.map +1 -0
- package/dist/plugins/server/plugins/server/Cache.js.map +1 -0
- package/dist/plugins/server/plugins/server/FtpConnector.d.ts +94 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js +521 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -0
- package/dist/plugins/{HooksPlugin.d.ts → server/plugins/server/HooksPlugin.d.ts} +1 -1
- package/dist/plugins/{HooksPlugin.js → server/plugins/server/HooksPlugin.js} +8 -10
- package/dist/plugins/server/plugins/server/HooksPlugin.js.map +1 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.d.ts +0 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js +14 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js.map +1 -0
- package/dist/plugins/{SslPlugin.js → server/plugins/server/SslPlugin.js} +8 -8
- package/dist/plugins/server/plugins/server/SslPlugin.js.map +1 -0
- package/dist/plugins/{StaticPlugin.js → server/plugins/server/StaticPlugin.js} +9 -4
- package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -0
- package/dist/plugins/server/server/config.d.ts +59 -0
- package/dist/plugins/server/server/config.js +182 -0
- package/dist/plugins/server/server/config.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsHosting.d.ts +13 -0
- package/dist/plugins/server/server/connectors/FsHosting.js +55 -0
- package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsStorage.d.ts +41 -0
- package/dist/{server/backends/FsBackend.js → plugins/server/server/connectors/FsStorage.js} +103 -125
- package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -0
- package/dist/plugins/server/server/connectors/connectors.d.ts +83 -0
- package/dist/plugins/server/server/connectors/connectors.js +99 -0
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -0
- package/dist/plugins/server/server/events.d.ts +26 -0
- package/dist/plugins/server/server/events.js +15 -0
- package/dist/plugins/server/server/events.js.map +1 -0
- package/dist/plugins/server/server/jobs.d.ts +6 -0
- package/dist/plugins/server/server/jobs.js.map +1 -0
- package/dist/plugins/server/server/utils/validation.d.ts +7 -0
- package/dist/{server → plugins/server/server}/utils/validation.js +3 -2
- package/dist/plugins/server/server/utils/validation.js.map +1 -0
- package/dist/plugins/server/types.d.ts +309 -0
- package/dist/{types.js → plugins/server/types.js} +18 -7
- package/dist/plugins/server/types.js.map +1 -0
- package/dist/server/constants.js +30 -0
- package/dist/server/plugins/server/Cache.js +15 -0
- package/dist/server/server/api/api.js +20 -0
- package/dist/server/server/api/connectorApi.js +200 -0
- package/dist/server/server/api/publicationApi.js +116 -0
- package/dist/server/server/api/websiteApi.js +297 -0
- package/dist/server/{cli.js → server/cli.js} +6 -5
- package/dist/server/server/config.js +121 -0
- package/dist/server/server/connectors/FsHosting.js +37 -0
- package/dist/server/server/connectors/FsStorage.js +218 -0
- package/dist/server/server/connectors/connectors.js +65 -0
- package/dist/server/server/events.js +14 -0
- package/dist/server/{express.js → server/express.js} +4 -3
- package/dist/server/{index.js → server/index.js} +14 -7
- package/dist/server/server/jobs.js +47 -0
- package/dist/server/server/utils/validation.js +15 -0
- package/dist/server/types.js +19 -0
- package/package.json +26 -15
- package/src/css/grapesjs.scss +5 -0
- package/src/ts/client/api.ts +135 -0
- package/src/ts/client/config.ts +3 -3
- package/{dist/events.js → src/ts/client/events.ts} +13 -6
- package/src/ts/client/expose.ts +11 -0
- package/src/ts/client/grapesjs/LoginDialog.ts +33 -32
- package/src/ts/client/grapesjs/PublicationManager.ts +86 -112
- package/src/ts/client/grapesjs/PublicationUi.ts +43 -33
- package/src/ts/client/grapesjs/eleventy.ts +4 -1
- package/src/ts/client/grapesjs/index.ts +6 -19
- package/src/ts/client/grapesjs/openImport.ts +5 -0
- package/src/ts/client/grapesjs/storage.ts +18 -14
- package/src/ts/client/index.ts +21 -15
- package/src/ts/constants.ts +24 -14
- package/src/ts/page.ts +1 -1
- package/src/ts/plugins/client/publicationRenderer.ts +128 -0
- package/src/ts/plugins/client/template.ts +196 -0
- package/src/ts/plugins/server/FtpConnector.ts +602 -0
- package/src/ts/plugins/{HooksPlugin.ts → server/HooksPlugin.ts} +9 -12
- package/src/ts/plugins/server/PublicationOptimizer.ts +14 -0
- package/src/ts/plugins/{SslPlugin.ts → server/SslPlugin.ts} +8 -8
- package/src/ts/plugins/{StaticPlugin.ts → server/StaticPlugin.ts} +8 -4
- package/src/ts/server/api/api.ts +19 -0
- package/src/ts/server/api/connectorApi.ts +322 -0
- package/src/ts/server/api/publicationApi.ts +166 -0
- package/src/ts/server/api/websiteApi.ts +420 -0
- package/src/ts/server/cli.ts +7 -5
- package/src/ts/server/config.ts +107 -95
- package/src/ts/server/connectors/FsHosting.ts +60 -0
- package/src/ts/server/connectors/FsStorage.ts +247 -0
- package/src/ts/server/connectors/connectors.ts +173 -0
- package/src/ts/server/events.ts +20 -0
- package/src/ts/server/express.ts +4 -3
- package/src/ts/server/index.ts +19 -15
- package/src/ts/server/jobs.test.ts +1 -0
- package/src/ts/server/utils/BackwardCompat.ts +1 -1
- package/src/ts/server/utils/validation.ts +3 -2
- package/src/ts/types.ts +93 -61
- package/.silex/default/website.json +0 -1
- package/dist/client/client/grapesjs/eleventy.d.ts +0 -1
- package/dist/client/client/grapesjs/template.d.ts +0 -1
- package/dist/client/client/services.d.ts +0 -35
- package/dist/client/events.d.ts +0 -2
- package/dist/constants.d.ts +0 -21
- package/dist/constants.js +0 -41
- package/dist/constants.js.map +0 -1
- package/dist/events.d.ts +0 -2
- package/dist/events.js.map +0 -1
- package/dist/plugins/AuthPlugin.js.map +0 -1
- package/dist/plugins/Cache.js.map +0 -1
- package/dist/plugins/FtpBackend.d.ts +0 -92
- package/dist/plugins/FtpBackend.js +0 -604
- package/dist/plugins/FtpBackend.js.map +0 -1
- package/dist/plugins/HooksPlugin.js.map +0 -1
- package/dist/plugins/PublicationPlugin.d.ts +0 -17
- package/dist/plugins/PublicationPlugin.js +0 -170
- package/dist/plugins/PublicationPlugin.js.map +0 -1
- package/dist/plugins/SslPlugin.js.map +0 -1
- package/dist/plugins/StaticPlugin.js.map +0 -1
- package/dist/plugins/WebsitePlugin.d.ts +0 -14
- package/dist/plugins/WebsitePlugin.js +0 -302
- package/dist/plugins/WebsitePlugin.js.map +0 -1
- package/dist/server/backends/FsBackend.d.ts +0 -42
- package/dist/server/backends/FsBackend.js.map +0 -1
- package/dist/server/backends/index.d.ts +0 -95
- package/dist/server/backends/index.js +0 -255
- package/dist/server/backends/index.js.map +0 -1
- package/dist/server/config.d.ts +0 -58
- package/dist/server/config.js +0 -174
- package/dist/server/config.js.map +0 -1
- package/dist/server/jobs.js.map +0 -1
- package/dist/server/utils/validation.js.map +0 -1
- package/dist/types.d.ts +0 -270
- package/dist/types.js.map +0 -1
- package/src/ts/client/grapesjs/template.ts +0 -183
- package/src/ts/client/services.ts +0 -129
- package/src/ts/plugins/FtpBackend.ts +0 -689
- package/src/ts/plugins/PublicationPlugin.ts +0 -170
- package/src/ts/plugins/WebsitePlugin.ts +0 -318
- package/src/ts/server/backends/FsBackend.ts +0 -266
- package/src/ts/server/backends/index.ts +0 -309
- /package/dist/{server → plugins/client/server}/jobs.d.ts +0 -0
- /package/dist/{server → plugins/client/server}/utils/validation.d.ts +0 -0
- /package/dist/plugins/{AuthPlugin.d.ts → server/plugins/server/AuthPlugin.d.ts} +0 -0
- /package/dist/plugins/{AuthPlugin.js → server/plugins/server/AuthPlugin.js} +0 -0
- /package/dist/plugins/{Cache.d.ts → server/plugins/server/Cache.d.ts} +0 -0
- /package/dist/plugins/{Cache.js → server/plugins/server/Cache.js} +0 -0
- /package/dist/plugins/{SslPlugin.d.ts → server/plugins/server/SslPlugin.d.ts} +0 -0
- /package/dist/plugins/{StaticPlugin.d.ts → server/plugins/server/StaticPlugin.d.ts} +0 -0
- /package/dist/{server → plugins/server/server}/jobs.js +0 -0
- /package/src/ts/plugins/{AuthPlugin.ts → server/AuthPlugin.ts} +0 -0
- /package/src/ts/plugins/{Cache.ts → server/Cache.ts} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConnectorFile, StorageConnector, StatusCallback, ConnectorSession, ConnectorFileContent } from './connectors';
|
|
2
|
+
import { ConnectorUser, WebsiteMeta, WebsiteId, ConnectorType, WebsiteMetaFileContent, WebsiteData, ConnectorOptions } from '../../types';
|
|
3
|
+
import { ServerConfig } from '../config';
|
|
4
|
+
type FsSession = ConnectorSession;
|
|
5
|
+
interface FsOptions {
|
|
6
|
+
path?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class FsStorage implements StorageConnector<FsSession> {
|
|
9
|
+
connectorId: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
icon: string;
|
|
12
|
+
disableLogout: boolean;
|
|
13
|
+
options: {
|
|
14
|
+
path: string;
|
|
15
|
+
};
|
|
16
|
+
connectorType: ConnectorType;
|
|
17
|
+
constructor(config: ServerConfig | null, opts: FsOptions);
|
|
18
|
+
initFs(): Promise<void>;
|
|
19
|
+
updateStatus(filesStatuses: any, status: any, statusCbk: any): void;
|
|
20
|
+
initStatus(files: any): any;
|
|
21
|
+
getOptions(formData: object): ConnectorOptions;
|
|
22
|
+
getOAuthUrl(session: object): Promise<string | null>;
|
|
23
|
+
getLoginForm(session: object, redirectTo: string): Promise<string | null>;
|
|
24
|
+
getSettingsForm(session: object, redirectTo: string): Promise<string | null>;
|
|
25
|
+
isLoggedIn(session: FsSession): Promise<boolean>;
|
|
26
|
+
setToken(session: FsSession, query: object): Promise<void>;
|
|
27
|
+
logout(session: FsSession): Promise<void>;
|
|
28
|
+
getUser(session: FsSession): Promise<ConnectorUser>;
|
|
29
|
+
setWebsiteMeta(session: any, id: string, data: WebsiteMetaFileContent): Promise<void>;
|
|
30
|
+
getWebsiteMeta(session: FsSession, id: WebsiteId): Promise<WebsiteMeta>;
|
|
31
|
+
createWebsite(session: FsSession, meta: WebsiteMetaFileContent): Promise<WebsiteId>;
|
|
32
|
+
readWebsite(session: FsSession, websiteId: WebsiteId): Promise<WebsiteData>;
|
|
33
|
+
updateWebsite(session: FsSession, websiteId: WebsiteId, data: WebsiteData): Promise<void>;
|
|
34
|
+
deleteWebsite(session: FsSession, websiteId: WebsiteId): Promise<void>;
|
|
35
|
+
listWebsites(session: any): Promise<WebsiteMeta[]>;
|
|
36
|
+
getAsset(session: FsSession, id: WebsiteId, path: string): Promise<ConnectorFile>;
|
|
37
|
+
writeAssets(session: FsSession, id: WebsiteId, files: ConnectorFile[], statusCbk?: StatusCallback): Promise<string[]>;
|
|
38
|
+
deleteAssets(session: FsSession, id: WebsiteId, paths: string[]): Promise<void>;
|
|
39
|
+
readAsset(session: object, websiteId: string, fileName: string): Promise<ConnectorFileContent>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import fs, { stat } from 'fs/promises';
|
|
18
|
+
import { createWriteStream } from 'fs';
|
|
19
|
+
import { toConnectorData } from './connectors';
|
|
20
|
+
import { join } from 'path';
|
|
21
|
+
import { JobStatus, ConnectorType, defaultWebsiteData } from '../../types';
|
|
22
|
+
import { userInfo } from 'os';
|
|
23
|
+
import { requiredParam } from '../utils/validation';
|
|
24
|
+
import { DEFAULT_WEBSITE_ID, WEBSITE_DATA_FILE, WEBSITE_META_DATA_FILE } from '../../constants';
|
|
25
|
+
import { Readable } from 'stream';
|
|
26
|
+
import { v4 as uuid } from 'uuid';
|
|
27
|
+
const USER_ICON = 'data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' height=\'1em\' viewBox=\'0 0 448 512\'%3E%3Cpath d=\'M304 128a80 80 0 1 0 -160 0 80 80 0 1 0 160 0zM96 128a128 128 0 1 1 256 0A128 128 0 1 1 96 128zM49.3 464H398.7c-8.9-63.3-63.3-112-129-112H178.3c-65.7 0-120.1 48.7-129 112zM0 482.3C0 383.8 79.8 304 178.3 304h91.4C368.2 304 448 383.8 448 482.3c0 16.4-13.3 29.7-29.7 29.7H29.7C13.3 512 0 498.7 0 482.3z\'/%3E%3C/svg%3E';
|
|
28
|
+
const FILE_ICON = 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M6%202L6%2022%2018%2022%2018%207%2012%202%206%202Z%22%3E%3C%2Fpath%3E%3Cpath%20d%3D%22M18%202L12%202%2012%208%2018%208%2018%202Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E';
|
|
29
|
+
export class FsStorage {
|
|
30
|
+
connectorId = 'fs-storage';
|
|
31
|
+
displayName = 'File system storage';
|
|
32
|
+
icon = FILE_ICON;
|
|
33
|
+
disableLogout = true;
|
|
34
|
+
options;
|
|
35
|
+
connectorType = ConnectorType.STORAGE;
|
|
36
|
+
constructor(config, opts) {
|
|
37
|
+
this.options = {
|
|
38
|
+
path: __dirname + '../../../../.silex',
|
|
39
|
+
...opts,
|
|
40
|
+
};
|
|
41
|
+
this.initFs();
|
|
42
|
+
}
|
|
43
|
+
async initFs() {
|
|
44
|
+
const stat = await fs.stat(this.options.path).catch(() => null);
|
|
45
|
+
if (!stat) {
|
|
46
|
+
const id = DEFAULT_WEBSITE_ID;
|
|
47
|
+
await fs.mkdir(join(this.options.path, id), { recursive: true });
|
|
48
|
+
await this.setWebsiteMeta({}, id, { name: 'Default website', connectorUserSettings: {} });
|
|
49
|
+
await this.updateWebsite({}, id, defaultWebsiteData);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// ********************
|
|
53
|
+
// Job utils methods
|
|
54
|
+
// ********************
|
|
55
|
+
updateStatus(filesStatuses, status, statusCbk) {
|
|
56
|
+
statusCbk && statusCbk({
|
|
57
|
+
message: `<p>Writing files:<ul><li>${filesStatuses.map(({ file, message }) => `${file.path}: ${message}`).join('</li><li>')}</li></ul></p>`,
|
|
58
|
+
status,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
initStatus(files) {
|
|
62
|
+
return files.map(file => ({
|
|
63
|
+
file,
|
|
64
|
+
message: 'Waiting',
|
|
65
|
+
status: JobStatus.IN_PROGRESS,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
// ********************
|
|
69
|
+
// Connector interface
|
|
70
|
+
// ********************
|
|
71
|
+
getOptions(formData) {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
async getOAuthUrl(session) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
async getLoginForm(session, redirectTo) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
async getSettingsForm(session, redirectTo) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
async isLoggedIn(session) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
async setToken(session, query) { }
|
|
87
|
+
async logout(session) { }
|
|
88
|
+
async getUser(session) {
|
|
89
|
+
const { username, } = userInfo();
|
|
90
|
+
return {
|
|
91
|
+
name: username,
|
|
92
|
+
picture: USER_ICON,
|
|
93
|
+
storage: await toConnectorData(session, this),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async setWebsiteMeta(session, id, data) {
|
|
97
|
+
const websiteId = requiredParam(id, 'website id');
|
|
98
|
+
const content = JSON.stringify(data);
|
|
99
|
+
const path = join(this.options.path, id, WEBSITE_META_DATA_FILE);
|
|
100
|
+
await fs.writeFile(path, content);
|
|
101
|
+
}
|
|
102
|
+
async getWebsiteMeta(session, id) {
|
|
103
|
+
const websiteId = requiredParam(id, 'website id');
|
|
104
|
+
// Get stats for website folder
|
|
105
|
+
const fileStat = await stat(join(this.options.path, websiteId));
|
|
106
|
+
const path = join(this.options.path, websiteId, WEBSITE_META_DATA_FILE);
|
|
107
|
+
// Get meta file
|
|
108
|
+
const content = await fs.readFile(path);
|
|
109
|
+
const meta = await JSON.parse(content.toString());
|
|
110
|
+
// Return all meta
|
|
111
|
+
return {
|
|
112
|
+
websiteId,
|
|
113
|
+
name: meta.name,
|
|
114
|
+
imageUrl: meta.imageUrl,
|
|
115
|
+
connectorUserSettings: meta.connectorUserSettings,
|
|
116
|
+
createdAt: fileStat.birthtime,
|
|
117
|
+
updatedAt: fileStat.mtime,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// ********************
|
|
121
|
+
// Storage interface
|
|
122
|
+
// ********************
|
|
123
|
+
async createWebsite(session, meta) {
|
|
124
|
+
const id = uuid();
|
|
125
|
+
await fs.mkdir(join(this.options.path, id), { recursive: true });
|
|
126
|
+
await this.setWebsiteMeta(session, id, meta);
|
|
127
|
+
await this.updateWebsite(session, id, defaultWebsiteData);
|
|
128
|
+
return id;
|
|
129
|
+
}
|
|
130
|
+
async readWebsite(session, websiteId) {
|
|
131
|
+
const id = requiredParam(websiteId, 'website id');
|
|
132
|
+
const path = join(this.options.path, id, WEBSITE_DATA_FILE);
|
|
133
|
+
const content = await fs.readFile(path);
|
|
134
|
+
return JSON.parse(content.toString());
|
|
135
|
+
}
|
|
136
|
+
async updateWebsite(session, websiteId, data) {
|
|
137
|
+
const id = requiredParam(websiteId, 'website id');
|
|
138
|
+
const path = join(this.options.path, id, WEBSITE_DATA_FILE);
|
|
139
|
+
await fs.writeFile(path, JSON.stringify(data));
|
|
140
|
+
}
|
|
141
|
+
async deleteWebsite(session, websiteId) {
|
|
142
|
+
const id = requiredParam(websiteId, 'website id');
|
|
143
|
+
const path = join(this.options.path, id);
|
|
144
|
+
return fs.rmdir(path, { recursive: true });
|
|
145
|
+
}
|
|
146
|
+
async listWebsites(session) {
|
|
147
|
+
const list = await fs.readdir(this.options.path);
|
|
148
|
+
return Promise.all(list.map(async (fileName) => {
|
|
149
|
+
const websiteId = fileName;
|
|
150
|
+
return this.getWebsiteMeta(session, websiteId);
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
async getAsset(session, id, path) {
|
|
154
|
+
const fullPath = join(this.options.path, id, path);
|
|
155
|
+
const content = await fs.readFile(fullPath);
|
|
156
|
+
return { path, content };
|
|
157
|
+
}
|
|
158
|
+
async writeAssets(session, id, files, statusCbk) {
|
|
159
|
+
const filesStatuses = this.initStatus(files);
|
|
160
|
+
let error = false;
|
|
161
|
+
const filePaths = [];
|
|
162
|
+
for (const fileStatus of filesStatuses) {
|
|
163
|
+
const { file } = fileStatus;
|
|
164
|
+
const path = join(this.options.path, id, file.path);
|
|
165
|
+
filePaths.push(path);
|
|
166
|
+
if (typeof file.content === 'string' || Buffer.isBuffer(file.content)) {
|
|
167
|
+
fileStatus.message = 'Writing';
|
|
168
|
+
this.updateStatus(filesStatuses, JobStatus.IN_PROGRESS, statusCbk);
|
|
169
|
+
try {
|
|
170
|
+
await fs.writeFile(path, file.content, 'binary');
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
fileStatus.message = `Error (${err})`;
|
|
174
|
+
this.updateStatus(filesStatuses, JobStatus.IN_PROGRESS, statusCbk);
|
|
175
|
+
error = true;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
fileStatus.message = 'Success';
|
|
179
|
+
this.updateStatus(filesStatuses, JobStatus.IN_PROGRESS, statusCbk);
|
|
180
|
+
}
|
|
181
|
+
else if (file.content instanceof Readable) {
|
|
182
|
+
fileStatus.message = 'Writing';
|
|
183
|
+
this.updateStatus(filesStatuses, JobStatus.IN_PROGRESS, statusCbk);
|
|
184
|
+
const writeStream = createWriteStream(path);
|
|
185
|
+
file.content.pipe(writeStream);
|
|
186
|
+
await new Promise((resolve) => {
|
|
187
|
+
writeStream.on('finish', () => {
|
|
188
|
+
fileStatus.message = 'Success';
|
|
189
|
+
this.updateStatus(filesStatuses, JobStatus.IN_PROGRESS, statusCbk);
|
|
190
|
+
resolve(file);
|
|
191
|
+
});
|
|
192
|
+
writeStream.on('error', err => {
|
|
193
|
+
console.error('writeStream error', err);
|
|
194
|
+
fileStatus.message = `Error (${err})`;
|
|
195
|
+
this.updateStatus(filesStatuses, JobStatus.IN_PROGRESS, statusCbk);
|
|
196
|
+
error = true;
|
|
197
|
+
resolve(file);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
console.error('Invalid file content', typeof file.content);
|
|
203
|
+
throw new Error('Invalid file content: ' + typeof file.content);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
this.updateStatus(filesStatuses, error ? JobStatus.ERROR : JobStatus.SUCCESS, statusCbk);
|
|
207
|
+
return filePaths;
|
|
208
|
+
}
|
|
209
|
+
async deleteAssets(session, id, paths) {
|
|
210
|
+
for (const path of paths) {
|
|
211
|
+
await fs.unlink(join(this.options.path, id, path));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
async readAsset(session, websiteId, fileName) {
|
|
215
|
+
const id = requiredParam(websiteId, 'website id');
|
|
216
|
+
const path = join(this.options.path, id, fileName);
|
|
217
|
+
return await fs.readFile(path);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=FsStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FsStorage.js","sourceRoot":"","sources":["../../../../../src/ts/server/connectors/FsStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAA;AACtC,OAAO,EAAqE,eAAe,EAAuB,MAAM,cAAc,CAAA;AACtI,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAA8B,SAAS,EAAa,aAAa,EAAuC,kBAAkB,EAAoB,MAAM,aAAa,CAAA;AACxK,OAAO,EAAE,QAAQ,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AE;YACxB,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAA;SACnD;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAe,EAAE,SAAiB,EAAE,QAAgB;QAClE,MAAM,EAAE,GAAG,aAAa,CAAY,SAAS,EAAE,YAAY,CAAC,CAAA;QAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;QAClD,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { ServerConfig } from '../config';
|
|
5
|
+
import { JobStatus, JobData, ConnectorData, ConnectorId, WebsiteId, ConnectorType, ConnectorUser, WebsiteMeta, WebsiteMetaFileContent, WebsiteData, ConnectorOptions } from '../../types';
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview define types for Silex connectors
|
|
8
|
+
* Bakends can provide storage for website data and assets, and/or hosting to publish the website online
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Connector data stored in the website meta file
|
|
12
|
+
*/
|
|
13
|
+
export type ConnectorFileContent = string | Buffer | Readable;
|
|
14
|
+
/**
|
|
15
|
+
* Files are stored in connector as a File object
|
|
16
|
+
* @see types/ClientSideFile
|
|
17
|
+
* @see contentToString()
|
|
18
|
+
*/
|
|
19
|
+
export interface ConnectorFile {
|
|
20
|
+
path: string;
|
|
21
|
+
content: ConnectorFileContent;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Callback to update the publication status
|
|
25
|
+
*/
|
|
26
|
+
export type StatusCallback = ({ message, status }: {
|
|
27
|
+
message: string;
|
|
28
|
+
status: JobStatus;
|
|
29
|
+
}) => Promise<void>;
|
|
30
|
+
export type ConnectorSession = object;
|
|
31
|
+
/**
|
|
32
|
+
* Connectors are the base interface for Storage and Hosting connectors
|
|
33
|
+
*/
|
|
34
|
+
export interface Connector<Session extends ConnectorSession = ConnectorSession> {
|
|
35
|
+
connectorId: ConnectorId;
|
|
36
|
+
connectorType: ConnectorType;
|
|
37
|
+
displayName: string;
|
|
38
|
+
icon: string;
|
|
39
|
+
disableLogout?: boolean;
|
|
40
|
+
getOAuthUrl(session: Session): Promise<string | null>;
|
|
41
|
+
getLoginForm(session: Session, redirectTo: string): Promise<string | null>;
|
|
42
|
+
getSettingsForm(session: Session, redirectTo: string): Promise<string | null>;
|
|
43
|
+
isLoggedIn(session: Session): Promise<boolean>;
|
|
44
|
+
setToken(session: Session, token: object): Promise<void>;
|
|
45
|
+
logout(session: Session): Promise<void>;
|
|
46
|
+
getUser(session: Session): Promise<ConnectorUser>;
|
|
47
|
+
getWebsiteMeta(session: Session, websiteId: WebsiteId): Promise<WebsiteMeta>;
|
|
48
|
+
setWebsiteMeta(session: Session, websiteId: WebsiteId, data: WebsiteMetaFileContent): Promise<void>;
|
|
49
|
+
getOptions(formData: object): ConnectorOptions;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Storage are used to store the website data and assets
|
|
53
|
+
* And possibly rename files and directories, and get the URL of a file
|
|
54
|
+
*
|
|
55
|
+
*/
|
|
56
|
+
export interface StorageConnector<Session extends ConnectorSession = ConnectorSession> extends Connector<Session> {
|
|
57
|
+
listWebsites(session: Session): Promise<WebsiteMeta[]>;
|
|
58
|
+
readWebsite(session: Session, websiteId: WebsiteId): Promise<WebsiteData | Readable>;
|
|
59
|
+
createWebsite(session: Session, data: WebsiteMetaFileContent): Promise<WebsiteId>;
|
|
60
|
+
updateWebsite(session: Session, websiteId: WebsiteId, data: WebsiteData): Promise<void>;
|
|
61
|
+
deleteWebsite(session: Session, websiteId: WebsiteId): Promise<void>;
|
|
62
|
+
writeAssets(session: Session, websiteId: WebsiteId, files: ConnectorFile[], status?: StatusCallback): Promise<string[]>;
|
|
63
|
+
readAsset(session: Session, websiteId: WebsiteId, fileName: string): Promise<ConnectorFileContent>;
|
|
64
|
+
deleteAssets(session: Session, websiteId: WebsiteId, fileNames: string[]): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Hosting connectors are used to publish the website
|
|
68
|
+
*/
|
|
69
|
+
export interface HostingConnector<Session extends ConnectorSession = ConnectorSession> extends Connector<Session> {
|
|
70
|
+
publish(session: Session, websiteId: WebsiteId, files: ConnectorFile[]): Promise<JobData>;
|
|
71
|
+
getUrl(session: Session, websiteId: WebsiteId): Promise<string>;
|
|
72
|
+
}
|
|
73
|
+
export declare function toConnectorEnum(type: string): ConnectorType;
|
|
74
|
+
/**
|
|
75
|
+
* Get a connector by id or by type
|
|
76
|
+
*/
|
|
77
|
+
export declare function getConnector<T extends Connector>(config: ServerConfig, session: any, type: ConnectorType, connectorId?: ConnectorId): Promise<T | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Convert a connector to a ConnectorData object to be sent to the frontend
|
|
80
|
+
*/
|
|
81
|
+
export declare function toConnectorData(session: any, connector: Connector): Promise<ConnectorData>;
|
|
82
|
+
export declare function contentToString(content: ConnectorFileContent): Promise<string>;
|
|
83
|
+
export declare function contentToReadable(content: ConnectorFileContent): Readable;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import { Readable } from 'stream';
|
|
18
|
+
import { ConnectorType } from '../../types';
|
|
19
|
+
export function toConnectorEnum(type) {
|
|
20
|
+
const result = ConnectorType[type.toUpperCase()];
|
|
21
|
+
if (!result)
|
|
22
|
+
throw new Error('Unknown connector ' + type);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get a connector by id or by type
|
|
27
|
+
*/
|
|
28
|
+
export async function getConnector(config, session, type, connectorId) {
|
|
29
|
+
// Get the connectors for this type
|
|
30
|
+
const connectors = config.getConnectors(type);
|
|
31
|
+
// Find the connector by id
|
|
32
|
+
if (connectorId)
|
|
33
|
+
return connectors.find(s => s.connectorId === connectorId && s.connectorType === type);
|
|
34
|
+
// Find the first logged in connector
|
|
35
|
+
for (const connector of connectors) {
|
|
36
|
+
if (await connector.isLoggedIn(session)) {
|
|
37
|
+
return connector;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Defaults to the first connector
|
|
41
|
+
return connectors[0];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert a connector to a ConnectorData object to be sent to the frontend
|
|
45
|
+
*/
|
|
46
|
+
export async function toConnectorData(session, connector) {
|
|
47
|
+
return {
|
|
48
|
+
connectorId: connector.connectorId,
|
|
49
|
+
type: connector.connectorType,
|
|
50
|
+
displayName: connector.displayName,
|
|
51
|
+
icon: connector.icon,
|
|
52
|
+
disableLogout: !!connector.disableLogout,
|
|
53
|
+
isLoggedIn: await connector.isLoggedIn(session),
|
|
54
|
+
oauthUrl: await connector.getOAuthUrl(session),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export async function contentToString(content) {
|
|
58
|
+
// String
|
|
59
|
+
if (typeof content === 'string')
|
|
60
|
+
return content;
|
|
61
|
+
// Buffer
|
|
62
|
+
if (Buffer.isBuffer(content))
|
|
63
|
+
return content.toString('utf8');
|
|
64
|
+
// Stream
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
let result = '';
|
|
67
|
+
content.on('data', (chunk) => {
|
|
68
|
+
result += chunk.toString('utf8');
|
|
69
|
+
});
|
|
70
|
+
content.on('error', (err) => {
|
|
71
|
+
reject(err);
|
|
72
|
+
});
|
|
73
|
+
content.on('end', () => {
|
|
74
|
+
resolve(result);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export function contentToReadable(content) {
|
|
79
|
+
// String
|
|
80
|
+
if (typeof content === 'string')
|
|
81
|
+
return Readable.from([content]);
|
|
82
|
+
// Buffer
|
|
83
|
+
if (Buffer.isBuffer(content))
|
|
84
|
+
return Readable.from([content]);
|
|
85
|
+
// Stream
|
|
86
|
+
if (content instanceof Readable)
|
|
87
|
+
return content;
|
|
88
|
+
// Unknown
|
|
89
|
+
throw new Error('Unknown content type');
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=connectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectors.js","sourceRoot":"","sources":["../../../../../src/ts/server/connectors/connectors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAA6D,aAAa,EAAqF,MAAM,aAAa,CAAA;AAoFzL,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,EAAgC,CAAC,CAAA;IAC9E,IAAG,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAA;IACxD,OAAO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,CAAC,MAAM,CAAC,CAAA;IAC7D,SAAS;IACT,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,MAAM,GAAG,EAAE,CAAA;QACf,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YACnC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QACF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;YACjC,MAAM,CAAC,GAAG,CAAC,CAAA;QACb,CAAC,CAAC,CAAA;QACF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACrB,OAAO,CAAC,MAAM,CAAC,CAAA;QACjB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAA6B;IAC7D,SAAS;IACT,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;IAChE,SAAS;IACT,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;IAC7D,SAAS;IACT,IAAI,OAAO,YAAY,QAAQ;QAAE,OAAO,OAAO,CAAA;IAC/C,UAAU;IACV,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;AACzC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ConnectorId, PublicationData, WebsiteData, WebsiteId } from '../types';
|
|
2
|
+
import { ConnectorFile } from './connectors/connectors';
|
|
3
|
+
export declare enum ServerEvent {
|
|
4
|
+
STARTUP_START = "startup-start",
|
|
5
|
+
STARTUP_END = "startup-end",
|
|
6
|
+
PUBLISH_START = "publish-start",
|
|
7
|
+
PUBLISH_END = "publish-end",
|
|
8
|
+
WEBSITE_STORE_START = "store-start",
|
|
9
|
+
WEBSITE_STORE_END = "store-end",
|
|
10
|
+
WEBSITE_ASSET_STORE_START = "asset-store-start",
|
|
11
|
+
WEBSITE_ASSET_STORE_END = "asset-store-end"
|
|
12
|
+
}
|
|
13
|
+
export type PublishStartEventType = PublicationData;
|
|
14
|
+
export type PublishEndEventType = Error | null;
|
|
15
|
+
export type WebsiteStoreStartEventType = {
|
|
16
|
+
websiteId: WebsiteId;
|
|
17
|
+
websiteData: WebsiteData;
|
|
18
|
+
connectorId: ConnectorId;
|
|
19
|
+
};
|
|
20
|
+
export type WebsiteStoreEndEventType = Error | null;
|
|
21
|
+
export type WebsiteAssetStoreStartEventType = {
|
|
22
|
+
files: ConnectorFile[];
|
|
23
|
+
websiteId: WebsiteId;
|
|
24
|
+
connectorId: ConnectorId;
|
|
25
|
+
};
|
|
26
|
+
export type WebsiteAssetStoreEndEventType = Error | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var ServerEvent;
|
|
2
|
+
(function (ServerEvent) {
|
|
3
|
+
ServerEvent["STARTUP_START"] = "startup-start";
|
|
4
|
+
ServerEvent["STARTUP_END"] = "startup-end";
|
|
5
|
+
ServerEvent["PUBLISH_START"] = "publish-start";
|
|
6
|
+
ServerEvent["PUBLISH_END"] = "publish-end";
|
|
7
|
+
ServerEvent["WEBSITE_STORE_START"] = "store-start";
|
|
8
|
+
ServerEvent["WEBSITE_STORE_END"] = "store-end";
|
|
9
|
+
ServerEvent["WEBSITE_ASSET_STORE_START"] = "asset-store-start";
|
|
10
|
+
ServerEvent["WEBSITE_ASSET_STORE_END"] = "asset-store-end";
|
|
11
|
+
})(ServerEvent || (ServerEvent = {}));
|
|
12
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/ts/server/events.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,WASX;AATD,WAAY,WAAW;IACrB,8CAA+B,CAAA;IAC/B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,0CAA2B,CAAA;IAC3B,kDAAmC,CAAA;IACnC,8CAA+B,CAAA;IAC/B,8DAA+C,CAAA;IAC/C,0DAA2C,CAAA;AAC7C,CAAC,EATW,WAAW,KAAX,WAAW,QAStB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import { JobStatus } from '../types';
|
|
18
|
+
// Delay after which the job is deleted from memory
|
|
19
|
+
const TIME_TO_KEEP_AFTER_STOP = 60 * 10 * 1000; // 10 min
|
|
20
|
+
// Store the jobs in memory
|
|
21
|
+
const jobs = new Array();
|
|
22
|
+
// Key which will change on server restart
|
|
23
|
+
const processKey = Math.ceil(Math.random() * 1000000);
|
|
24
|
+
// Next id for the next job
|
|
25
|
+
let nextJobId = 0;
|
|
26
|
+
// Create a new job
|
|
27
|
+
export function startJob(message = '') {
|
|
28
|
+
const jobId = `${processKey}_${++nextJobId}`;
|
|
29
|
+
const job = {
|
|
30
|
+
jobId,
|
|
31
|
+
status: JobStatus.IN_PROGRESS,
|
|
32
|
+
message: message
|
|
33
|
+
};
|
|
34
|
+
jobs.push(job);
|
|
35
|
+
return job;
|
|
36
|
+
}
|
|
37
|
+
// Retriev a job if it exists
|
|
38
|
+
export function getJob(id) {
|
|
39
|
+
return jobs.find(job => job.jobId === id);
|
|
40
|
+
}
|
|
41
|
+
// End the job with success
|
|
42
|
+
export function jobSuccess(id, message = '') {
|
|
43
|
+
return end(id, JobStatus.SUCCESS, message);
|
|
44
|
+
}
|
|
45
|
+
// End the job with error
|
|
46
|
+
export function jobError(id, message = '') {
|
|
47
|
+
return end(id, JobStatus.ERROR, message);
|
|
48
|
+
}
|
|
49
|
+
// Remove a job from memory
|
|
50
|
+
// This is also used in unit tests to avoid memory lea
|
|
51
|
+
export function killJob(job) {
|
|
52
|
+
clearTimeout(job._timeout);
|
|
53
|
+
jobs.splice(jobs.findIndex(j => job.jobId === j.jobId), 1);
|
|
54
|
+
}
|
|
55
|
+
// End the job
|
|
56
|
+
function end(id, status, message = '') {
|
|
57
|
+
const job = getJob(id);
|
|
58
|
+
if (job) {
|
|
59
|
+
job.status = status;
|
|
60
|
+
if (message)
|
|
61
|
+
job.message = message;
|
|
62
|
+
job._timeout = setTimeout(() => killJob(job), TIME_TO_KEEP_AFTER_STOP);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=jobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../../../src/ts/server/jobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAW,SAAS,EAAS,MAAM,UAAU,CAAA;AAEpD,mDAAmD;AACnD,MAAM,uBAAuB,GAAG,EAAE,GAAC,EAAE,GAAC,IAAI,CAAA,CAAC,SAAS;AAEpD,2BAA2B;AAC3B,MAAM,IAAI,GAAG,IAAI,KAAK,EAAW,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AAC,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED,cAAc;AACd,SAAS,GAAG,CAAC,EAAS,EAAE,MAAiB,EAAE,OAAO,GAAG,EAAE;IACrD,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAA;IACtB,IAAG,GAAG,EAAE;QACN,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;QACnB,IAAG,OAAO;YAAE,GAAG,CAAC,OAAO,GAAG,OAAO,CAAA;QACjC,GAAG,CAAC,QAAQ,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,uBAAuB,CAAC,CAAA;QACtE,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Throw an error if a parameter is missing
|
|
19
|
+
* @param value the value to check
|
|
20
|
+
* @param name the name of the parameter
|
|
21
|
+
* @throws Error if the parameter is missing
|
|
22
|
+
*/
|
|
23
|
+
export function requiredParam(value, name, defaultValue) {
|
|
24
|
+
if (value === undefined) {
|
|
25
|
+
if (defaultValue !== undefined) {
|
|
26
|
+
return defaultValue;
|
|
27
|
+
}
|
|
28
|
+
const error = new Error(`Missing required parameter ${name}`);
|
|
29
|
+
console.error(`Missing required parameter ${name}`, error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../../../src/ts/server/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAI,KAAoB,EAAE,IAAY,EAAE,YAAgB;IACnF,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,IAAI,YAAY,KAAK,SAAS,EAAE;YAC9B,OAAO,YAA8B,CAAA;SACtC;QACD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,8BAA8B,IAAI,EAAE,CAAC,CAAA;QAC7D,OAAO,CAAC,KAAK,CAAC,8BAA8B,IAAI,EAAE,EAAE,KAAK,CAAC,CAAA;QAC1D,MAAM,KAAK,CAAA;KACZ;IACD,OAAO,KAAuB,CAAA;AAChC,CAAC"}
|