@silexlabs/silex 3.0.0-alpha.42 → 3.0.0-alpha.44
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/dist/client/client/api.d.ts +6 -6
- package/dist/client/client/config.d.ts +26 -211
- package/dist/client/client/events.d.ts +14 -0
- package/dist/client/client/expose.d.ts +1 -2
- package/dist/client/client/grapesjs/LoginDialog.d.ts +1 -0
- package/dist/client/client/grapesjs/index.d.ts +3 -209
- package/dist/client/client/index.d.ts +1 -0
- package/dist/client/constants.d.ts +2 -3
- package/dist/client/css/admin.css +7 -0
- package/dist/client/js/main.js +51 -51
- package/dist/client/types.d.ts +7 -1
- package/dist/plugins/client/client/events.d.ts +14 -0
- package/dist/plugins/client/client/events.js +32 -0
- package/dist/plugins/client/client/events.js.map +1 -0
- package/dist/plugins/client/page.d.ts +2 -0
- package/dist/plugins/client/{events.js → page.js} +15 -11
- 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.js +4 -4
- package/dist/plugins/client/plugins/client/template.js.map +1 -1
- package/dist/plugins/client/types.d.ts +315 -0
- package/dist/plugins/client/types.js +57 -0
- package/dist/plugins/client/types.js.map +1 -0
- package/dist/plugins/server/constants.d.ts +2 -3
- package/dist/plugins/server/constants.js +3 -4
- package/dist/plugins/server/constants.js.map +1 -1
- package/dist/plugins/server/plugins/server/FtpConnector.d.ts +17 -28
- package/dist/plugins/server/plugins/server/FtpConnector.js +17 -16
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -1
- package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +81 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js +373 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/HooksPlugin.js +8 -8
- package/dist/plugins/server/plugins/server/HooksPlugin.js.map +1 -1
- 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/server/plugins/server/SslPlugin.js +2 -2
- package/dist/plugins/server/plugins/server/SslPlugin.js.map +1 -1
- package/dist/plugins/server/plugins/server/StaticPlugin.js +2 -2
- package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -1
- package/dist/plugins/server/server/config.d.ts +18 -18
- package/dist/plugins/server/server/config.js +79 -81
- package/dist/plugins/server/server/config.js.map +1 -1
- package/dist/plugins/server/server/connectors/FsStorage.d.ts +13 -11
- package/dist/plugins/server/server/connectors/FsStorage.js +31 -14
- package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -1
- package/dist/plugins/server/server/connectors/connectors.d.ts +5 -2
- package/dist/plugins/server/server/connectors/connectors.js +32 -3
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -1
- 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/types.d.ts +7 -1
- package/dist/plugins/server/types.js +10 -1
- package/dist/plugins/server/types.js.map +1 -1
- package/dist/server/constants.js +3 -4
- package/dist/server/server/api/connectorApi.js +16 -11
- package/dist/server/server/api/publicationApi.js +26 -28
- package/dist/server/server/api/websiteApi.js +46 -41
- package/dist/server/server/cli.js +36 -18
- package/dist/server/server/config.js +63 -66
- package/dist/server/server/connectors/FsStorage.js +28 -14
- package/dist/server/server/connectors/connectors.js +27 -3
- package/dist/server/server/events.js +14 -0
- package/dist/server/server/expose.js +27 -0
- package/dist/server/server/express.js +3 -3
- package/dist/server/server/index.js +34 -4
- package/dist/server/types.js +10 -1
- package/package.json +6 -3
- package/src/css/_variables.scss +1 -0
- package/src/css/grapesjs.scss +5 -0
- package/src/css/loader.scss +2 -0
- package/src/ts/client/api.ts +8 -11
- package/src/ts/client/config.ts +30 -14
- package/src/ts/client/events.ts +31 -0
- package/src/ts/client/expose.ts +1 -2
- package/src/ts/client/grapesjs/LoginDialog.ts +12 -1
- package/src/ts/client/grapesjs/PublicationManager.ts +10 -10
- package/src/ts/client/grapesjs/eleventy.ts +2 -2
- package/src/ts/client/grapesjs/index.ts +8 -13
- package/src/ts/client/grapesjs/storage.ts +18 -10
- package/src/ts/client/index.ts +35 -16
- package/src/ts/constants.ts +2 -3
- package/src/ts/plugins/client/publicationRenderer.ts +128 -0
- package/src/ts/plugins/client/template.ts +4 -4
- package/src/ts/plugins/server/FtpConnector.test.ts +82 -0
- package/src/ts/plugins/server/FtpConnector.ts +31 -37
- package/src/ts/plugins/server/GitlabConnector.ts +434 -0
- package/src/ts/plugins/server/HooksPlugin.ts +8 -9
- package/src/ts/plugins/server/PublicationOptimizer.ts +14 -0
- package/src/ts/plugins/server/SslPlugin.ts +2 -2
- package/src/ts/plugins/server/StaticPlugin.ts +2 -2
- package/src/ts/server/api/connectorApi.ts +32 -27
- package/src/ts/server/api/publicationApi.ts +35 -48
- package/src/ts/server/api/websiteApi.ts +67 -45
- package/src/ts/server/cli.ts +25 -13
- package/src/ts/server/config.ts +80 -79
- package/src/ts/server/connectors/FsStorage.test.ts +51 -0
- package/src/ts/server/connectors/FsStorage.ts +45 -24
- package/src/ts/server/connectors/connectors.ts +35 -5
- package/src/ts/server/events.ts +20 -0
- package/src/ts/{events.ts → server/expose.ts} +2 -10
- package/src/ts/server/express.ts +3 -3
- package/src/ts/server/index.ts +36 -10
- package/src/ts/types.ts +10 -1
- package/.silex/default/website.json +0 -1
- package/dist/client/events.d.ts +0 -10
- package/dist/plugins/client/events.d.ts +0 -10
- package/dist/plugins/client/events.js.map +0 -1
- package/dist/plugins/server/events.d.ts +0 -10
- package/dist/plugins/server/events.js +0 -30
- package/dist/plugins/server/events.js.map +0 -1
- package/dist/server/events.js +0 -13
|
@@ -13,7 +13,11 @@ export interface WebsiteFile {
|
|
|
13
13
|
htmlPath: string;
|
|
14
14
|
cssPath: string;
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export declare class ApiError extends Error {
|
|
17
|
+
readonly httpStatusCode: number;
|
|
18
|
+
constructor(message: string, httpStatusCode: number);
|
|
19
|
+
}
|
|
20
|
+
export type ApiResponseError = {
|
|
17
21
|
message: string;
|
|
18
22
|
};
|
|
19
23
|
export type ApiPublicationPublishBody = WebsiteData;
|
|
@@ -252,6 +256,8 @@ export interface ConnectorData {
|
|
|
252
256
|
disableLogout: boolean;
|
|
253
257
|
isLoggedIn: boolean;
|
|
254
258
|
oauthUrl: string | null;
|
|
259
|
+
color: string;
|
|
260
|
+
background: string;
|
|
255
261
|
}
|
|
256
262
|
/**
|
|
257
263
|
* User settings for a connector and for a given website
|
|
@@ -16,7 +16,16 @@
|
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.JobStatus = exports.ConnectorType = exports.Unit = exports.defaultWebsiteData = void 0;
|
|
19
|
+
exports.JobStatus = exports.ConnectorType = exports.Unit = exports.defaultWebsiteData = exports.ApiError = void 0;
|
|
20
|
+
class ApiError extends Error {
|
|
21
|
+
httpStatusCode;
|
|
22
|
+
constructor(message, httpStatusCode) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.httpStatusCode = httpStatusCode;
|
|
25
|
+
console.info('API error', httpStatusCode, message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ApiError = ApiError;
|
|
20
29
|
// **
|
|
21
30
|
// Website API
|
|
22
31
|
exports.defaultWebsiteData = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ts/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ts/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAqBH,MAAa,QAAS,SAAQ,KAAK;IACY;IAA7C,YAAY,OAAe,EAAkB,cAAsB;QACjE,KAAK,CAAC,OAAO,CAAC,CAAA;QAD6B,mBAAc,GAAd,cAAc,CAAQ;QAEjE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,CAAA;IACpD,CAAC;CACF;AALD,4BAKC;AA+CD,KAAK;AACL,cAAc;AACD,QAAA,kBAAkB,GAAgB;AAC7C,YAAY;AACZ,aAAa;AACb,aAAa;AACb,eAAe;AACf,YAAY;AACZ,cAAc;AACd,kBAAkB;CACJ,CAAA;AAyDhB,IAAY,IAEX;AAFD,WAAY,IAAI;IACd,iBAAS,CAAA;AACX,CAAC,EAFW,IAAI,oBAAJ,IAAI,QAEf;AAoDD;;GAEG;AACH,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,oCAAmB,CAAA;AACrB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAuDD;;GAEG;AACH,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,gCAAmB,CAAA;IACnB,4BAAe,CAAA;AACjB,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
|
package/dist/server/constants.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.API_WEBSITE_META_WRITE = exports.API_WEBSITE_META_READ = exports.API_WEBSITE_ASSETS_WRITE = exports.
|
|
3
|
+
exports.API_WEBSITE_META_WRITE = exports.API_WEBSITE_META_READ = exports.API_WEBSITE_ASSETS_WRITE = exports.API_WEBSITE_ASSET_READ = exports.API_WEBSITE_LIST = exports.API_WEBSITE_DELETE = exports.API_WEBSITE_CREATE = exports.API_WEBSITE_WRITE = exports.API_WEBSITE_READ = exports.API_WEBSITE_PATH = exports.API_PUBLICATION_STATUS = exports.API_PUBLICATION_PUBLISH = exports.API_PUBLICATION_PATH = exports.API_CONNECTOR_LOGIN_CALLBACK = exports.API_CONNECTOR_SETTINGS = exports.API_CONNECTOR_LOGIN = exports.API_CONNECTOR_LOGOUT = exports.API_CONNECTOR_LIST = exports.API_CONNECTOR_USER = exports.API_CONNECTOR_PATH = exports.API_PATH = exports.CLIENT_CONFIG_FILE_NAME = exports.DEFAULT_LANGUAGE = exports.DEFAULT_WEBSITE_ID = exports.WEBSITE_META_DATA_FILE = exports.WEBSITE_DATA_FILE = void 0;
|
|
4
4
|
exports.WEBSITE_DATA_FILE = 'website.json';
|
|
5
5
|
exports.WEBSITE_META_DATA_FILE = 'meta.json';
|
|
6
6
|
exports.DEFAULT_WEBSITE_ID = 'default';
|
|
7
|
-
exports.DEFAULT_CONNECTOR_ID = '';
|
|
8
7
|
exports.DEFAULT_LANGUAGE = 'en';
|
|
9
8
|
exports.CLIENT_CONFIG_FILE_NAME = 'silex.js';
|
|
10
9
|
exports.API_PATH = '/api';
|
|
@@ -24,7 +23,7 @@ exports.API_WEBSITE_WRITE = '/';
|
|
|
24
23
|
exports.API_WEBSITE_CREATE = '/';
|
|
25
24
|
exports.API_WEBSITE_DELETE = '/';
|
|
26
25
|
exports.API_WEBSITE_LIST = '/';
|
|
27
|
-
exports.
|
|
28
|
-
exports.API_WEBSITE_ASSETS_WRITE = 'assets';
|
|
26
|
+
exports.API_WEBSITE_ASSET_READ = '/assets';
|
|
27
|
+
exports.API_WEBSITE_ASSETS_WRITE = '/assets';
|
|
29
28
|
exports.API_WEBSITE_META_READ = '/meta';
|
|
30
29
|
exports.API_WEBSITE_META_WRITE = '/meta';
|
|
@@ -45,7 +45,7 @@ async function routeUser(req, res) {
|
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
47
|
console.error('Error in the login status request', error);
|
|
48
|
-
res.status(error?.code ?? 500).json({
|
|
48
|
+
res.status(error?.code ?? error?.httpStatusCode ?? 500).json({
|
|
49
49
|
error: true,
|
|
50
50
|
message: error.message,
|
|
51
51
|
});
|
|
@@ -64,7 +64,7 @@ async function routeListConnectors(req, res) {
|
|
|
64
64
|
}
|
|
65
65
|
catch (error) {
|
|
66
66
|
console.error('Error while listing connectors', error);
|
|
67
|
-
res.status(error?.code ?? 500).json({
|
|
67
|
+
res.status(error?.code ?? error?.httpStatusCode ?? 500).json({
|
|
68
68
|
error: true,
|
|
69
69
|
message: 'Error while listing connectors: ' + error.message,
|
|
70
70
|
});
|
|
@@ -72,7 +72,7 @@ async function routeListConnectors(req, res) {
|
|
|
72
72
|
}
|
|
73
73
|
catch (error) {
|
|
74
74
|
console.error('Error in the list connectors request', error);
|
|
75
|
-
res.status(error?.code ?? 400).json({
|
|
75
|
+
res.status(error?.code ?? error?.httpStatusCode ?? 400).json({
|
|
76
76
|
error: true,
|
|
77
77
|
message: 'Error in the list connectors request: ' + error.message,
|
|
78
78
|
});
|
|
@@ -105,7 +105,7 @@ async function routeLogin(req, res) {
|
|
|
105
105
|
}
|
|
106
106
|
catch (error) {
|
|
107
107
|
console.error('Error in the login request', error);
|
|
108
|
-
res.status(error?.code ?? 400).json({
|
|
108
|
+
res.status(error?.code ?? error?.httpStatusCode ?? 400).json({
|
|
109
109
|
error: true,
|
|
110
110
|
message: 'Error in the login request: ' + error.message,
|
|
111
111
|
});
|
|
@@ -124,15 +124,20 @@ async function routeLoginSuccess(req, res) {
|
|
|
124
124
|
const connector = await (0, connectors_1.getConnector)(config, req['session'], type, connectorId);
|
|
125
125
|
if (!connector)
|
|
126
126
|
throw new Error('Connector not found ' + connectorId);
|
|
127
|
-
await connector.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
if (await connector.isLoggedIn(session)) {
|
|
128
|
+
console.info('User already logged in for connector ' + connectorId);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
await connector.setToken(session, {
|
|
132
|
+
...query,
|
|
133
|
+
...body,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
131
136
|
res.send(getEndAuthHtml('Logged in', false, connectorId, connector.getOptions(body)));
|
|
132
137
|
}
|
|
133
138
|
catch (error) {
|
|
134
139
|
res
|
|
135
|
-
.status(error?.code ?? 500)
|
|
140
|
+
.status(error?.code ?? error?.httpStatusCode ?? 500)
|
|
136
141
|
.send(getEndAuthHtml(error.message, true));
|
|
137
142
|
}
|
|
138
143
|
}
|
|
@@ -155,7 +160,7 @@ async function routeLogout(req, res) {
|
|
|
155
160
|
}
|
|
156
161
|
catch (error) {
|
|
157
162
|
console.error('Error while logging out', error);
|
|
158
|
-
res.status(error?.code ?? 500).json({
|
|
163
|
+
res.status(error?.code ?? error?.httpStatusCode ?? 500).json({
|
|
159
164
|
error: true,
|
|
160
165
|
message: 'Error while logging out: ' + error.message,
|
|
161
166
|
});
|
|
@@ -164,7 +169,7 @@ async function routeLogout(req, res) {
|
|
|
164
169
|
}
|
|
165
170
|
catch (error) {
|
|
166
171
|
console.error('Error in the logout request', error);
|
|
167
|
-
res.status(error?.code ?? 400).json({
|
|
172
|
+
res.status(error?.code ?? error?.httpStatusCode ?? 400).json({
|
|
168
173
|
error: true,
|
|
169
174
|
message: 'Error in the logout request: ' + error.message,
|
|
170
175
|
});
|
|
@@ -7,7 +7,7 @@ const jobs_1 = require("../jobs");
|
|
|
7
7
|
const types_1 = require("../../types");
|
|
8
8
|
const connectors_1 = require("../connectors/connectors");
|
|
9
9
|
const validation_1 = require("../utils/validation");
|
|
10
|
-
const
|
|
10
|
+
const events_1 = require("../events");
|
|
11
11
|
class PublicationError extends Error {
|
|
12
12
|
code;
|
|
13
13
|
constructor(message, code) {
|
|
@@ -16,6 +16,7 @@ class PublicationError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.PublicationError = PublicationError;
|
|
19
|
+
const PROJECT_ROOT = require.main ? require.main.path : process.cwd();
|
|
19
20
|
async function getHostingConnector(session, config, connectorId) {
|
|
20
21
|
const hostingConnector = await (0, connectors_1.getConnector)(config, session, types_1.ConnectorType.HOSTING, connectorId);
|
|
21
22
|
if (!hostingConnector) {
|
|
@@ -38,12 +39,7 @@ async function getStorageConnector(session, config, connectorId) {
|
|
|
38
39
|
return storageConnector;
|
|
39
40
|
}
|
|
40
41
|
exports.getStorageConnector = getStorageConnector;
|
|
41
|
-
function default_1(config
|
|
42
|
-
const options = {
|
|
43
|
-
statusUrl: process.env.SILEX_PUBLICATION_STATUS_URL,
|
|
44
|
-
connector: 'src/plugins/DefaultConnector.js',
|
|
45
|
-
...opts,
|
|
46
|
-
};
|
|
42
|
+
function default_1(config) {
|
|
47
43
|
const router = (0, express_1.Router)();
|
|
48
44
|
router.get(constants_1.API_PUBLICATION_STATUS, async function (req, res) {
|
|
49
45
|
const query = req.query;
|
|
@@ -69,47 +65,49 @@ function default_1(config, opts = {}) {
|
|
|
69
65
|
const storageId = (0, validation_1.requiredParam)(query.storageId, 'storageId in query');
|
|
70
66
|
const hostingId = (0, validation_1.requiredParam)(query.hostingId, 'hostingId in query');
|
|
71
67
|
const session = (0, validation_1.requiredParam)(req['session'], 'session on express request');
|
|
72
|
-
const
|
|
68
|
+
const data = body;
|
|
69
|
+
const { files, publication, assets } = data;
|
|
73
70
|
if (!files || !publication || !assets) {
|
|
74
71
|
throw new PublicationError('Missing data from request: files, publication or assets', 400);
|
|
75
72
|
}
|
|
73
|
+
config.emit(events_1.ServerEvent.PUBLISH_START, data);
|
|
76
74
|
const hostingConnector = await getHostingConnector(session, config, hostingId);
|
|
77
75
|
const storage = await getStorageConnector(session, config, storageId);
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
const assetsFiles = await Promise.all(assets.map(async (asset) => {
|
|
77
|
+
if (!asset.path)
|
|
78
|
+
throw new PublicationError('Missing path in asset', 400);
|
|
79
|
+
if (!asset.src)
|
|
80
|
+
throw new PublicationError('Missing src in asset', 400);
|
|
81
|
+
const prefix = constants_1.API_WEBSITE_ASSET_READ.replace(/^\//, '');
|
|
82
|
+
const src = asset.src.startsWith(prefix) ? asset.src.substring(prefix.length) : asset.src;
|
|
83
|
+
return {
|
|
84
|
+
path: asset.path,
|
|
85
|
+
content: await storage.readAsset(session, websiteId, src),
|
|
86
|
+
};
|
|
87
|
+
}));
|
|
88
|
+
const filesList = files.flatMap(file => ([{
|
|
84
89
|
path: file.htmlPath,
|
|
85
90
|
content: file.html,
|
|
86
91
|
}, {
|
|
87
92
|
path: file.cssPath,
|
|
88
93
|
content: file.css,
|
|
89
94
|
}])).concat(assetsFiles);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (err) {
|
|
97
|
-
console.error('Error publishing the website', err);
|
|
98
|
-
res.status(500).json({
|
|
99
|
-
message: `Error publishing the website. ${err.message}`
|
|
100
|
-
});
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
95
|
+
res.json({
|
|
96
|
+
url: await hostingConnector.getUrl(session, websiteId),
|
|
97
|
+
job: await hostingConnector.publish(session, websiteId, filesList),
|
|
98
|
+
});
|
|
103
99
|
}
|
|
104
100
|
catch (err) {
|
|
105
101
|
console.error('Error publishing the website', err);
|
|
106
102
|
res
|
|
107
|
-
.status(err.code
|
|
103
|
+
.status(typeof err.code === 'number' ? err.code : 500)
|
|
108
104
|
.json({
|
|
109
105
|
message: `Error publishing the website. ${err.message}`
|
|
110
106
|
});
|
|
107
|
+
config.emit(events_1.ServerEvent.PUBLISH_END, err);
|
|
111
108
|
return;
|
|
112
109
|
}
|
|
110
|
+
config.emit(events_1.ServerEvent.PUBLISH_END);
|
|
113
111
|
});
|
|
114
112
|
return router;
|
|
115
113
|
}
|
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WebsiteError = void 0;
|
|
7
6
|
const express_1 = require("express");
|
|
8
7
|
const formidable_1 = __importDefault(require("formidable"));
|
|
9
8
|
const constants_1 = require("../../constants");
|
|
@@ -13,14 +12,7 @@ const connectors_1 = require("../connectors/connectors");
|
|
|
13
12
|
const stream_1 = require("stream");
|
|
14
13
|
const validation_1 = require("../utils/validation");
|
|
15
14
|
const path_1 = require("path");
|
|
16
|
-
|
|
17
|
-
code;
|
|
18
|
-
constructor(message, code) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.code = code;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.WebsiteError = WebsiteError;
|
|
15
|
+
const events_1 = require("../events");
|
|
24
16
|
function default_1(config, opts = {}) {
|
|
25
17
|
const options = {
|
|
26
18
|
assetsPath: '/assets',
|
|
@@ -45,9 +37,8 @@ function default_1(config, opts = {}) {
|
|
|
45
37
|
}
|
|
46
38
|
}
|
|
47
39
|
catch (e) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
res.status(e.code).json({ message: e.message });
|
|
40
|
+
if (e.httpStatusCode) {
|
|
41
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
51
42
|
}
|
|
52
43
|
else {
|
|
53
44
|
res.status(500).json({ message: e.message });
|
|
@@ -64,8 +55,8 @@ function default_1(config, opts = {}) {
|
|
|
64
55
|
}
|
|
65
56
|
catch (e) {
|
|
66
57
|
console.error('Error getting website data', e);
|
|
67
|
-
if (e
|
|
68
|
-
res.status(e.
|
|
58
|
+
if (e.httpStatusCode) {
|
|
59
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
69
60
|
}
|
|
70
61
|
else {
|
|
71
62
|
res.status(500).json({ message: e.message });
|
|
@@ -78,13 +69,17 @@ function default_1(config, opts = {}) {
|
|
|
78
69
|
const body = req.body;
|
|
79
70
|
const websiteId = (0, validation_1.requiredParam)(query.websiteId, 'Website id');
|
|
80
71
|
const websiteData = (0, validation_1.requiredParam)(body, 'Website data');
|
|
81
|
-
|
|
72
|
+
const connectorId = query.connectorId;
|
|
73
|
+
config.emit(events_1.ServerEvent.WEBSITE_STORE_START, { websiteId, websiteData, connectorId });
|
|
74
|
+
await writeWebsite(req['session'], websiteId, websiteData, connectorId);
|
|
75
|
+
config.emit(events_1.ServerEvent.WEBSITE_STORE_END, null);
|
|
82
76
|
res.status(200).json({ message: 'Website saved' });
|
|
83
77
|
}
|
|
84
78
|
catch (e) {
|
|
85
79
|
console.error('Error saving website data', e);
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
config.emit(events_1.ServerEvent.WEBSITE_STORE_END, e);
|
|
81
|
+
if (e.httpStatusCode) {
|
|
82
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
88
83
|
}
|
|
89
84
|
else {
|
|
90
85
|
res.status(500).json({ message: e.message });
|
|
@@ -100,15 +95,15 @@ function default_1(config, opts = {}) {
|
|
|
100
95
|
const connectorId = query.connectorId;
|
|
101
96
|
const connector = await (0, connectors_1.getConnector)(config, session, types_1.ConnectorType.STORAGE, connectorId);
|
|
102
97
|
if (!connector) {
|
|
103
|
-
throw new
|
|
98
|
+
throw new types_1.ApiError(`Connector ${connectorId} not found`, 500);
|
|
104
99
|
}
|
|
105
100
|
await connector.createWebsite(session, websiteMeta);
|
|
106
101
|
res.json({ message: 'Website meta saved' });
|
|
107
102
|
}
|
|
108
103
|
catch (e) {
|
|
109
104
|
console.error('Error saving website meta', e);
|
|
110
|
-
if (e
|
|
111
|
-
res.status(e.
|
|
105
|
+
if (e.httpStatusCode) {
|
|
106
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
112
107
|
}
|
|
113
108
|
else {
|
|
114
109
|
res.status(500).json({ message: e.message });
|
|
@@ -125,15 +120,15 @@ function default_1(config, opts = {}) {
|
|
|
125
120
|
const connectorId = query.connectorId;
|
|
126
121
|
const connector = await (0, connectors_1.getConnector)(config, session, types_1.ConnectorType.STORAGE, connectorId);
|
|
127
122
|
if (!connector) {
|
|
128
|
-
throw new
|
|
123
|
+
throw new types_1.ApiError(`Connector ${connectorId} not found`, 500);
|
|
129
124
|
}
|
|
130
125
|
await connector.setWebsiteMeta(session, websiteId, websiteMeta);
|
|
131
126
|
res.json({ message: 'Website meta saved' });
|
|
132
127
|
}
|
|
133
128
|
catch (e) {
|
|
134
129
|
console.error('Error saving website meta', e);
|
|
135
|
-
if (e
|
|
136
|
-
res.status(e.
|
|
130
|
+
if (e.httpStatusCode) {
|
|
131
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
137
132
|
}
|
|
138
133
|
else {
|
|
139
134
|
res.status(500).json({ message: e.message });
|
|
@@ -148,15 +143,15 @@ function default_1(config, opts = {}) {
|
|
|
148
143
|
const connectorId = query.connectorId;
|
|
149
144
|
const connector = await (0, connectors_1.getConnector)(config, session, types_1.ConnectorType.STORAGE, connectorId);
|
|
150
145
|
if (!connector) {
|
|
151
|
-
throw new
|
|
146
|
+
throw new types_1.ApiError(`Connector ${connectorId} not found`, 500);
|
|
152
147
|
}
|
|
153
148
|
const websiteMeta = await connector.getWebsiteMeta(session, websiteId);
|
|
154
149
|
res.json(websiteMeta);
|
|
155
150
|
}
|
|
156
151
|
catch (e) {
|
|
157
152
|
console.error('Error getting website meta', e);
|
|
158
|
-
if (e
|
|
159
|
-
res.status(e.
|
|
153
|
+
if (e.httpStatusCode) {
|
|
154
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
160
155
|
}
|
|
161
156
|
else {
|
|
162
157
|
res.status(500).json({ message: e.message });
|
|
@@ -172,15 +167,15 @@ function default_1(config, opts = {}) {
|
|
|
172
167
|
}
|
|
173
168
|
catch (e) {
|
|
174
169
|
console.error('Error deleting website data', e);
|
|
175
|
-
if (e
|
|
176
|
-
res.status(e.
|
|
170
|
+
if (e.httpStatusCode) {
|
|
171
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
177
172
|
}
|
|
178
173
|
else {
|
|
179
174
|
res.status(500).json({ message: e.message });
|
|
180
175
|
}
|
|
181
176
|
}
|
|
182
177
|
});
|
|
183
|
-
router.get(constants_1.
|
|
178
|
+
router.get(constants_1.API_WEBSITE_ASSET_READ + '/:path', async (req, res) => {
|
|
184
179
|
{
|
|
185
180
|
try {
|
|
186
181
|
const query = req.query;
|
|
@@ -198,8 +193,8 @@ function default_1(config, opts = {}) {
|
|
|
198
193
|
}
|
|
199
194
|
catch (e) {
|
|
200
195
|
console.error('Error getting asset', e);
|
|
201
|
-
if (e
|
|
202
|
-
res.status(e.
|
|
196
|
+
if (e.httpStatusCode) {
|
|
197
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
203
198
|
}
|
|
204
199
|
else {
|
|
205
200
|
res.status(500).json({ message: e.message });
|
|
@@ -216,45 +211,51 @@ function default_1(config, opts = {}) {
|
|
|
216
211
|
multiples: true,
|
|
217
212
|
keepExtensions: true,
|
|
218
213
|
});
|
|
214
|
+
const connectorId = query.connectorId;
|
|
219
215
|
const files = await new Promise((resolve, reject) => {
|
|
220
216
|
form.parse(req, async (err, fields, _files) => {
|
|
221
217
|
if (err) {
|
|
222
218
|
console.error('Error parsing upload data', err);
|
|
223
|
-
reject(new
|
|
219
|
+
reject(new types_1.ApiError('Error parsing upload data: ' + err.message, 400));
|
|
224
220
|
}
|
|
225
221
|
else {
|
|
226
222
|
const files = [].concat(_files['files[]'])
|
|
227
223
|
.map(file => file.toJSON())
|
|
228
224
|
.map(file => ({
|
|
229
|
-
path:
|
|
225
|
+
path: `/${file.originalFilename}`,
|
|
230
226
|
content: (0, fs_1.createReadStream)(file.filepath),
|
|
231
227
|
}));
|
|
232
228
|
resolve(files);
|
|
233
229
|
}
|
|
234
230
|
});
|
|
235
231
|
});
|
|
236
|
-
|
|
232
|
+
config.emit(events_1.ServerEvent.WEBSITE_ASSET_STORE_START, { files, websiteId, connectorId });
|
|
233
|
+
await writeAssets(req['session'], websiteId, files, connectorId);
|
|
237
234
|
res.json({
|
|
238
|
-
data
|
|
235
|
+
data: files.map(file => constants_1.API_PATH + constants_1.API_WEBSITE_PATH + constants_1.API_WEBSITE_ASSET_READ
|
|
236
|
+
+ file.path
|
|
237
|
+
+ `?websiteId=${websiteId}&connectorId=${connectorId ? connectorId : ''}`),
|
|
239
238
|
});
|
|
239
|
+
config.emit(events_1.ServerEvent.WEBSITE_ASSET_STORE_END, null);
|
|
240
240
|
}
|
|
241
241
|
catch (e) {
|
|
242
242
|
console.error('Error uploading assets', e);
|
|
243
|
-
if (e
|
|
244
|
-
res.status(e.
|
|
243
|
+
if (e.httpStatusCode) {
|
|
244
|
+
res.status(e.httpStatusCode).json({ message: e.message });
|
|
245
245
|
}
|
|
246
246
|
else {
|
|
247
247
|
res.status(500).json({ message: e.message });
|
|
248
248
|
}
|
|
249
|
+
config.emit(events_1.ServerEvent.WEBSITE_ASSET_STORE_END, e);
|
|
249
250
|
}
|
|
250
251
|
});
|
|
251
252
|
async function getStorageConnector(session, connectorId) {
|
|
252
253
|
const storageConnector = await (0, connectors_1.getConnector)(config, session, types_1.ConnectorType.STORAGE, connectorId);
|
|
253
254
|
if (!storageConnector) {
|
|
254
|
-
throw new
|
|
255
|
+
throw new types_1.ApiError('No storage connector found', 404);
|
|
255
256
|
}
|
|
256
257
|
if (!await storageConnector.isLoggedIn(session)) {
|
|
257
|
-
throw new
|
|
258
|
+
throw new types_1.ApiError('Not logged in', 401);
|
|
258
259
|
}
|
|
259
260
|
return storageConnector;
|
|
260
261
|
}
|
|
@@ -276,11 +277,15 @@ function default_1(config, opts = {}) {
|
|
|
276
277
|
}
|
|
277
278
|
async function readAsset(session, websiteId, fileName, connectorId) {
|
|
278
279
|
const storageConnector = await getStorageConnector(session, connectorId);
|
|
279
|
-
return storageConnector.readAsset(session, websiteId, `/${
|
|
280
|
+
return storageConnector.readAsset(session, websiteId, `/${fileName}`);
|
|
280
281
|
}
|
|
281
282
|
async function writeAssets(session, websiteId, files, connectorId) {
|
|
282
283
|
const storageConnector = await getStorageConnector(session, connectorId);
|
|
283
|
-
|
|
284
|
+
const cleanPathFiles = files.map(file => ({
|
|
285
|
+
...file,
|
|
286
|
+
path: file.path.replace('/assets/', '/'),
|
|
287
|
+
}));
|
|
288
|
+
await storageConnector.writeAssets(session, websiteId, cleanPathFiles);
|
|
284
289
|
return files.map(({ path }) => `${path}?websiteId=${websiteId}`);
|
|
285
290
|
}
|
|
286
291
|
return router;
|
|
@@ -7,27 +7,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const index_1 = __importDefault(require("./index"));
|
|
8
8
|
const cli_1 = require("cli");
|
|
9
9
|
const options = (0, cli_1.parse)({
|
|
10
|
-
|
|
11
|
-
port: ['p', 'Port to listen to', 'int'],
|
|
12
|
-
|
|
10
|
+
'host': ['', 'Sets the host param of the express module "cookie-session".', 'string'],
|
|
11
|
+
'port': ['p', 'Port to listen to', 'int'],
|
|
12
|
+
'protocol': ['', 'Sets the protocol param of the express module "cookie-session".', 'string'],
|
|
13
|
+
'config': ['c', 'Path for the server side config file to load at startup', 'file'],
|
|
14
|
+
'client-config': ['', 'Path to client config file to be served on .silex-client.js', 'string'],
|
|
15
|
+
'fs-root': ['', 'Path to the root folder where to store websites. Used by the default connector (fs).', 'string'],
|
|
16
|
+
'session-name': ['', 'Sets the name param of the express module "cookie-session".', 'string'],
|
|
17
|
+
'session-secret': ['s', 'Session secret', 'string'],
|
|
13
18
|
'ssl-port': [false, 'Port to listen to for SSL/HTTPS', 'int'],
|
|
14
19
|
'force-https': [false, 'Force HTTPS', 'boolean'],
|
|
15
20
|
'ssl-private-key': [false, 'Path to private key for SSL', 'file'],
|
|
16
21
|
'ssl-certificate': [false, 'Path to SSL certificate', 'file'],
|
|
17
22
|
'force-https-trust-xfp-header': [false, 'Sets the trustXFPHeader param of the express module "cookie-session". Use only with --force-https', 'boolean'],
|
|
18
|
-
'session-secret': ['s', 'Session secret', 'string'],
|
|
19
23
|
'cors-url': ['', 'Enable CORS for URL (can be "*")', 'string'],
|
|
20
|
-
'
|
|
21
|
-
'
|
|
24
|
+
'express-json-limit': ['', 'Sets the limit param of the express module "json".', 'string'],
|
|
25
|
+
'express-text-limit': ['', 'Sets the limit param of the express module "text".', 'string'],
|
|
26
|
+
'express-urlencoded-limit': ['', 'Sets the limit param of the express module "urlencoded".', 'string'],
|
|
27
|
+
'debug': [false, 'Debug mode, with live reload, source maps etc.', 'boolean'],
|
|
22
28
|
}, {});
|
|
23
|
-
if (options
|
|
24
|
-
process.env.
|
|
29
|
+
if (options['host'])
|
|
30
|
+
process.env.SILEX_HOST = options['host'];
|
|
25
31
|
if (options.port)
|
|
26
|
-
process.env.
|
|
27
|
-
if (options
|
|
28
|
-
process.env.
|
|
32
|
+
process.env.SILEX_PORT = options.port;
|
|
33
|
+
if (options['protocol'])
|
|
34
|
+
process.env.SILEX_PROTOCOL = options['protocol'];
|
|
35
|
+
if (options.config)
|
|
36
|
+
process.env.SILEX_CONFIG = options.config;
|
|
37
|
+
if (options['client-config'])
|
|
38
|
+
process.env.SILEX_CLIENT_CONFIG = options['client-config'];
|
|
39
|
+
if (options['fs-root'])
|
|
40
|
+
process.env.SILEX_FS_ROOT = options['fs-root'];
|
|
41
|
+
if (options['session-name'])
|
|
42
|
+
process.env.SILEX_SESSION_NAME = options['session-name'];
|
|
43
|
+
if (options['session-secret'])
|
|
44
|
+
process.env.SILEX_SESSION_SECRET = options['session-secret'];
|
|
29
45
|
if (options['ssl-port'])
|
|
30
|
-
process.env.
|
|
46
|
+
process.env.SILEX_SSL_PORT = options['ssl-port'];
|
|
31
47
|
if (options['force-https'])
|
|
32
48
|
process.env.SILEX_FORCE_HTTPS = options['force-https'];
|
|
33
49
|
if (options['ssl-private-key'])
|
|
@@ -36,12 +52,14 @@ if (options['ssl-certificate'])
|
|
|
36
52
|
process.env.SILEX_SSL_CERTIFICATE = options['ssl-certificate'];
|
|
37
53
|
if (options['force-https-trust-xfp-header'])
|
|
38
54
|
process.env.SILEX_FORCE_HTTPS_TRUST_XFP_HEADER = options['force-https-trust-xfp-header'];
|
|
39
|
-
if (options['session-secret'])
|
|
40
|
-
process.env.SILEX_SESSION_SECRET = options['session-secret'];
|
|
41
55
|
if (options['cors-url'])
|
|
42
56
|
process.env.SILEX_CORS_URL = options['cors-url'];
|
|
43
|
-
if (options['
|
|
44
|
-
process.env.
|
|
45
|
-
if (options['
|
|
46
|
-
process.env.
|
|
57
|
+
if (options['express-json-limit'])
|
|
58
|
+
process.env.SILEX_EXPRESS_JSON_LIMIT = options['express-json-limit'];
|
|
59
|
+
if (options['express-text-limit'])
|
|
60
|
+
process.env.SILEX_EXPRESS_TEXT_LIMIT = options['express-text-limit'];
|
|
61
|
+
if (options['express-urlencoded-limit'])
|
|
62
|
+
process.env.SILEX_EXPRESS_URLENCODED_LIMIT = options['express-urlencoded-limit'];
|
|
63
|
+
if (options.debug)
|
|
64
|
+
process.env.SILEX_DEBUG = options.debug;
|
|
47
65
|
(0, index_1.default)();
|