@silexlabs/silex 3.0.0-alpha.78 → 3.0.0-alpha.80
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/assetUrl.d.ts +16 -0
- package/dist/client/js/main.js +78 -78
- package/dist/plugins/client/client/assetUrl.d.ts +16 -0
- package/dist/plugins/client/client/assetUrl.js +18 -8
- package/dist/plugins/client/client/assetUrl.js.map +1 -1
- package/dist/plugins/server/server/connectors/FsHosting.d.ts +0 -1
- package/dist/plugins/server/server/connectors/FsHosting.js +2 -2
- package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -1
- package/dist/server/server/connectors/FsHosting.js +1 -2
- package/package.json +1 -1
- package/src/ts/client/assetUrl.test.ts +21 -0
- package/src/ts/client/assetUrl.ts +19 -8
- package/src/ts/server/api/websiteApi.ts +1 -0
- package/src/ts/server/connectors/FsHosting.ts +2 -2
- package/src/ts/server/connectors/FsStorage.ts +0 -1
- package/dist/plugins/server/plugins/server/HooksPlugin.d.ts +0 -7
- package/dist/plugins/server/plugins/server/HooksPlugin.js +0 -74
- package/dist/plugins/server/plugins/server/HooksPlugin.js.map +0 -1
- package/src/ts/plugins/server/HooksPlugin.ts +0 -76
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { Asset, ClientSideFileType, ConnectorId, Page, Style, WebsiteId } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Function to convert a path from it stored version to the displayed version
|
|
4
|
+
* Stored version is like `/assets/image.webp`
|
|
5
|
+
* Grapesjs version is like `/api/website/assets/image.webp?websiteId=47868975&connectorId=gitlab`
|
|
6
|
+
* Exported for unit tests
|
|
7
|
+
*/
|
|
8
|
+
export declare function storedToDisplayed(path: string, websiteId: WebsiteId, storageId: ConnectorId): string;
|
|
9
|
+
/**
|
|
10
|
+
* Function to convert a path from the one we give to grapesjs to the stored version
|
|
11
|
+
* Grapesjs version is like `/api/website/assets/image.webp?websiteId=47868975&connectorId=gitlab`
|
|
12
|
+
* Stored version is like `/assets/image.webp`
|
|
13
|
+
* @param path the path to convert
|
|
14
|
+
* @returns the converted path
|
|
15
|
+
* Exported for unit tests
|
|
16
|
+
*/
|
|
17
|
+
export declare function displayedToStored(path: string): string;
|
|
2
18
|
/**
|
|
3
19
|
* Publication transformer to convert the asset URL during publication
|
|
4
20
|
*/
|
|
@@ -8,22 +8,27 @@ import { ClientSideFileType } from '../types';
|
|
|
8
8
|
* Before saving the site data we convert all URLs to the storage version
|
|
9
9
|
* During publicationn we convert all URLs to the storage version and back
|
|
10
10
|
*/
|
|
11
|
+
// Get the base URL where Silex is served
|
|
12
|
+
const baseUrl = window.location.pathname.replace(/\/$/, '');
|
|
11
13
|
// Orging and path, should we use config.rootUrl?
|
|
12
|
-
const SERVER_URL = window.location.origin +
|
|
14
|
+
const SERVER_URL = window.location.origin + baseUrl;
|
|
13
15
|
/**
|
|
14
16
|
* Function to convert a path from it stored version to the displayed version
|
|
15
17
|
* Stored version is like `/assets/image.webp`
|
|
16
18
|
* Grapesjs version is like `/api/website/assets/image.webp?websiteId=47868975&connectorId=gitlab`
|
|
19
|
+
* Exported for unit tests
|
|
17
20
|
*/
|
|
18
|
-
function storedToDisplayed(path, websiteId, storageId) {
|
|
21
|
+
export function storedToDisplayed(path, websiteId, storageId) {
|
|
19
22
|
// Check the path is a stored path
|
|
20
23
|
if (path.startsWith('/assets')) {
|
|
21
24
|
const url = new URL(path, SERVER_URL);
|
|
22
25
|
url.pathname = url.pathname.replace(/^\/assets/, '');
|
|
23
|
-
url.pathname = `${API_PATH}${API_WEBSITE_PATH}${API_WEBSITE_ASSET_READ}${url.pathname}`;
|
|
26
|
+
url.pathname = `${baseUrl}${API_PATH}${API_WEBSITE_PATH}${API_WEBSITE_ASSET_READ}${url.pathname}`;
|
|
24
27
|
url.searchParams.set('websiteId', websiteId);
|
|
25
28
|
url.searchParams.set('connectorId', storageId);
|
|
26
|
-
const encodedPath = '/' + url.toString()
|
|
29
|
+
const encodedPath = '/' + url.toString() // add a leading slash
|
|
30
|
+
.replace(new RegExp(`^${SERVER_URL}`), '')
|
|
31
|
+
.replace(/^\//, ''); // remove the first slash if it exists
|
|
27
32
|
return decodeURIComponent(encodedPath);
|
|
28
33
|
}
|
|
29
34
|
else {
|
|
@@ -37,16 +42,21 @@ function storedToDisplayed(path, websiteId, storageId) {
|
|
|
37
42
|
* Stored version is like `/assets/image.webp`
|
|
38
43
|
* @param path the path to convert
|
|
39
44
|
* @returns the converted path
|
|
45
|
+
* Exported for unit tests
|
|
40
46
|
*/
|
|
41
|
-
function displayedToStored(path) {
|
|
47
|
+
export function displayedToStored(path) {
|
|
48
|
+
// The path to the assets API
|
|
49
|
+
const apiPath = `${baseUrl}${API_PATH}${API_WEBSITE_PATH}${API_WEBSITE_ASSET_READ}`;
|
|
42
50
|
// Check the path is a displayed path
|
|
43
|
-
if (path.startsWith(
|
|
51
|
+
if (path.startsWith(apiPath)) {
|
|
44
52
|
const url = new URL(path, SERVER_URL);
|
|
45
|
-
url.pathname = url.pathname.replace(new RegExp(`^${
|
|
53
|
+
url.pathname = url.pathname.replace(new RegExp(`^${apiPath}`), '');
|
|
46
54
|
url.pathname = `/assets${url.pathname}`;
|
|
47
55
|
url.searchParams.delete('websiteId');
|
|
48
56
|
url.searchParams.delete('connectorId');
|
|
49
|
-
const encodedPath = '/' + url.toString()
|
|
57
|
+
const encodedPath = '/' + url.toString() // add a leading slash
|
|
58
|
+
.replace(new RegExp(`^${SERVER_URL}`), '')
|
|
59
|
+
.replace(/^\//, ''); // remove the first slash if it exists
|
|
50
60
|
return decodeURIComponent(encodedPath);
|
|
51
61
|
}
|
|
52
62
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetUrl.js","sourceRoot":"","sources":["../../../../src/ts/client/assetUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACjF,OAAO,EAA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AAK,CAAC,KAAK;oBACd,kBAAkB,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBAChE;aACF,CAAA;SACF;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAe;IACtD,MAAM,OAAO,GAAG,4BAA4B,CAAA;IAC5C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAY,EAAE,EAAE;QACjC,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE;YAClD,MAAM,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAC7G,OAAO;gBACL,GAAG,KAAK;gBACR,KAAK,EAAE;oBACL,GAAG,KAAK,CAAC,KAAK;oBACd,kBAAkB,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBAChE;aACF,CAAA;SACF;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -6,7 +6,6 @@ type FsSession = ConnectorSession;
|
|
|
6
6
|
export declare class FsHosting extends FsStorage implements HostingConnector<FsSession> {
|
|
7
7
|
connectorId: string;
|
|
8
8
|
displayName: string;
|
|
9
|
-
icon: string;
|
|
10
9
|
connectorType: ConnectorType;
|
|
11
10
|
publish(session: FsSession, id: WebsiteId, files: ConnectorFile[], { startJob, jobSuccess, jobError }: JobManager): Promise<JobData>;
|
|
12
11
|
getUrl(session: FsSession, id: WebsiteId): Promise<string>;
|
|
@@ -23,13 +23,13 @@ const types_1 = require("../../types");
|
|
|
23
23
|
class FsHosting extends FsStorage_1.FsStorage {
|
|
24
24
|
connectorId = 'fs-hosting';
|
|
25
25
|
displayName = 'File system hosting';
|
|
26
|
-
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';
|
|
27
26
|
connectorType = types_1.ConnectorType.HOSTING;
|
|
28
27
|
async publish(session, id, files, { startJob, jobSuccess, jobError }) {
|
|
29
28
|
const job = startJob(`Publishing to ${this.displayName}`);
|
|
30
29
|
job.logs = [[`Publishing to ${this.displayName}`]];
|
|
31
30
|
job.errors = [[]];
|
|
32
|
-
|
|
31
|
+
// Call write without id or folder so that it goes in / (path will be modified by publication transformers)
|
|
32
|
+
this.write(session, '', files, '', async ({ status, message }) => {
|
|
33
33
|
// Update the job status
|
|
34
34
|
job.status = status;
|
|
35
35
|
job.message = message;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FsHosting.js","sourceRoot":"","sources":["../../../../../src/ts/server/connectors/FsHosting.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAGH,+BAA2B;AAC3B,2CAAuC;AACvC,uCAA8F;AAS9F,MAAa,SAAU,SAAQ,qBAAS;IACtC,WAAW,GAAG,YAAY,CAAA;IAC1B,WAAW,GAAG,qBAAqB,CAAA;IACnC,
|
|
1
|
+
{"version":3,"file":"FsHosting.js","sour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,EAAE,OAAO,CAAC,CAAA;aAC7B;QACH,CAAC,CAAC,CAAA;QACF,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAkB,EAAE,EAAa;QAC5C,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,YAAY,CAAC,CAAA;QAC1D,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QAC5C,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAA;IAC3B,CAAC;CACF;AA9BD,8BA8BC"}
|
|
@@ -7,13 +7,12 @@ const types_1 = require("../../types");
|
|
|
7
7
|
class FsHosting extends FsStorage_1.FsStorage {
|
|
8
8
|
connectorId = 'fs-hosting';
|
|
9
9
|
displayName = 'File system hosting';
|
|
10
|
-
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';
|
|
11
10
|
connectorType = types_1.ConnectorType.HOSTING;
|
|
12
11
|
async publish(session, id, files, { startJob, jobSuccess, jobError }) {
|
|
13
12
|
const job = startJob(`Publishing to ${this.displayName}`);
|
|
14
13
|
job.logs = [[`Publishing to ${this.displayName}`]];
|
|
15
14
|
job.errors = [[]];
|
|
16
|
-
this.write(session,
|
|
15
|
+
this.write(session, '', files, '', async ({ status, message }) => {
|
|
17
16
|
job.status = status;
|
|
18
17
|
job.message = message;
|
|
19
18
|
job.logs[0].push(message);
|
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jest, expect, describe, it, beforeEach } from '@jest/globals'
|
|
2
|
+
import { displayedToStored, storedToDisplayed } from './assetUrl'
|
|
3
|
+
|
|
4
|
+
describe('assetUrl', () => {
|
|
5
|
+
it('store url to display url', () => {
|
|
6
|
+
// Convert a valid URL as stored
|
|
7
|
+
expect(storedToDisplayed('/assets/test.webp', 'test-id', 'test-connector'))
|
|
8
|
+
.toBe('/api/website/assets/test.webp?websiteId=test-id&connectorId=test-connector')
|
|
9
|
+
// Convert a URL which is already as displayed
|
|
10
|
+
expect(storedToDisplayed('/api/website/assets/test.webp?websiteId=test-id&connectorId=test-connector', 'test-id', 'test-connector'))
|
|
11
|
+
.toBe('/api/website/assets/test.webp?websiteId=test-id&connectorId=test-connector')
|
|
12
|
+
})
|
|
13
|
+
it('display url to store url', () => {
|
|
14
|
+
// Convert a valid URL as displayed
|
|
15
|
+
expect(displayedToStored('/api/website/assets/test.webp?websiteId=test-id&connectorId=test-connector'))
|
|
16
|
+
.toBe('/assets/test.webp')
|
|
17
|
+
// Convert a URL which is already as stored
|
|
18
|
+
expect(displayedToStored('/assets/test.webp'))
|
|
19
|
+
.toBe('/assets/test.webp')
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -10,23 +10,29 @@ import { Asset, ClientSideFileType, Component, ConnectorId, Page, Style, Website
|
|
|
10
10
|
* During publicationn we convert all URLs to the storage version and back
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
// Get the base URL where Silex is served
|
|
14
|
+
const baseUrl = window.location.pathname.replace(/\/$/, '')
|
|
15
|
+
|
|
13
16
|
// Orging and path, should we use config.rootUrl?
|
|
14
|
-
const SERVER_URL = window.location.origin +
|
|
17
|
+
const SERVER_URL = window.location.origin + baseUrl
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Function to convert a path from it stored version to the displayed version
|
|
18
21
|
* Stored version is like `/assets/image.webp`
|
|
19
22
|
* Grapesjs version is like `/api/website/assets/image.webp?websiteId=47868975&connectorId=gitlab`
|
|
23
|
+
* Exported for unit tests
|
|
20
24
|
*/
|
|
21
|
-
function storedToDisplayed(path: string, websiteId: WebsiteId, storageId: ConnectorId): string {
|
|
25
|
+
export function storedToDisplayed(path: string, websiteId: WebsiteId, storageId: ConnectorId): string {
|
|
22
26
|
// Check the path is a stored path
|
|
23
27
|
if (path.startsWith('/assets')) {
|
|
24
28
|
const url = new URL(path, SERVER_URL)
|
|
25
29
|
url.pathname = url.pathname.replace(/^\/assets/, '')
|
|
26
|
-
url.pathname = `${API_PATH}${API_WEBSITE_PATH}${API_WEBSITE_ASSET_READ}${url.pathname}`
|
|
30
|
+
url.pathname = `${baseUrl}${API_PATH}${API_WEBSITE_PATH}${API_WEBSITE_ASSET_READ}${url.pathname}`
|
|
27
31
|
url.searchParams.set('websiteId', websiteId)
|
|
28
32
|
url.searchParams.set('connectorId', storageId)
|
|
29
|
-
const encodedPath = '/' + url.toString()
|
|
33
|
+
const encodedPath = '/' + url.toString() // add a leading slash
|
|
34
|
+
.replace(new RegExp(`^${SERVER_URL}`), '')
|
|
35
|
+
.replace(/^\//, '') // remove the first slash if it exists
|
|
30
36
|
return decodeURIComponent(encodedPath)
|
|
31
37
|
} else {
|
|
32
38
|
console.error('storedToDisplayed: path is not a stored path', path)
|
|
@@ -40,16 +46,21 @@ function storedToDisplayed(path: string, websiteId: WebsiteId, storageId: Connec
|
|
|
40
46
|
* Stored version is like `/assets/image.webp`
|
|
41
47
|
* @param path the path to convert
|
|
42
48
|
* @returns the converted path
|
|
49
|
+
* Exported for unit tests
|
|
43
50
|
*/
|
|
44
|
-
function displayedToStored(path: string): string {
|
|
51
|
+
export function displayedToStored(path: string): string {
|
|
52
|
+
// The path to the assets API
|
|
53
|
+
const apiPath = `${baseUrl}${API_PATH}${API_WEBSITE_PATH}${API_WEBSITE_ASSET_READ}`
|
|
45
54
|
// Check the path is a displayed path
|
|
46
|
-
if (path.startsWith(
|
|
55
|
+
if (path.startsWith(apiPath)) {
|
|
47
56
|
const url = new URL(path, SERVER_URL)
|
|
48
|
-
url.pathname = url.pathname.replace(new RegExp(`^${
|
|
57
|
+
url.pathname = url.pathname.replace(new RegExp(`^${apiPath}`), '')
|
|
49
58
|
url.pathname = `/assets${url.pathname}`
|
|
50
59
|
url.searchParams.delete('websiteId')
|
|
51
60
|
url.searchParams.delete('connectorId')
|
|
52
|
-
const encodedPath = '/' + url.toString()
|
|
61
|
+
const encodedPath = '/' + url.toString() // add a leading slash
|
|
62
|
+
.replace(new RegExp(`^${SERVER_URL}`), '')
|
|
63
|
+
.replace(/^\//, '') // remove the first slash if it exists
|
|
53
64
|
return decodeURIComponent(encodedPath)
|
|
54
65
|
} else {
|
|
55
66
|
console.error('displayedToStored: path is not a displayed path', path)
|
|
@@ -302,6 +302,7 @@ export default function (config: ServerConfig, opts = {}): Router {
|
|
|
302
302
|
// As expected by grapesjs (https://grapesjs.com/docs/modules/Assets.html#uploading-assets)
|
|
303
303
|
res.json({
|
|
304
304
|
data: result.map(path =>
|
|
305
|
+
// FIXME: We should return path without this line, as it is saved, not as it is displayed
|
|
305
306
|
baseUrl + API_PATH + API_WEBSITE_PATH + API_WEBSITE_ASSET_READ
|
|
306
307
|
+ path
|
|
307
308
|
+ `?websiteId=${websiteId}&connectorId=${connectorId ? connectorId : ''}` // As expected by wesite API (readAsset)
|
|
@@ -30,14 +30,14 @@ interface FsOptions {
|
|
|
30
30
|
export class FsHosting extends FsStorage implements HostingConnector<FsSession> {
|
|
31
31
|
connectorId = 'fs-hosting'
|
|
32
32
|
displayName = 'File system hosting'
|
|
33
|
-
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'
|
|
34
33
|
connectorType = ConnectorType.HOSTING
|
|
35
34
|
|
|
36
35
|
async publish(session: FsSession, id: WebsiteId, files: ConnectorFile[], {startJob, jobSuccess, jobError}: JobManager): Promise<JobData> {
|
|
37
36
|
const job = startJob(`Publishing to ${this.displayName}`) as PublicationJobData
|
|
38
37
|
job.logs = [[`Publishing to ${this.displayName}`]]
|
|
39
38
|
job.errors = [[]]
|
|
40
|
-
|
|
39
|
+
// Call write without id or folder so that it goes in / (path will be modified by publication transformers)
|
|
40
|
+
this.write(session, '', files, '', async ({status, message}) => {
|
|
41
41
|
// Update the job status
|
|
42
42
|
job.status = status
|
|
43
43
|
job.message = message
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Silex website builder, free/libre no-code tool for makers.
|
|
4
|
-
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
5
|
-
*
|
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
|
7
|
-
* it under the terms of the GNU Affero General Public License as published by
|
|
8
|
-
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU Affero General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
23
|
-
const events_1 = require("../../server/events");
|
|
24
|
-
// **********
|
|
25
|
-
throw new Error('TODO: implement hooks plugin');
|
|
26
|
-
// **********
|
|
27
|
-
async function default_1(config, opts = {}) {
|
|
28
|
-
// Options with defaults
|
|
29
|
-
const options = {
|
|
30
|
-
gitUrl: process.env.SILEX_HOOK_GIT,
|
|
31
|
-
buildUrl: process.env.SILEX_HOOK_BUILD,
|
|
32
|
-
websitePath: process.env.DATA_FOLDER,
|
|
33
|
-
assetsPath: process.env.ASSETS_FOLDER,
|
|
34
|
-
...opts
|
|
35
|
-
};
|
|
36
|
-
config.on(events_1.ServerEvent.WEBSITE_STORE_END, async ({ res, req, projectId, data }) => {
|
|
37
|
-
if (options.gitUrl) {
|
|
38
|
-
await hook(options.gitUrl, {
|
|
39
|
-
path: options.websitePath,
|
|
40
|
-
message: 'Change from Silex',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
config.on(events_1.ServerEvent.WEBSITE_ASSET_STORE_END, async (e) => {
|
|
45
|
-
if (options.gitUrl) {
|
|
46
|
-
await hook(options.gitUrl, {
|
|
47
|
-
path: options.assetsPath,
|
|
48
|
-
message: 'Change from Silex',
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
config.on(events_1.ServerEvent.PUBLISH_END, async ({ projectId, files, req, res }) => {
|
|
53
|
-
if (options.buildUrl) {
|
|
54
|
-
await hook(options.buildUrl);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
exports.default = default_1;
|
|
59
|
-
async function hook(url, params = {}) {
|
|
60
|
-
if (url) {
|
|
61
|
-
const urlObj = new URL(url);
|
|
62
|
-
console.log('Calling hook', { url });
|
|
63
|
-
try {
|
|
64
|
-
Object.keys(params)
|
|
65
|
-
.forEach(key => urlObj.searchParams.append(key, params[key]));
|
|
66
|
-
return (0, node_fetch_1.default)(urlObj.toString());
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
console.log('Hook call failed', { url, error });
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=HooksPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HooksPlugin.js","sourceRoot":"","sources":["../../../../../src/ts/plugins/server/HooksPlugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;AAEH,4DAA8B;AAE9B,gDAAgF;AAOhF,aAAa;AACb,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;AAC/C,aAAa;AAEE,KAAK,oBAAU,MAAoB,EAAE,OAAqB,EAAE;IACzE,wBAAwB;IACxB,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QAClC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;QACtC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;QACpC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;QACrC,GAAG,IAAI;KACR,CAAA;IACD,MAAM,CAAC,EAAE,CAAC,oBAAW,CAAC,iBAAiB,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;QAC/E,IAAG,OAAO,CAAC,MAAM,EAAE;YACjB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;gBACzB,IAAI,EAAE,OAAO,CAAC,WAAW;gBACzB,OAAO,EAAE,mBAAmB;aAC7B,CAAC,CAAA;SACH;IACH,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,EAAE,CAAC,oBAAW,CAAC,uBAAuB,EAAE,KAAK,EAAE,CAAgC,EAAE,EAAE;QACxF,IAAG,OAAO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
|
-
*
|
|
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
|
-
import fetch from 'node-fetch'
|
|
19
|
-
import { ServerConfig } from '../../server/config'
|
|
20
|
-
import { ServerEvent, WebsiteAssetStoreEndEventType } from '../../server/events'
|
|
21
|
-
|
|
22
|
-
type HooksOptions = {
|
|
23
|
-
gitUrl?: string
|
|
24
|
-
buildUrl?: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// **********
|
|
28
|
-
throw new Error('TODO: implement hooks plugin')
|
|
29
|
-
// **********
|
|
30
|
-
|
|
31
|
-
export default async function(config: ServerConfig, opts: HooksOptions = {}) {
|
|
32
|
-
// Options with defaults
|
|
33
|
-
const options = {
|
|
34
|
-
gitUrl: process.env.SILEX_HOOK_GIT,
|
|
35
|
-
buildUrl: process.env.SILEX_HOOK_BUILD,
|
|
36
|
-
websitePath: process.env.DATA_FOLDER,
|
|
37
|
-
assetsPath: process.env.ASSETS_FOLDER,
|
|
38
|
-
...opts
|
|
39
|
-
}
|
|
40
|
-
config.on(ServerEvent.WEBSITE_STORE_END, async ({ res, req, projectId, data }) => {
|
|
41
|
-
if(options.gitUrl) {
|
|
42
|
-
await hook(options.gitUrl, {
|
|
43
|
-
path: options.websitePath,
|
|
44
|
-
message: 'Change from Silex',
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
config.on(ServerEvent.WEBSITE_ASSET_STORE_END, async (e: WebsiteAssetStoreEndEventType) => {
|
|
49
|
-
if(options.gitUrl) {
|
|
50
|
-
await hook(options.gitUrl, {
|
|
51
|
-
path: options.assetsPath,
|
|
52
|
-
message: 'Change from Silex',
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
config.on(ServerEvent.PUBLISH_END, async ({ projectId, files, req, res }) => {
|
|
57
|
-
if(options.buildUrl) {
|
|
58
|
-
await hook(options.buildUrl)
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function hook(url, params = {}) {
|
|
64
|
-
if(url) {
|
|
65
|
-
const urlObj = new URL(url)
|
|
66
|
-
console.log('Calling hook', {url})
|
|
67
|
-
try {
|
|
68
|
-
Object.keys(params)
|
|
69
|
-
.forEach(key => urlObj.searchParams.append(key, params[key]))
|
|
70
|
-
return fetch(urlObj.toString())
|
|
71
|
-
} catch(error) {
|
|
72
|
-
console.log('Hook call failed', {url, error})
|
|
73
|
-
return null
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|