@silexlabs/silex 3.0.0-alpha.49 → 3.0.0-alpha.51
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/config.d.ts +14 -1
- package/dist/client/client/grapesjs/PublicationManager.d.ts +2 -7
- package/dist/client/client/publication-transformers.d.ts +41 -0
- package/dist/client/css/admin.css +4 -1
- package/dist/client/js/main.js +3 -3
- package/dist/client/types.d.ts +18 -16
- package/dist/plugins/client/client/api.d.ts +83 -0
- package/dist/plugins/client/client/api.js +105 -0
- package/dist/plugins/client/client/api.js.map +1 -0
- package/dist/plugins/client/client/config.d.ts +58 -0
- package/dist/plugins/client/client/config.js +80 -0
- package/dist/plugins/client/client/config.js.map +1 -0
- package/dist/plugins/client/client/events.js +2 -0
- package/dist/plugins/client/client/events.js.map +1 -1
- package/dist/plugins/client/client/grapesjs/LoginDialog.d.ts +15 -0
- package/dist/plugins/client/client/grapesjs/LoginDialog.js +193 -0
- package/dist/plugins/client/client/grapesjs/LoginDialog.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.d.ts +70 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.js +310 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.d.ts +61 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.js +324 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/blocks.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/blocks.js +37 -0
- package/dist/plugins/client/client/grapesjs/blocks.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/index.d.ts +5 -0
- package/dist/plugins/client/client/grapesjs/index.js +264 -0
- package/dist/plugins/client/client/grapesjs/index.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/internal-links.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/internal-links.js +220 -0
- package/dist/plugins/client/client/grapesjs/internal-links.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.d.ts +2 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.js +83 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/openImport.d.ts +9 -0
- package/dist/plugins/client/client/grapesjs/openImport.js +74 -0
- package/dist/plugins/client/client/grapesjs/openImport.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/page-panel.d.ts +3 -0
- package/dist/plugins/client/client/grapesjs/page-panel.js +113 -0
- package/dist/plugins/client/client/grapesjs/page-panel.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/project-bar.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/project-bar.js +106 -0
- package/dist/plugins/client/client/grapesjs/project-bar.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/rich-text.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/rich-text.js +31 -0
- package/dist/plugins/client/client/grapesjs/rich-text.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/semantic.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/semantic.js +110 -0
- package/dist/plugins/client/client/grapesjs/semantic.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/settings.d.ts +2 -0
- package/dist/plugins/client/client/grapesjs/settings.js +197 -0
- package/dist/plugins/client/client/grapesjs/settings.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/storage.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/storage.js +124 -0
- package/dist/plugins/client/client/grapesjs/storage.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.d.ts +3 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.js +36 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.js.map +1 -0
- package/dist/plugins/client/client/publication-transformers.d.ts +41 -0
- package/dist/plugins/client/client/publication-transformers.js +165 -0
- package/dist/plugins/client/client/publication-transformers.js.map +1 -0
- package/dist/plugins/client/constants.d.ts +29 -0
- package/dist/plugins/client/constants.js +46 -0
- package/dist/plugins/client/constants.js.map +1 -0
- package/dist/plugins/client/plugins/client/11ty.d.ts +17 -0
- package/dist/plugins/client/plugins/client/11ty.js +70 -0
- package/dist/plugins/client/plugins/client/11ty.js.map +1 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js +59 -21
- package/dist/plugins/client/plugins/client/publicationRenderer.js.map +1 -1
- package/dist/plugins/client/plugins/client/website-info.js +1 -1
- package/dist/plugins/client/plugins/client/website-info.js.map +1 -1
- package/dist/plugins/client/types.d.ts +18 -16
- package/dist/plugins/client/types.js.map +1 -1
- package/dist/plugins/server/plugins/server/FtpConnector.d.ts +2 -1
- package/dist/plugins/server/plugins/server/FtpConnector.js +5 -6
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -1
- package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +1 -7
- package/dist/plugins/server/plugins/server/GitlabConnector.js +124 -112
- package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -1
- package/dist/plugins/server/server/connectors/FsHosting.d.ts +2 -1
- package/dist/plugins/server/server/connectors/FsHosting.js +4 -5
- package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -1
- package/dist/plugins/server/server/connectors/FsStorage.js +1 -0
- package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -1
- package/dist/plugins/server/server/connectors/connectors.d.ts +2 -1
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -1
- package/dist/plugins/server/server/jobs.d.ts +6 -0
- package/dist/plugins/server/server/jobs.js +3 -1
- package/dist/plugins/server/server/jobs.js.map +1 -1
- package/dist/plugins/server/types.d.ts +18 -16
- package/dist/plugins/server/types.js.map +1 -1
- package/dist/server/server/api/publicationApi.js +14 -20
- package/dist/server/server/connectors/FsHosting.js +4 -5
- package/dist/server/server/connectors/FsStorage.js +1 -0
- package/dist/server/server/jobs.js +2 -1
- package/package.json +1 -1
- package/public/silex.js +23 -0
- package/src/css/website-info.scss +4 -1
- package/src/ts/client/config.ts +22 -2
- package/src/ts/client/events.ts +3 -0
- package/src/ts/client/grapesjs/PublicationManager.ts +23 -3
- package/src/ts/client/grapesjs/internal-links.ts +0 -2
- package/src/ts/client/grapesjs/storage.ts +1 -1
- package/src/ts/client/index.ts +4 -0
- package/src/ts/client/publication-transformers.test.ts +146 -0
- package/src/ts/client/publication-transformers.ts +188 -0
- package/src/ts/plugins/client/11ty.ts +89 -0
- package/src/ts/plugins/client/publicationRenderer.ts +64 -22
- package/src/ts/plugins/client/website-info.ts +1 -1
- package/src/ts/plugins/server/FtpConnector.ts +3 -3
- package/src/ts/plugins/server/GitlabConnector.ts +128 -109
- package/src/ts/server/api/publicationApi.ts +16 -23
- package/src/ts/server/connectors/FsHosting.ts +2 -2
- package/src/ts/server/connectors/FsStorage.ts +1 -0
- package/src/ts/server/connectors/connectors.ts +3 -1
- package/src/ts/server/jobs.ts +10 -0
- package/src/ts/server/utils/BackwardCompat.ts +530 -529
- package/src/ts/types.ts +20 -17
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { API_CONNECTOR_LOGIN_CALLBACK, API_CONNECTOR_PATH, API_PATH, WEBSITE_DATA_FILE
|
|
18
|
+
import { API_CONNECTOR_LOGIN_CALLBACK, API_CONNECTOR_PATH, API_PATH, WEBSITE_DATA_FILE } from '../../constants'
|
|
19
19
|
import { ServerConfig } from '../../server/config'
|
|
20
20
|
import { ConnectorFile, ConnectorFileContent, StatusCallback, StorageConnector, contentToBuffer, contentToString, toConnectorData } from '../../server/connectors/connectors'
|
|
21
21
|
import { ApiError, ConnectorType, ConnectorUser, WebsiteData, WebsiteId, WebsiteMeta, WebsiteMetaFileContent } from '../../types'
|
|
@@ -33,8 +33,9 @@ export interface GitlabOptions {
|
|
|
33
33
|
clientSecret: string
|
|
34
34
|
branch: string
|
|
35
35
|
assetsFolder: string
|
|
36
|
-
metaRepo: string
|
|
37
|
-
metaRepoFile: string
|
|
36
|
+
//metaRepo: string
|
|
37
|
+
//metaRepoFile: string
|
|
38
|
+
repoPrefix: string
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
interface GitlabToken {
|
|
@@ -120,8 +121,9 @@ export default class GitlabConnector implements StorageConnector {
|
|
|
120
121
|
this.options = {
|
|
121
122
|
branch: 'main',
|
|
122
123
|
assetsFolder: 'assets',
|
|
123
|
-
metaRepo: 'silex-meta',
|
|
124
|
-
metaRepoFile: 'websites.json',
|
|
124
|
+
//metaRepo: 'silex-meta',
|
|
125
|
+
//metaRepoFile: 'websites.json',
|
|
126
|
+
repoPrefix: 'silex_',
|
|
125
127
|
...opts,
|
|
126
128
|
} as GitlabOptions
|
|
127
129
|
if(!this.options.clientId) throw new Error('Missing Gitlab client ID')
|
|
@@ -162,28 +164,28 @@ export default class GitlabConnector implements StorageConnector {
|
|
|
162
164
|
* Get the meta repo path for the current user
|
|
163
165
|
* The meta repo contains a JSON file which contains the list of websites
|
|
164
166
|
*/
|
|
165
|
-
private getMetaRepoPath(session: GitlabSession): string {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
private async initStorage(session: GitlabSession): Promise<void> {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
167
|
+
//private getMetaRepoPath(session: GitlabSession): string {
|
|
168
|
+
// if(!session.gitlab?.username) throw new ApiError('Missing Gitlab user ID. User not logged in?', 401)
|
|
169
|
+
// return encodeURIComponent(`${session.gitlab.username}/${this.options.metaRepo}`)
|
|
170
|
+
//}
|
|
171
|
+
|
|
172
|
+
///**
|
|
173
|
+
// * Initialize the storage with a meta repo
|
|
174
|
+
// */
|
|
175
|
+
//private async initStorage(session: GitlabSession): Promise<void> {
|
|
176
|
+
// // Create the meta repo
|
|
177
|
+
// try {
|
|
178
|
+
// const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
|
|
179
|
+
// name: this.options.metaRepo,
|
|
180
|
+
// }) as any
|
|
181
|
+
// return this.createFile(session, this.getMetaRepoPath(session), this.options.metaRepoFile, JSON.stringify({
|
|
182
|
+
// websites: {}
|
|
183
|
+
// } as MetaRepoFileContent))
|
|
184
|
+
// } catch (e) {
|
|
185
|
+
// console.error('Could not init storage', e.statusCode, e.httpStatusCode, e)
|
|
186
|
+
// throw e
|
|
187
|
+
// }
|
|
188
|
+
//}
|
|
187
189
|
|
|
188
190
|
/**
|
|
189
191
|
* Call the Gitlab API with the user's token and handle errors
|
|
@@ -368,36 +370,38 @@ export default class GitlabConnector implements StorageConnector {
|
|
|
368
370
|
}
|
|
369
371
|
|
|
370
372
|
async listWebsites(session: GitlabSession): Promise<WebsiteMeta[]> {
|
|
371
|
-
try {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
373
|
+
//try {
|
|
374
|
+
// const result = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
375
|
+
// ref: this.options.branch,
|
|
376
|
+
// })
|
|
377
|
+
// const { content } = result
|
|
378
|
+
// const contentDecoded = Buffer.from(content, 'base64').toString('utf8')
|
|
379
|
+
// const websites = (JSON.parse(contentDecoded) as MetaRepoFileContent).websites
|
|
380
|
+
// return Object.entries(websites).map(([websiteId, {meta, createdAt, updatedAt}]) => ({
|
|
381
|
+
// websiteId,
|
|
382
|
+
// createdAt: new Date(createdAt),
|
|
383
|
+
// updatedAt: new Date(updatedAt),
|
|
384
|
+
// ...meta,
|
|
385
|
+
// }))
|
|
386
|
+
//} catch (e) {
|
|
387
|
+
// console.error('Could not list websites', e.statusCode, e.httpStatusCode, e.code)
|
|
388
|
+
// if (e.statusCode === 404 || e.httpStatusCode === 404) {
|
|
389
|
+
// await this.initStorage(session)
|
|
390
|
+
// return []
|
|
391
|
+
// } else {
|
|
392
|
+
// throw e
|
|
393
|
+
// }
|
|
394
|
+
//}
|
|
395
|
+
const projects = await this.callApi(session, `api/v4/users/${session.gitlab?.userId}/projects`) as any[]
|
|
396
|
+
return projects
|
|
397
|
+
.filter(p => p.name.startsWith(this.options.repoPrefix))
|
|
398
|
+
.map(p => ({
|
|
399
|
+
websiteId: p.id,
|
|
400
|
+
name: p.name.replace(this.options.repoPrefix, ''),
|
|
401
|
+
createdAt: p.created_at,
|
|
402
|
+
updatedAt: p.last_activity_at,
|
|
403
|
+
connectorUserSettings: {},
|
|
383
404
|
}))
|
|
384
|
-
} catch (e) {
|
|
385
|
-
console.error('Could not list websites', e.statusCode, e.httpStatusCode, e.code)
|
|
386
|
-
if (e.statusCode === 404 || e.httpStatusCode === 404) {
|
|
387
|
-
await this.initStorage(session)
|
|
388
|
-
return []
|
|
389
|
-
} else {
|
|
390
|
-
throw e
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
//const projects = await this.callApi(session, `api/v4/users/${session.gitlab?.user?.id}/projects`) as any[]
|
|
394
|
-
//return projects.map(p => ({
|
|
395
|
-
// websiteId: p.id,
|
|
396
|
-
// name: p.name,
|
|
397
|
-
// createdAt: p.created_at,
|
|
398
|
-
// updatedAt: p.last_activity_at,
|
|
399
|
-
// connectorUserSettings: {},
|
|
400
|
-
//}))
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
async readWebsite(session: GitlabSession, websiteId: string): Promise<WebsiteData> {
|
|
@@ -412,12 +416,12 @@ export default class GitlabConnector implements StorageConnector {
|
|
|
412
416
|
|
|
413
417
|
async createWebsite(session: GitlabSession, websiteMeta: WebsiteMetaFileContent): Promise<WebsiteId> {
|
|
414
418
|
const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
|
|
415
|
-
name: websiteMeta.name,
|
|
419
|
+
name: this.options.repoPrefix + websiteMeta.name,
|
|
416
420
|
}) as any
|
|
417
421
|
await this.createFile(session, project.id, WEBSITE_DATA_FILE, JSON.stringify({} as WebsiteData))
|
|
418
422
|
//await this.createFile(session, project.id, WEBSITE_META_DATA_FILE, JSON.stringify(websiteMeta))
|
|
419
423
|
//await this.updateWebsite(session, project.id, {} as WebsiteData)
|
|
420
|
-
await this.setWebsiteMeta(session, project.id, websiteMeta)
|
|
424
|
+
//await this.setWebsiteMeta(session, project.id, websiteMeta)
|
|
421
425
|
return project.id
|
|
422
426
|
}
|
|
423
427
|
|
|
@@ -434,67 +438,82 @@ export default class GitlabConnector implements StorageConnector {
|
|
|
434
438
|
async deleteWebsite(session: GitlabSession, websiteId: WebsiteId): Promise<void> {
|
|
435
439
|
// Delete repo
|
|
436
440
|
await this.callApi(session, `api/v4/projects/${websiteId}`, 'DELETE')
|
|
437
|
-
|
|
438
|
-
const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
439
|
-
|
|
440
|
-
})
|
|
441
|
-
const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
442
|
-
const data = metaRepo.websites[websiteId]
|
|
443
|
-
if(!data) throw new ApiError(`Website ${websiteId} not found`, 404)
|
|
444
|
-
|
|
445
|
-
delete metaRepo.websites[websiteId]
|
|
446
|
-
|
|
447
|
-
const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
})
|
|
441
|
+
//// Load the meta repo data
|
|
442
|
+
//const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
443
|
+
// ref: this.options.branch,
|
|
444
|
+
//})
|
|
445
|
+
//const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
446
|
+
//const data = metaRepo.websites[websiteId]
|
|
447
|
+
//if(!data) throw new ApiError(`Website ${websiteId} not found`, 404)
|
|
448
|
+
//// Update or create the website meta data
|
|
449
|
+
//delete metaRepo.websites[websiteId]
|
|
450
|
+
//// Save the meta repo data
|
|
451
|
+
//const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
|
|
452
|
+
// branch: this.options.branch,
|
|
453
|
+
// commit_message: `Delete meta data of ${data.meta.name} (${websiteId}) from Silex`,
|
|
454
|
+
// content: JSON.stringify(metaRepo),
|
|
455
|
+
// file_path: this.options.metaRepoFile,
|
|
456
|
+
//})
|
|
453
457
|
}
|
|
454
458
|
|
|
455
459
|
async getWebsiteMeta(session: GitlabSession, websiteId: WebsiteId): Promise<WebsiteMeta> {
|
|
456
|
-
const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
457
|
-
|
|
458
|
-
})
|
|
459
|
-
const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
460
|
-
if(!metaRepo.websites[websiteId]) throw new ApiError(`Website ${websiteId} not found`, 404)
|
|
460
|
+
//const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
461
|
+
// ref: this.options.branch,
|
|
462
|
+
//})
|
|
463
|
+
//const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
464
|
+
//if(!metaRepo.websites[websiteId]) throw new ApiError(`Website ${websiteId} not found`, 404)
|
|
465
|
+
//return {
|
|
466
|
+
// websiteId,
|
|
467
|
+
// createdAt: new Date(metaRepo.websites[websiteId].createdAt),
|
|
468
|
+
// updatedAt: new Date(metaRepo.websites[websiteId].updatedAt),
|
|
469
|
+
// ...metaRepo.websites[websiteId].meta,
|
|
470
|
+
//}
|
|
471
|
+
// const response = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'GET', null, {
|
|
472
|
+
// ref: this.options.branch,
|
|
473
|
+
// }) as any
|
|
474
|
+
// Base64 to string to JSON
|
|
475
|
+
// const contentDecoded = Buffer.from(response.content, 'base64').toString('utf8')
|
|
476
|
+
// const websiteMeta = JSON.parse(contentDecoded) as WebsiteMetaFileContent
|
|
477
|
+
const project = await this.callApi(session, `api/v4/projects/${websiteId}`)
|
|
461
478
|
return {
|
|
462
479
|
websiteId,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
480
|
+
name: project.name.replace(this.options.repoPrefix, ''),
|
|
481
|
+
imageUrl: project.avatar_url,
|
|
482
|
+
createdAt: project.created_at,
|
|
483
|
+
updatedAt: project.last_activity_at,
|
|
484
|
+
connectorUserSettings: {},
|
|
466
485
|
}
|
|
467
|
-
//const project = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`) as any
|
|
468
|
-
//return {
|
|
469
|
-
// websiteId: project.id,
|
|
470
|
-
// name: project.name,
|
|
471
|
-
// createdAt: project.created_at,
|
|
472
|
-
// updatedAt: project.last_activity_at,
|
|
473
|
-
// connectorUserSettings: {},
|
|
474
|
-
//}
|
|
475
486
|
}
|
|
476
487
|
|
|
477
488
|
async setWebsiteMeta(session: GitlabSession, websiteId: WebsiteId, websiteMeta: WebsiteMetaFileContent): Promise<void> {
|
|
478
|
-
|
|
479
|
-
const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
480
|
-
|
|
481
|
-
})
|
|
482
|
-
const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
483
|
-
|
|
484
|
-
metaRepo.websites[websiteId] = {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
})
|
|
489
|
+
//// Load the meta repo data
|
|
490
|
+
//const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
|
|
491
|
+
// ref: this.options.branch,
|
|
492
|
+
//})
|
|
493
|
+
//const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
|
|
494
|
+
//// Update or create the website meta data
|
|
495
|
+
//metaRepo.websites[websiteId] = {
|
|
496
|
+
// updatedAt: new Date().toISOString(),
|
|
497
|
+
// createdAt: metaRepo.websites[websiteId]?.createdAt ?? new Date().toISOString(),
|
|
498
|
+
// meta: websiteMeta,
|
|
499
|
+
//}
|
|
500
|
+
//// Save the meta repo data
|
|
501
|
+
//const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
|
|
502
|
+
// branch: this.options.branch,
|
|
503
|
+
// commit_message: `Update website meta data of ${websiteMeta.name} (${websiteId}) from Silex`,
|
|
504
|
+
// content: JSON.stringify(metaRepo),
|
|
505
|
+
// file_path: this.options.metaRepoFile,
|
|
506
|
+
//})
|
|
496
507
|
|
|
497
|
-
//
|
|
508
|
+
// Rename the repo if needed
|
|
509
|
+
const oldMeta = await this.getWebsiteMeta(session, websiteId)
|
|
510
|
+
if(websiteMeta.name !== oldMeta.name) {
|
|
511
|
+
await this.callApi(session, `api/v4/projects/${websiteId}`, 'PUT', {
|
|
512
|
+
name: this.options.repoPrefix + websiteMeta.name,
|
|
513
|
+
})
|
|
514
|
+
}
|
|
515
|
+
//// Update the metadata file
|
|
516
|
+
//await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'PUT', {
|
|
498
517
|
// branch: this.options.branch,
|
|
499
518
|
// commit_message: 'Update website meta data from Silex',
|
|
500
519
|
// content: JSON.stringify(websiteMeta),
|
|
@@ -17,13 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
import { Router } from 'express'
|
|
19
19
|
import { API_PUBLICATION_PUBLISH, API_PUBLICATION_STATUS, API_WEBSITE_ASSET_READ } from '../../constants'
|
|
20
|
-
import {
|
|
21
|
-
import { ApiPublicationPublishBody, ApiPublicationPublishQuery, ApiPublicationPublishResponse, ApiPublicationStatusQuery, ApiPublicationStatusResponse, JobId, PublicationSettings, PublicationData as PublicationData, ConnectorType, ConnectorId, WebsiteId} from '../../types'
|
|
20
|
+
import { ApiPublicationPublishBody, ApiPublicationPublishQuery, ApiPublicationPublishResponse, ApiPublicationStatusQuery, ApiPublicationStatusResponse, JobId, PublicationData, ConnectorType, ConnectorId, WebsiteId, ClientSideFile, ClientSideFileWithContent, ClientSideFileWithSrc} from '../../types'
|
|
22
21
|
import { ConnectorFile, HostingConnector, StorageConnector, getConnector } from '../connectors/connectors'
|
|
23
22
|
import { ServerConfig } from '../config'
|
|
24
23
|
import { requiredParam } from '../utils/validation'
|
|
25
|
-
import { join } from 'path'
|
|
26
24
|
import { PublishEndEventType, PublishStartEventType, ServerEvent } from '../events'
|
|
25
|
+
import { getJob, jobManager } from '../jobs'
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* @fileoverview Publication plugin for Silex
|
|
@@ -109,9 +108,9 @@ export default function (config: ServerConfig): Router {
|
|
|
109
108
|
|
|
110
109
|
// Check params
|
|
111
110
|
const data = body as PublicationData
|
|
112
|
-
const { files
|
|
113
|
-
if(!files
|
|
114
|
-
throw new PublicationError('Missing
|
|
111
|
+
const { files } = data
|
|
112
|
+
if(!files) {
|
|
113
|
+
throw new PublicationError('Missing files in body', 400)
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
// Hook for plugins
|
|
@@ -123,29 +122,23 @@ export default function (config: ServerConfig): Router {
|
|
|
123
122
|
// Get storage connector which holds the assets
|
|
124
123
|
const storage = await getStorageConnector(session, config, storageId)
|
|
125
124
|
|
|
126
|
-
//
|
|
127
|
-
const
|
|
128
|
-
if(!asset.path) throw new PublicationError('Missing path in asset', 400)
|
|
129
|
-
if(!asset.src) throw new PublicationError('Missing src in asset', 400)
|
|
130
|
-
// Remove the / from the asset root if it starts with one
|
|
125
|
+
// Load the content if necessary
|
|
126
|
+
const filesList: ConnectorFile[] = await Promise.all(files.map(async (file: ClientSideFile) => {
|
|
131
127
|
const prefix = API_WEBSITE_ASSET_READ.replace(/^\//, '')
|
|
132
|
-
|
|
133
|
-
const
|
|
128
|
+
const fileWithContent = file as ClientSideFileWithContent
|
|
129
|
+
const fileWithSrc = file as ClientSideFileWithSrc
|
|
130
|
+
if(!fileWithContent.content && !fileWithSrc.src) throw new PublicationError('Missing content or src in file', 400)
|
|
131
|
+
const src = fileWithSrc.src?.startsWith(prefix) ? fileWithSrc.src.substring(prefix.length) : fileWithSrc.src
|
|
134
132
|
return {
|
|
135
|
-
path:
|
|
136
|
-
content:
|
|
133
|
+
path: file.path,
|
|
134
|
+
content: fileWithContent.content ??
|
|
135
|
+
await storage.readAsset(session, websiteId, src),
|
|
137
136
|
}
|
|
138
137
|
}))
|
|
139
|
-
|
|
140
|
-
path: file.htmlPath,
|
|
141
|
-
content: file.html,
|
|
142
|
-
}, {
|
|
143
|
-
path: file.cssPath,
|
|
144
|
-
content: file.css,
|
|
145
|
-
}])).concat(assetsFiles)
|
|
138
|
+
|
|
146
139
|
res.json({
|
|
147
140
|
url: await hostingConnector.getUrl(session, websiteId),
|
|
148
|
-
job: await hostingConnector.publish(session, websiteId, filesList),
|
|
141
|
+
job: await hostingConnector.publish(session, websiteId, filesList, jobManager),
|
|
149
142
|
} as ApiPublicationPublishResponse)
|
|
150
143
|
} catch (err) {
|
|
151
144
|
console.error('Error publishing the website', err)
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
|
|
18
18
|
import { ConnectorFile, StorageConnector, HostingConnector, StatusCallback, ConnectorSession, contentToString, toConnectorData, ConnectorFileContent} from './connectors'
|
|
19
19
|
import { join } from 'path'
|
|
20
|
-
import { jobError, jobSuccess, startJob } from '../jobs'
|
|
21
20
|
import { FsStorage } from './FsStorage'
|
|
22
21
|
import { ConnectorType, JobData, JobStatus, PublicationJobData, WebsiteId } from '../../types'
|
|
22
|
+
import { JobManager } from '../jobs'
|
|
23
23
|
|
|
24
24
|
type FsSession = ConnectorSession
|
|
25
25
|
|
|
@@ -33,7 +33,7 @@ export class FsHosting extends FsStorage implements HostingConnector<FsSession>
|
|
|
33
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
34
|
connectorType = ConnectorType.HOSTING
|
|
35
35
|
|
|
36
|
-
async publish(session: FsSession, id: WebsiteId, files: ConnectorFile[]): Promise<JobData> {
|
|
36
|
+
async publish(session: FsSession, id: WebsiteId, files: ConnectorFile[], {startJob, jobSuccess, jobError}: JobManager): Promise<JobData> {
|
|
37
37
|
const job = startJob(`Publishing to ${this.displayName}`) as PublicationJobData
|
|
38
38
|
job.logs = [[`Publishing to ${this.displayName}`]]
|
|
39
39
|
job.errors = [[]]
|
|
@@ -201,6 +201,7 @@ export class FsStorage implements StorageConnector<FsSession> {
|
|
|
201
201
|
let error: Error | null = null
|
|
202
202
|
for (const fileStatus of filesStatuses) {
|
|
203
203
|
const {file} = fileStatus
|
|
204
|
+
console.log('writeAssets', file, this.options.path, id, this.options.assetsFolder, file.path)
|
|
204
205
|
const path = join(this.options.path, id, this.options.assetsFolder, file.path)
|
|
205
206
|
if (typeof file.content === 'string' || Buffer.isBuffer(file.content)) {
|
|
206
207
|
fileStatus.message = 'Writing'
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { Readable } from 'stream'
|
|
19
19
|
import { ServerConfig } from '../config'
|
|
20
20
|
import { JobStatus, JobData, ConnectorData, ConnectorId, WebsiteId, ConnectorType, ConnectorUser, WebsiteMeta, WebsiteMetaFileContent, WebsiteData, ConnectorOptions } from '../../types'
|
|
21
|
+
import { JobManager } from '../jobs'
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @fileoverview define types for Silex connectors
|
|
@@ -99,8 +100,9 @@ export interface StorageConnector<Session extends ConnectorSession = ConnectorSe
|
|
|
99
100
|
* Hosting connectors are used to publish the website
|
|
100
101
|
*/
|
|
101
102
|
export interface HostingConnector<Session extends ConnectorSession = ConnectorSession> extends Connector<Session> {
|
|
102
|
-
publish(session: Session, websiteId: WebsiteId, files: ConnectorFile[]): Promise<JobData>
|
|
103
|
+
publish(session: Session, websiteId: WebsiteId, files: ConnectorFile[], jobManager: JobManager): Promise<JobData> // Pass the jobManager as plugins do not neccessarily share the same module instance
|
|
103
104
|
getUrl(session: Session, websiteId: WebsiteId): Promise<string>
|
|
105
|
+
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
export function toConnectorEnum(type: string | ConnectorType): ConnectorType {
|
package/src/ts/server/jobs.ts
CHANGED
|
@@ -75,3 +75,13 @@ function end(id: JobId, status: JobStatus, message = ''): boolean {
|
|
|
75
75
|
}
|
|
76
76
|
return false
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
// Type definition of the job manager
|
|
80
|
+
export interface JobManager {
|
|
81
|
+
startJob: typeof startJob
|
|
82
|
+
jobSuccess: typeof jobSuccess
|
|
83
|
+
jobError: typeof jobError
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Export the job manager
|
|
87
|
+
export const jobManager: JobManager = { startJob, jobSuccess, jobError }
|