@silexlabs/silex 3.0.0-alpha.70 → 3.0.0-alpha.73

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.
Files changed (43) hide show
  1. package/.silex.js +4 -0
  2. package/dist/client/css/admin.css +5 -2
  3. package/dist/client/js/main.js +6 -6
  4. package/dist/plugins/client/client/grapesjs/PublicationUi.js +3 -3
  5. package/dist/plugins/client/client/grapesjs/PublicationUi.js.map +1 -1
  6. package/dist/plugins/client/client/grapesjs/index.js +0 -5
  7. package/dist/plugins/client/client/grapesjs/index.js.map +1 -1
  8. package/dist/plugins/client/client/grapesjs/storage.js +25 -31
  9. package/dist/plugins/client/client/grapesjs/storage.js.map +1 -1
  10. package/dist/plugins/client/client/grapesjs/symbolDialogs.js +1 -1
  11. package/dist/plugins/client/client/grapesjs/symbolDialogs.js.map +1 -1
  12. package/dist/plugins/client/client/publication-transformers.js +0 -4
  13. package/dist/plugins/client/client/publication-transformers.js.map +1 -1
  14. package/dist/plugins/client/plugins/client/11ty.js.map +1 -1
  15. package/dist/plugins/server/plugins/server/AuthPlugin.js +2 -0
  16. package/dist/plugins/server/plugins/server/AuthPlugin.js.map +1 -1
  17. package/dist/plugins/server/plugins/server/DownloadConnector.js.map +1 -1
  18. package/dist/plugins/server/plugins/server/GitlabConnector.js +60 -3
  19. package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -1
  20. package/dist/plugins/server/server/connectors/connectors.d.ts +1 -1
  21. package/dist/plugins/server/server/events.js.map +1 -1
  22. package/dist/server/server/api/connectorApi.js +1 -1
  23. package/dist/server/server/api/websiteApi.js +7 -5
  24. package/package.json +1 -3
  25. package/public/silex.js +4 -50
  26. package/src/css/silex.scss +3 -0
  27. package/src/ts/client/grapesjs/PublicationUi.ts +3 -3
  28. package/src/ts/client/grapesjs/index.ts +0 -5
  29. package/src/ts/client/grapesjs/storage.ts +20 -25
  30. package/src/ts/client/grapesjs/symbolDialogs.ts +1 -1
  31. package/src/ts/client/publication-transformers.ts +0 -5
  32. package/src/ts/plugins/client/11ty.ts +0 -1
  33. package/src/ts/plugins/server/AuthPlugin.ts +2 -2
  34. package/src/ts/plugins/server/DownloadConnector.ts +0 -2
  35. package/src/ts/plugins/server/GitlabConnector.ts +61 -3
  36. package/src/ts/server/api/connectorApi.ts +1 -1
  37. package/src/ts/server/api/websiteApi.ts +10 -5
  38. package/src/ts/server/connectors/connectors.ts +1 -1
  39. package/src/ts/server/events.ts +0 -1
  40. package/dist/plugins/server/server/api/publicationApi.d.ts +0 -23
  41. package/dist/plugins/server/server/api/publicationApi.js +0 -148
  42. package/dist/plugins/server/server/api/publicationApi.js.map +0 -1
  43. package/src/example-client-config.js +0 -64
package/public/silex.js CHANGED
@@ -15,56 +15,10 @@
15
15
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
- import websiteInfoPlugin from './plugins/client/website-info.js'
18
+ /**
19
+ * This file is loaded by Silex when the user opens the editor
20
+ * Unless you override the default config with the environment variable SILEX_CLIENT_CONFIG or the CLI option --client-config
21
+ */
19
22
 
20
- // This file is loaded by Silex when the user opens the editor
21
- // Unless you override the default config with the environment variable SILEX_CLIENT_CONFIG or the CLI option --client-config
22
23
  export default async function (config) {
23
- // Add plugins
24
- config.addPlugin(websiteInfoPlugin, {})
25
-
26
- // // For example add a GrapesJs plugin like this
27
- // config.grapesJsConfig.plugins.push(plugin)
28
- // config.grapesJsConfig.pluginsOpts[plugin] = {
29
- // }
30
- // // Or like this to override the default options
31
- // // See the docs for the list of options
32
- // return {
33
- // ...config,
34
- // grapesJsConfig: {
35
- // ...config.grapesJsConfig,
36
- // plugins: [
37
- // ...config.grapesJsConfig.plugins,
38
- // plugin,
39
- // ],
40
- // pluginsOpts: {
41
- // ...config.grapesJsConfig.pluginsOpts,
42
- // [plugin]: {
43
- // },
44
- // },
45
- // },
46
- // }
47
-
48
- // config.addPublicationTransformers({
49
- // // Override how components render at publication by grapesjs
50
- // renderComponent(component, initialHtml) {
51
- // return initialHtml
52
- // },
53
- // // Override how styles render at publication by grapesjs
54
- // renderCssRule(rule, initialCss) {
55
- // return initialCss
56
- // },
57
- // // Define how files are named
58
- // transformPath(path) {
59
- // return path
60
- // },
61
- // // Difine files URLs
62
- // transformPermalink(link) {
63
- // return link
64
- // },
65
- // // Transform files after they are rendered and before they are published
66
- // transformFile(file) {
67
- // return file
68
- // }
69
- // })
70
24
  }
@@ -37,6 +37,9 @@
37
37
  overflow: auto;
38
38
  form.silex-form {
39
39
  padding-bottom: 100px; // leave space for fixed footer
40
+ textarea {
41
+ min-height: 250px;
42
+ }
40
43
  }
41
44
  .silex-form__element {
42
45
  padding: 10px 5px;
@@ -174,7 +174,7 @@ export class PublicationUi {
174
174
  <p>Publication error</p>
175
175
  <div>${unsafeHTML(this.errorMessage)}</div>
176
176
  ` : ''}
177
- ${job && job.message ? html`
177
+ ${job?.message ? html`
178
178
  <p>${unsafeHTML(job.message)}</p>
179
179
  ` : ''}
180
180
  ${this.isPending(status) ? html`
@@ -183,7 +183,7 @@ export class PublicationUi {
183
183
  style="width: 100%;"
184
184
  ></progress>
185
185
  ` : ''}
186
- ${job && job.logs?.length && job.logs[0].length ? html`
186
+ ${job?.logs?.length && job.logs[0].length ? html`
187
187
  <br><details>
188
188
  <summary>Logs</summary>
189
189
  <pre style="
@@ -195,7 +195,7 @@ export class PublicationUi {
195
195
  </pre>
196
196
  </details>
197
197
  ` : ''}
198
- ${job && job.errors?.length && job.errors[0].length ? html`
198
+ ${job?.errors?.length && job.errors[0].length ? html`
199
199
  <br><details>
200
200
  <summary>Errors</summary>
201
201
  <pre style="
@@ -112,17 +112,12 @@ export function getEditorConfig(id: WebsiteId, connectorId: ConnectorId, rootUrl
112
112
 
113
113
  storageManager: {
114
114
  autoload: false,
115
- //type: 'remote',
116
115
  type: 'connector',
117
116
  options: {
118
117
  connector: {
119
118
  id,
120
119
  connectorId,
121
120
  },
122
- //remote: {
123
- // urlStore: `${rootUrl}/${API_WEBSITE_WRITE}?id=${id}`,
124
- // urlLoad: `${rootUrl}/${API_WEBSITE_READ}?id=${id}`,
125
- //},
126
121
  },
127
122
  },
128
123
 
@@ -25,45 +25,40 @@ export const storagePlugin = (editor) => {
25
25
  async load(options: { id: WebsiteId, connectorId: ConnectorId }): Promise<WebsiteData> {
26
26
  try {
27
27
  const user: ConnectorUser = await getCurrentUser(editor) ?? await updateUser(editor, ConnectorType.STORAGE, options.connectorId)
28
- if(user) {
29
- const data = await websiteLoad({websiteId: options.id, connectorId: user.storage.connectorId}) as WebsiteData
30
- if(data.assets) data.assets = addTempDataToAssetUrl(data.assets, options.id, user.storage.connectorId)
31
- if(data.pages) data.pages = addTemDataToPages(data.pages, options.id, user.storage.connectorId)
32
- if(data.styles) data.styles = addTempDataToStyles(data.styles, options.id, user.storage.connectorId)
33
- return data
34
- } else {
35
- return new Promise((resolve, reject) => {
36
- editor.once(eventLoggedIn, async () => {
37
- try {
38
- editor.StorageManager.setAutosave(false)
39
- const data = await editor.Storage.load(options)
40
- editor.StorageManager.setAutosave(true)
41
- //editor.loadProjectData(data)
42
- resolve(data)
43
- } catch (err) {
44
- console.error('connectorPlugin load error', err)
45
- reject(err)
46
- }
47
- })
48
- editor.Commands.run(cmdLogin)
28
+ if(!user) throw new ApiError('Not logged in', 401)
29
+ const data = await websiteLoad({websiteId: options.id, connectorId: user.storage.connectorId}) as WebsiteData
30
+ if(data.assets) data.assets = addTempDataToAssetUrl(data.assets, options.id, user.storage.connectorId)
31
+ if(data.pages) data.pages = addTemDataToPages(data.pages, options.id, user.storage.connectorId)
32
+ if(data.styles) data.styles = addTempDataToStyles(data.styles, options.id, user.storage.connectorId)
33
+ return data
34
+
35
+ } catch (err) {
36
+ if(err.httpStatusCode === 401) {
37
+ editor.once(eventLoggedIn, async () => {
38
+ try {
39
+ editor.StorageManager.setAutosave(false)
40
+ const data = await editor.Storage.load(options)
41
+ editor.StorageManager.setAutosave(true)
42
+ editor.loadProjectData(data)
43
+ } catch (err) {
44
+ console.error('connectorPlugin load error', err)
45
+ throw err
46
+ }
49
47
  })
48
+ editor.Commands.run(cmdLogin)
50
49
  }
51
- } catch (err) {
52
50
  console.error('connectorPlugin load error', err)
53
51
  throw err
54
52
  }
55
53
  },
56
54
 
57
55
  async store(data: WebsiteData, options: { id: WebsiteId, connectorId: ConnectorId }) {
58
- console.log('connectorPlugin store', data, options)
59
56
  try {
60
57
  if(await getCurrentUser(editor)) {
61
- console.log('connectorPlugin store2', data, options)
62
58
  const user = await getCurrentUser(editor)
63
59
  data.assets = removeTempDataFromAssetUrl(data.assets)
64
60
  data.pages = removeTempDataFromPages(data.pages)
65
61
  data.styles = removeTempDataFromStyles(data.styles)
66
- console.log('connectorPlugin store3', data, options)
67
62
  await websiteSave({websiteId: options.id, connectorId: user.storage.connectorId, data})
68
63
  } else {
69
64
  editor.once(eventLoggedIn, () => {
@@ -31,7 +31,7 @@ export default grapesjs.plugins.add(name, (editor, opts) => {
31
31
  editor.Commands.add(cmdPromptAddSymbol, {
32
32
  run: (_, sender) => {
33
33
  const label = prompt('Label', getNext('Symbol '))
34
- const icon = prompt('Icon', 'fa-list')
34
+ const icon = 'fa-gem'
35
35
  editor.runCommand(cmdAddSymbol, { label, icon })
36
36
  }
37
37
  })
@@ -18,7 +18,6 @@
18
18
  import { Component, CssRule, Editor, ObjectStrings, Page } from 'grapesjs'
19
19
  import { ClientSideFile, ClientSideFileType, ClientSideFileWithPermalink, PublicationData } from '../types'
20
20
  import { onAll } from './utils'
21
- import { getPageLink, getPageSlug } from '../page'
22
21
 
23
22
  /**
24
23
  * @fileoverview Silex publication transformers are used to control how the site is rendered and published
@@ -95,15 +94,11 @@ export function renderComponents(editor: Editor) {
95
94
  c[ATTRIBUTE_METHOD_STORE_INLINE_CSS] = c.getStyle
96
95
  const href = c.get('attributes').href as string | undefined
97
96
  if(href?.startsWith('./')) {
98
- //const page = editor.Pages.getAll().find(p => getPageLink(p.getName()) === href)
99
- //if(page) {
100
97
  c[ATTRIBUTE_METHOD_STORE_HREF] = href
101
98
  c.set('attributes', {
102
99
  ...c.get('attributes'),
103
- //href: transformPagePermalin(editor, page),
104
100
  href: transformPermalink(editor, href, ClientSideFileType.HTML),
105
101
  })
106
- //}
107
102
  }
108
103
  // Handle both c.attributes.src and c.attributes.attributes.src
109
104
  // For some reason we need both
@@ -1,4 +1,3 @@
1
- import { Page } from 'grapesjs'
2
1
  import { ClientConfig } from '../../client/config'
3
2
  import { ClientSideFile, ClientSideFileWithContent } from '../../types'
4
3
 
@@ -15,8 +15,8 @@
15
15
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
- import express from 'express'
19
- import { Directus } from '@directus/sdk'
18
+ // import express from 'express'
19
+ // import { Directus } from '@directus/sdk'
20
20
 
21
21
  export default async function(config, opts = {}) {
22
22
  // config.on('silex:startup:start', ({app}) => {
@@ -4,10 +4,8 @@ import { ConnectorOptions, ConnectorType, ConnectorUser, JobData, JobStatus, Pub
4
4
  import { ConnectorFile, ConnectorSession, HostingConnector } from '../../server/connectors/connectors'
5
5
  import { tmpdir } from 'os'
6
6
  import { JobManager } from '../../server/jobs'
7
- import { Readable } from 'stream'
8
7
  import { ServerConfig } from '../../server/config'
9
8
  import { ServerEvent } from '../../server/events'
10
- import { getHostingConnector } from '../../server/api/publicationApi'
11
9
 
12
10
  import { Request, Response } from 'express'
13
11
 
@@ -108,14 +108,72 @@ async function wait(ms: number) {
108
108
  return new Promise(resolve => setTimeout(resolve, ms))
109
109
  }
110
110
 
111
+ const svg = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
112
+ <svg
113
+ xmlns:svg="http://www.w3.org/2000/svg"
114
+ xmlns="http://www.w3.org/2000/svg"
115
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
116
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
117
+ width="1000"
118
+ height="963.197"
119
+ viewBox="0 0 1000 963.197"
120
+ version="1.1"
121
+ id="svg85">
122
+ <sodipodi:namedview
123
+ id="namedview87"
124
+ pagecolor="#ffffff"
125
+ bordercolor="#666666"
126
+ borderopacity="1.0"
127
+ inkscape:pageshadow="2"
128
+ inkscape:pageopacity="0.0"
129
+ inkscape:pagecheckerboard="0"
130
+ showgrid="false"
131
+ inkscape:zoom="1"
132
+ inkscape:cx="991.5"
133
+ inkscape:cy="964.5"
134
+ inkscape:window-width="1126"
135
+ inkscape:window-height="895"
136
+ inkscape:window-x="774"
137
+ inkscape:window-y="12"
138
+ inkscape:window-maximized="0"
139
+ inkscape:current-layer="svg85" />
140
+ <defs
141
+ id="defs74">
142
+ <style
143
+ id="style72">.cls-1{fill:#e24329;}.cls-2{fill:#fc6d26;}.cls-3{fill:#fca326;}</style>
144
+ </defs>
145
+ <g
146
+ id="LOGO"
147
+ transform="matrix(5.2068817,0,0,5.2068817,-489.30756,-507.76085)">
148
+ <path
149
+ class="cls-1"
150
+ d="m 282.83,170.73 -0.27,-0.69 -26.14,-68.22 a 6.81,6.81 0 0 0 -2.69,-3.24 7,7 0 0 0 -8,0.43 7,7 0 0 0 -2.32,3.52 l -17.65,54 h -71.47 l -17.65,-54 a 6.86,6.86 0 0 0 -2.32,-3.53 7,7 0 0 0 -8,-0.43 6.87,6.87 0 0 0 -2.69,3.24 L 97.44,170 l -0.26,0.69 a 48.54,48.54 0 0 0 16.1,56.1 l 0.09,0.07 0.24,0.17 39.82,29.82 19.7,14.91 12,9.06 a 8.07,8.07 0 0 0 9.76,0 l 12,-9.06 19.7,-14.91 40.06,-30 0.1,-0.08 a 48.56,48.56 0 0 0 16.08,-56.04 z"
151
+ id="path76" />
152
+ <path
153
+ class="cls-2"
154
+ d="m 282.83,170.73 -0.27,-0.69 a 88.3,88.3 0 0 0 -35.15,15.8 L 190,229.25 c 19.55,14.79 36.57,27.64 36.57,27.64 l 40.06,-30 0.1,-0.08 a 48.56,48.56 0 0 0 16.1,-56.08 z"
155
+ id="path78" />
156
+ <path
157
+ class="cls-3"
158
+ d="m 153.43,256.89 19.7,14.91 12,9.06 a 8.07,8.07 0 0 0 9.76,0 l 12,-9.06 19.7,-14.91 c 0,0 -17.04,-12.89 -36.59,-27.64 -19.55,14.75 -36.57,27.64 -36.57,27.64 z"
159
+ id="path80" />
160
+ <path
161
+ class="cls-2"
162
+ d="M 132.58,185.84 A 88.19,88.19 0 0 0 97.44,170 l -0.26,0.69 a 48.54,48.54 0 0 0 16.1,56.1 l 0.09,0.07 0.24,0.17 39.82,29.82 c 0,0 17,-12.85 36.57,-27.64 z"
163
+ id="path82" />
164
+ </g>
165
+ </svg>`
166
+ const encodedSvg = encodeURIComponent(svg)
167
+ const ICON = `data:image/svg+xml,${encodedSvg}`
168
+
111
169
  export default class GitlabConnector implements StorageConnector {
112
170
  connectorId = 'gitlab'
113
171
  connectorType = ConnectorType.STORAGE
114
172
  displayName = 'GitLab'
115
- icon = 'http://gitlab.lcqb.upmc.fr/assets/favicon-075eba76312e8421991a0c1f89a89ee81678bcde72319dd3e8047e2a47cd3a42.ico'
173
+ icon = ICON
116
174
  disableLogout = false
117
- color = '#ffffff'
118
- background = '#FC6D26'
175
+ color = '#2B1B63'
176
+ background = 'rgba(252, 109, 38, 0.2)'
119
177
  options: GitlabOptions
120
178
 
121
179
  constructor(private config: ServerConfig, opts: Partial<GitlabOptions>) {
@@ -96,7 +96,7 @@ async function routeUser(req: Request, res: Response) {
96
96
  const user = await connector.getUser(session)
97
97
  res.json(user as ApiConnectorUserResponse)
98
98
  } catch (error) {
99
- console.error('Error in the login status request', error)
99
+ console.error('Error in the user request', error, error.code)
100
100
  res.status(validateStatus(error?.code ?? error?.httpStatusCode, 500)).json({
101
101
  error: true,
102
102
  message: error.message,
@@ -293,14 +293,14 @@ export default function (config: ServerConfig, opts = {}): Router {
293
293
  config.emit(ServerEvent.WEBSITE_ASSET_STORE_START, { files, websiteId, connectorId } as WebsiteAssetStoreStartEventType)
294
294
 
295
295
  // Write the files
296
- await writeAssets(req['session'], websiteId, files, connectorId)
296
+ const result = await writeAssets(req['session'], websiteId, files, connectorId)
297
297
 
298
298
  // Return the file URLs to insert in the website
299
299
  // As expected by grapesjs (https://grapesjs.com/docs/modules/Assets.html#uploading-assets)
300
300
  res.json({
301
- data: files.map(file =>
301
+ data: result.map(path =>
302
302
  API_PATH + API_WEBSITE_PATH + API_WEBSITE_ASSET_READ
303
- + file.path
303
+ + path
304
304
  + `?websiteId=${websiteId}&connectorId=${connectorId ? connectorId : ''}` // As expected by wesite API (readAsset)
305
305
  ),
306
306
  } as ApiWebsiteAssetsWriteResponse)
@@ -394,6 +394,7 @@ export default function (config: ServerConfig, opts = {}): Router {
394
394
 
395
395
  /**
396
396
  * Write an asset to the connector
397
+ * @returns File names on the storage connector, always starting with a slash
397
398
  */
398
399
  async function writeAssets(session: any, websiteId: string, files: ConnectorFile[], connectorId?: string): Promise<string[]> {
399
400
  // Get the desired connector
@@ -406,14 +407,18 @@ export default function (config: ServerConfig, opts = {}): Router {
406
407
  }))
407
408
 
408
409
  // Write the asset to the connector
409
- await storageConnector.writeAssets(
410
+ const result = await storageConnector.writeAssets(
410
411
  session,
411
412
  websiteId,
412
413
  cleanPathFiles,
413
414
  )
414
415
 
415
416
  // Return the files URLs with the website id
416
- return files.map(({ path }) => `${path}?websiteId=${websiteId}`)
417
+ return files.map(({ path }, idx) => `${
418
+ result && result[idx]
419
+ ? `/${result[idx].replace(/^\//, '')}` // ensure the leading slash
420
+ : path
421
+ }?websiteId=${websiteId}`)
417
422
  }
418
423
  return router
419
424
  }
@@ -87,7 +87,7 @@ export interface StorageConnector<Session extends ConnectorSession = ConnectorSe
87
87
  updateWebsite(session: Session, websiteId: WebsiteId, data: WebsiteData): Promise<void>
88
88
  deleteWebsite(session: Session, websiteId: WebsiteId): Promise<void>
89
89
  // CRUD on assets
90
- writeAssets(session: Session, websiteId: WebsiteId, files: ConnectorFile[], status?: StatusCallback): Promise<void>
90
+ writeAssets(session: Session, websiteId: WebsiteId, files: ConnectorFile[], status?: StatusCallback): Promise<string[] | void>
91
91
  readAsset(session: Session, websiteId: WebsiteId, fileName: string): Promise<ConnectorFileContent>
92
92
  deleteAssets(session: Session, websiteId: WebsiteId, fileNames: string[]): Promise<void>
93
93
  //getFileUrl(session: Session, websiteId: WebsiteId, path: string): Promise<string>
@@ -15,7 +15,6 @@
15
15
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
- // FIXME: this is for client and server, it is confusing, split in 2 files
19
18
  import { ConnectorId, PublicationData, WebsiteData, WebsiteId } from '../types'
20
19
  import { ConnectorFile } from './connectors/connectors'
21
20
 
@@ -1,23 +0,0 @@
1
- import { Router } from 'express';
2
- import { HostingConnector, StorageConnector } from '../connectors/connectors';
3
- import { ServerConfig } from '../config';
4
- /**
5
- * @fileoverview Publication plugin for Silex
6
- * Adds a publication API to Silex server
7
- */
8
- /**
9
- * Error thrown by the publication API
10
- * @param message error message
11
- * @param code http status code
12
- */
13
- export declare class PublicationError extends Error {
14
- code: number;
15
- constructor(message: string, code: number);
16
- }
17
- /**
18
- * Get the desired connector
19
- * Can be the default connector or a specific one
20
- */
21
- export declare function getHostingConnector(session: any, config: ServerConfig, connectorId?: string): Promise<HostingConnector>;
22
- export declare function getStorageConnector(session: any, config: ServerConfig, connectorId?: string): Promise<StorageConnector>;
23
- export default function (config: ServerConfig): Router;
@@ -1,148 +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
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.getStorageConnector = exports.getHostingConnector = exports.PublicationError = void 0;
20
- const express_1 = require("express");
21
- const constants_1 = require("../../constants");
22
- const types_1 = require("../../types");
23
- const connectors_1 = require("../connectors/connectors");
24
- const validation_1 = require("../utils/validation");
25
- const events_1 = require("../events");
26
- const jobs_1 = require("../jobs");
27
- /**
28
- * @fileoverview Publication plugin for Silex
29
- * Adds a publication API to Silex server
30
- */
31
- /**
32
- * Error thrown by the publication API
33
- * @param message error message
34
- * @param code http status code
35
- */
36
- class PublicationError extends Error {
37
- code;
38
- constructor(message, code) {
39
- super(message);
40
- this.code = code;
41
- }
42
- }
43
- exports.PublicationError = PublicationError;
44
- const PROJECT_ROOT = require.main ? require.main.path : process.cwd();
45
- /**
46
- * Get the desired connector
47
- * Can be the default connector or a specific one
48
- */
49
- async function getHostingConnector(session, config, connectorId) {
50
- const hostingConnector = await (0, connectors_1.getConnector)(config, session, types_1.ConnectorType.HOSTING, connectorId); // ?? config.getHostingConnectors()[0]
51
- if (!hostingConnector) {
52
- throw new PublicationError('No hosting connector found', 500);
53
- }
54
- if (!await hostingConnector.isLoggedIn(session)) {
55
- throw new PublicationError('Not logged in', 401);
56
- }
57
- return hostingConnector;
58
- }
59
- exports.getHostingConnector = getHostingConnector;
60
- async function getStorageConnector(session, config, connectorId) {
61
- const storageConnector = await (0, connectors_1.getConnector)(config, session, types_1.ConnectorType.STORAGE, connectorId); // ?? config.getStorageConnectors()[0]
62
- if (!storageConnector) {
63
- throw new PublicationError('No storage connector found', 500);
64
- }
65
- if (!await storageConnector.isLoggedIn(session)) {
66
- throw new PublicationError('Not logged in to the storage connector', 401);
67
- }
68
- return storageConnector;
69
- }
70
- exports.getStorageConnector = getStorageConnector;
71
- function default_1(config) {
72
- // Create a new router
73
- const router = (0, express_1.Router)();
74
- // Get publication status
75
- router.get(constants_1.API_PUBLICATION_STATUS, async function (req, res) {
76
- const query = req.query;
77
- const jobId = query.jobId;
78
- const job = jobId && (0, jobs_1.getJob)(jobId);
79
- if (!job) {
80
- console.error(`Error: job not found with id ${jobId}`);
81
- res.status(404).json({
82
- message: 'Error: job not found.',
83
- });
84
- return;
85
- }
86
- res.json({
87
- ...job,
88
- _timeout: undefined,
89
- });
90
- });
91
- // Publish website
92
- router.post(constants_1.API_PUBLICATION_PUBLISH, async function (req, res) {
93
- try {
94
- const query = req.query;
95
- const body = req.body;
96
- const websiteId = (0, validation_1.requiredParam)(query.websiteId, 'id in query');
97
- const storageId = (0, validation_1.requiredParam)(query.storageId, 'storageId in query');
98
- const hostingId = (0, validation_1.requiredParam)(query.hostingId, 'hostingId in query');
99
- const session = (0, validation_1.requiredParam)(req['session'], 'session on express request');
100
- // Check params
101
- const data = body;
102
- const { files } = data;
103
- if (!files) {
104
- throw new PublicationError('Missing files in body', 400);
105
- }
106
- // Hook for plugins
107
- config.emit(events_1.ServerEvent.PUBLISH_START, data);
108
- // Get hosting connector and make sure the user is logged in
109
- const hostingConnector = await getHostingConnector(session, config, hostingId);
110
- // Get storage connector which holds the assets
111
- const storage = await getStorageConnector(session, config, storageId);
112
- // Load the content if necessary
113
- const filesList = await Promise.all(files.map(async (file) => {
114
- const prefix = constants_1.API_WEBSITE_ASSET_READ;
115
- const fileWithContent = file;
116
- const fileWithSrc = file;
117
- if (!fileWithContent.content && !fileWithSrc.src)
118
- throw new PublicationError('Missing content or src in file', 400);
119
- const src = fileWithSrc.src?.startsWith(prefix) ? fileWithSrc.src.substring(prefix.length) : fileWithSrc.src;
120
- return {
121
- path: file.path,
122
- content: fileWithContent.content ??
123
- await storage.readAsset(session, websiteId, src),
124
- };
125
- }));
126
- res.json({
127
- url: await hostingConnector.getUrl(session, websiteId),
128
- job: await hostingConnector.publish(session, websiteId, filesList, jobs_1.jobManager),
129
- });
130
- }
131
- catch (err) {
132
- console.error('Error publishing the website', err);
133
- res
134
- .status(typeof err.code === 'number' ? err.code : 500)
135
- .json({
136
- message: `Error publishing the website. ${err.message}`
137
- });
138
- // Hook for plugins
139
- config.emit(events_1.ServerEvent.PUBLISH_END, err);
140
- return;
141
- }
142
- // Hook for plugins
143
- config.emit(events_1.ServerEvent.PUBLISH_END);
144
- });
145
- return router;
146
- }
147
- exports.default = default_1;
148
- //# sourceMappingURL=publicationApi.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"publicationApi.js","sourceRoot":"","sources":["../../../../../src/ts/server/api/publicationApi.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,qCAAgC;AAChC,+CAAyG;AACzG,uCAA2S;AAC3S,yDAA0G;AAE1G,oDAAmD;AACnD,sCAAmF;AACnF,kCAA4C;AAE5C;;;GAGG;AAEH;;;;GAIG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACL;IAApC,YAAY,OAAe,EAAS,IAAY;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QADoB,SAAI,GAAJ,IAAI,CAAQ;IAEhD,CAAC;CACF;AAJD,4CAIC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAA;AAErE;;;GAGG;AACI,KAAK,UAAU,mBAAmB,CAAC,OAAY,EAAE,MAAoB,EAAE,WAAoB;IAChG,MAAM,gBAAgB,GAAG,MAAM,IAAA,yBAAY,EAAC,MAAM,EAAE,OAAO,EAAE,qBAAa,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA,CAAC,uCAAuC;IAExI,IAAI,CAAC,gBAAgB,EAAE;QACrB,MAAM,IAAI,gBAAgB,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAA;KAC9D;IAED,IAAI,CAAC,MAAM,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC/C,MAAM,IAAI,gBAAgB,CAAC,eAAe,EAAE,GAAG,CAAC,CAAA;KACjD;IAED,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AAmB;QACnB,MAAM,CAAC,IAAI,CAAC,oBAAW,CAAC,WAAW,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AAlFD,4BAkFC"}
@@ -1,64 +0,0 @@
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
- import directusStorage from 'https://unpkg.com/@silexlabs/grapesjs-directus-storage'
19
- console.log('directusStorage', directusStorage, directusStorage?.default)
20
-
21
- // Use the environment variable SILEX_CLIENT_CONFIG or the CLI option --client-config to override the default config with this file
22
- export default async function (config, options) {
23
- console.log('In example config')
24
- //await config.addPlugin('gjs-blocks-basic', 'https://unpkg.com/grapesjs-blocks-basic', {
25
- // blocks: ['text', 'image', 'video', 'map'],
26
- //})
27
-
28
- // Optional plugins
29
- await config.addPlugin([
30
- '@silexlabs/grapesjs-directus-storage',
31
- './plugins/@silexlabs/grapesjs-directus-storage/dist/index.js',
32
- ], {
33
- '@silexlabs/grapesjs-directus-storage': {
34
- directusUrl: 'http://localhost:8055',
35
- },
36
- './plugins/@silexlabs/grapesjs-directus-storage/dist/index.js': {
37
- directusUrl: 'http://localhost:8055',
38
- },
39
- })
40
-
41
- // Return an object to override default config
42
- return {
43
- ...config,
44
- ...options,
45
- editor: {
46
- ...config.editor,
47
- storageManager: {
48
- autoload: false,
49
- type: 'directus',
50
- },
51
- plugins: [
52
- ...config.editor.plugins,
53
- directusStorage,
54
- ],
55
- pluginsOpts: {
56
- ...config.editor.pluginsOpts,
57
- [directusStorage]: {
58
- directusUrl: 'http://localhost:8055',
59
- },
60
- },
61
- },
62
- }
63
- }
64
-