@silexlabs/silex 3.0.0-alpha.43 → 3.0.0-alpha.45
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/.env.default +18 -0
- 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 +2 -0
- package/dist/client/client/expose.d.ts +0 -1
- 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 +2 -0
- package/dist/client/js/main.js +47 -47
- package/dist/client/types.d.ts +7 -1
- package/dist/plugins/client/client/events.d.ts +2 -0
- package/dist/plugins/client/client/events.js +2 -0
- package/dist/plugins/client/client/events.js.map +1 -1
- 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 +7 -1
- package/dist/plugins/client/types.js +8 -0
- package/dist/plugins/client/types.js.map +1 -1
- 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 +16 -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/server/config.js +1 -1
- package/dist/plugins/server/server/config.js.map +1 -1
- package/dist/plugins/server/server/connectors/FsStorage.d.ts +13 -12
- package/dist/plugins/server/server/connectors/FsStorage.js +22 -15
- 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 +31 -3
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -1
- 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 +18 -20
- package/dist/server/server/api/websiteApi.js +36 -40
- package/dist/server/server/cli.js +34 -16
- package/dist/server/server/config.js +1 -1
- package/dist/server/server/connectors/FsStorage.js +19 -15
- package/dist/server/server/connectors/connectors.js +27 -3
- package/dist/server/server/expose.js +27 -0
- package/dist/server/server/index.js +28 -2
- package/dist/server/types.js +10 -1
- package/package.json +4 -1
- package/src/css/_variables.scss +1 -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 +2 -0
- package/src/ts/client/expose.ts +0 -1
- package/src/ts/client/grapesjs/LoginDialog.ts +12 -1
- package/src/ts/client/grapesjs/PublicationManager.ts +1 -1
- package/src/ts/client/grapesjs/index.ts +8 -13
- package/src/ts/client/grapesjs/storage.ts +18 -10
- package/src/ts/client/index.ts +32 -14
- package/src/ts/constants.ts +2 -3
- 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 +30 -37
- package/src/ts/plugins/server/GitlabConnector.ts +434 -0
- package/src/ts/server/api/connectorApi.ts +31 -26
- package/src/ts/server/api/publicationApi.ts +23 -23
- package/src/ts/server/api/websiteApi.ts +42 -43
- package/src/ts/server/cli.ts +23 -11
- package/src/ts/server/config.ts +1 -1
- package/src/ts/server/connectors/FsStorage.test.ts +51 -0
- package/src/ts/server/connectors/FsStorage.ts +35 -25
- package/src/ts/server/connectors/connectors.ts +32 -4
- package/{dist/plugins/client/server/utils/validation.js → src/ts/server/expose.ts} +3 -18
- package/src/ts/server/index.ts +24 -2
- package/src/ts/types.ts +10 -1
- package/dist/plugins/client/constants.d.ts +0 -30
- package/dist/plugins/client/constants.js +0 -47
- package/dist/plugins/client/constants.js.map +0 -1
- package/dist/plugins/client/server/config.d.ts +0 -59
- package/dist/plugins/client/server/config.js +0 -178
- package/dist/plugins/client/server/config.js.map +0 -1
- package/dist/plugins/client/server/connectors/FsHosting.d.ts +0 -13
- package/dist/plugins/client/server/connectors/FsHosting.js +0 -51
- package/dist/plugins/client/server/connectors/FsHosting.js.map +0 -1
- package/dist/plugins/client/server/connectors/FsStorage.d.ts +0 -41
- package/dist/plugins/client/server/connectors/FsStorage.js +0 -220
- package/dist/plugins/client/server/connectors/FsStorage.js.map +0 -1
- package/dist/plugins/client/server/connectors/connectors.d.ts +0 -83
- package/dist/plugins/client/server/connectors/connectors.js +0 -91
- package/dist/plugins/client/server/connectors/connectors.js.map +0 -1
- package/dist/plugins/client/server/events.d.ts +0 -26
- package/dist/plugins/client/server/events.js +0 -12
- package/dist/plugins/client/server/events.js.map +0 -1
- package/dist/plugins/client/server/jobs.d.ts +0 -6
- package/dist/plugins/client/server/jobs.js +0 -67
- package/dist/plugins/client/server/jobs.js.map +0 -1
- package/dist/plugins/client/server/utils/validation.d.ts +0 -7
- package/dist/plugins/client/server/utils/validation.js.map +0 -1
package/src/ts/client/index.ts
CHANGED
|
@@ -21,15 +21,18 @@
|
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { ClientConfig } from './config'
|
|
25
25
|
import { ClientEvent } from './events'
|
|
26
26
|
import { initEditor, getEditor } from './grapesjs/index'
|
|
27
27
|
|
|
28
|
+
// Expose API to calling app as window.silex
|
|
29
|
+
export * from './expose'
|
|
30
|
+
|
|
28
31
|
/**
|
|
29
32
|
* Start Silex, called from host HTML page with window.silex.start()
|
|
30
33
|
*/
|
|
31
34
|
export async function start(options = {}) {
|
|
32
|
-
const config = new
|
|
35
|
+
const config = new ClientConfig()
|
|
33
36
|
Object.assign(config, options)
|
|
34
37
|
|
|
35
38
|
// Config file in root folder which may be generated by the server
|
|
@@ -43,31 +46,46 @@ export async function start(options = {}) {
|
|
|
43
46
|
// Notify plugins that loading is over and Silex is starting
|
|
44
47
|
config.emit(ClientEvent.STARTUP_START)
|
|
45
48
|
|
|
49
|
+
// Init GrapesJS config which depend on the config file properties
|
|
50
|
+
config.initGrapesConfig()
|
|
51
|
+
|
|
46
52
|
// Start grapesjs
|
|
47
53
|
try{
|
|
48
|
-
await initEditor(config.grapesJsConfig
|
|
54
|
+
await initEditor(config.grapesJsConfig)
|
|
49
55
|
} catch(e) {
|
|
50
56
|
console.error('Error starting Silex', e)
|
|
51
57
|
throw e
|
|
52
58
|
}
|
|
53
59
|
|
|
60
|
+
config.emit(ClientEvent.GRAPESJS_START)
|
|
54
61
|
const editor = getEditor()
|
|
55
|
-
|
|
62
|
+
config.emit(ClientEvent.GRAPESJS_END, { editor })
|
|
56
63
|
|
|
57
64
|
// Init internationalization module
|
|
58
65
|
editor.I18n.setLocale(config.lang)
|
|
59
66
|
|
|
60
67
|
// Load the site
|
|
61
68
|
editor.StorageManager.setAutosave(false)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
console.log('before load')
|
|
70
|
+
try {
|
|
71
|
+
await editor.load(null)
|
|
72
|
+
} catch(e) {
|
|
73
|
+
if(e.httpStatusCode === 401) {
|
|
74
|
+
// Unauthorized, will try to login
|
|
75
|
+
} else {
|
|
76
|
+
// Will display an error message, see in storage.ts
|
|
77
|
+
}
|
|
78
|
+
} finally {
|
|
79
|
+
console.log('after load')
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
// This needs time for grapesjs
|
|
82
|
+
editor.editor.set('changesCount', 0)
|
|
83
|
+
editor.StorageManager.setAutosave(true)
|
|
67
84
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
// This needs time for the loader to be hidden
|
|
86
|
+
document.querySelector('.silex-loader').classList.add('silex-dialog-hide')
|
|
87
|
+
document.querySelector('#gjs').classList.remove('silex-dialog-hide')
|
|
88
|
+
config.emit(ClientEvent.STARTUP_END, { editor, config })
|
|
89
|
+
}, 100)
|
|
90
|
+
}
|
|
73
91
|
}
|
package/src/ts/constants.ts
CHANGED
|
@@ -23,7 +23,6 @@ export const WEBSITE_DATA_FILE = 'website.json'
|
|
|
23
23
|
export const WEBSITE_META_DATA_FILE = 'meta.json'
|
|
24
24
|
|
|
25
25
|
export const DEFAULT_WEBSITE_ID = 'default'
|
|
26
|
-
export const DEFAULT_CONNECTOR_ID = ''
|
|
27
26
|
export const DEFAULT_LANGUAGE = 'en'
|
|
28
27
|
export const CLIENT_CONFIG_FILE_NAME = 'silex.js'
|
|
29
28
|
|
|
@@ -47,7 +46,7 @@ export const API_WEBSITE_WRITE = '/'
|
|
|
47
46
|
export const API_WEBSITE_CREATE = '/'
|
|
48
47
|
export const API_WEBSITE_DELETE = '/'
|
|
49
48
|
export const API_WEBSITE_LIST = '/'
|
|
50
|
-
export const
|
|
51
|
-
export const API_WEBSITE_ASSETS_WRITE = 'assets'
|
|
49
|
+
export const API_WEBSITE_ASSET_READ = '/assets'
|
|
50
|
+
export const API_WEBSITE_ASSETS_WRITE = '/assets'
|
|
52
51
|
export const API_WEBSITE_META_READ = '/meta'
|
|
53
52
|
export const API_WEBSITE_META_WRITE = '/meta'
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
//import {styleMap} from 'lit-html/directives/style-map.js'
|
|
20
20
|
//import { onAll } from '@silexlabs/silex/dist/client/utils.js'
|
|
21
21
|
import { onAll } from '../../client/utils.js'
|
|
22
|
-
import {
|
|
22
|
+
import { ClientEvent } from '../../client/events.js'
|
|
23
23
|
|
|
24
24
|
//// @ts-ignore
|
|
25
25
|
//import {html, render} from '/node_modules/lit-html/lit-html.js'
|
|
@@ -38,7 +38,7 @@ export default async (config, opts: any = {}) => {
|
|
|
38
38
|
// @ts-ignore
|
|
39
39
|
const { styleMap } = await import('/node_modules/lit-html/directives/style-map.js')
|
|
40
40
|
|
|
41
|
-
config.on(
|
|
41
|
+
config.on(ClientEvent.GRAPESJS_END, () => {
|
|
42
42
|
const editor = silex.getEditor()
|
|
43
43
|
// Add the new trait to all component types
|
|
44
44
|
editor.DomComponents.getTypes().map(type => {
|
|
@@ -158,7 +158,7 @@ export default async (config, opts: any = {}) => {
|
|
|
158
158
|
// put back together
|
|
159
159
|
.join('\n')
|
|
160
160
|
}
|
|
161
|
-
editor.on(
|
|
161
|
+
editor.on(ClientEvent.PUBLISH_START, () => {
|
|
162
162
|
// Insert templates
|
|
163
163
|
onAll(editor, c => {
|
|
164
164
|
const template = c.get(templateKey)
|
|
@@ -186,7 +186,7 @@ export default async (config, opts: any = {}) => {
|
|
|
186
186
|
}
|
|
187
187
|
})
|
|
188
188
|
})
|
|
189
|
-
editor.on(
|
|
189
|
+
editor.on(ClientEvent.PUBLISH_END, () => {
|
|
190
190
|
onAll(editor, c => {
|
|
191
191
|
// Restore the original method
|
|
192
192
|
c.toHTML = c.get('tmpHtml')
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ServerConfig } from '../../server/config'
|
|
2
|
+
import { expect, jest, beforeEach, afterEach, it, describe } from '@jest/globals'
|
|
3
|
+
import { ConnectorType, WebsiteData, WebsiteId } from '../../types'
|
|
4
|
+
import { Readable } from 'stream'
|
|
5
|
+
|
|
6
|
+
const mocks = {
|
|
7
|
+
access: jest.fn(),
|
|
8
|
+
close: jest.fn(),
|
|
9
|
+
trackProgress: jest.fn(),
|
|
10
|
+
uploadFrom: jest.fn(),
|
|
11
|
+
}
|
|
12
|
+
function mockClient() {
|
|
13
|
+
jest.mock('basic-ftp', () => ({
|
|
14
|
+
Client: jest.fn().mockImplementation(() => mocks),
|
|
15
|
+
}))
|
|
16
|
+
}
|
|
17
|
+
mockClient()
|
|
18
|
+
|
|
19
|
+
const FtpConnector = (await import('./FtpConnector')).default
|
|
20
|
+
|
|
21
|
+
let connector
|
|
22
|
+
const storageRootPath = 'dummy storageRootPath'
|
|
23
|
+
const assetsFolder = 'dummy assetsFolder'
|
|
24
|
+
const dummySession = {
|
|
25
|
+
[`ftp-${ConnectorType.STORAGE}`]: {
|
|
26
|
+
host: 'dummy host',
|
|
27
|
+
user: 'dummy user',
|
|
28
|
+
pass: 'dummy pass',
|
|
29
|
+
port: 1234,
|
|
30
|
+
secure: false,
|
|
31
|
+
storageRootPath,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
const dummyId: WebsiteId = 'dummy id'
|
|
35
|
+
const dummyWebsite: WebsiteData = {
|
|
36
|
+
pages: [],
|
|
37
|
+
assets: [],
|
|
38
|
+
styles: [],
|
|
39
|
+
settings: {},
|
|
40
|
+
fonts: [],
|
|
41
|
+
symbols: [],
|
|
42
|
+
publication: {},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
mockClient()
|
|
47
|
+
connector = new FtpConnector({} as ServerConfig, {
|
|
48
|
+
type: ConnectorType.STORAGE,
|
|
49
|
+
assetsFolder,
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
afterEach(async () => {
|
|
54
|
+
// FIXME: This removes the mock of Client
|
|
55
|
+
//await jest.resetAllMocks()
|
|
56
|
+
// Reset each mock
|
|
57
|
+
Object.keys(mocks).forEach(key => {
|
|
58
|
+
mocks[key].mockClear()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('FtpConnector website', () => {
|
|
63
|
+
it('should write to FTP', async () => {
|
|
64
|
+
await connector.updateWebsite(dummySession, dummyId, dummyWebsite)
|
|
65
|
+
expect(mocks.uploadFrom).toHaveBeenCalledTimes(1)
|
|
66
|
+
expect(mocks.uploadFrom.mock.calls[0][0]).toBeInstanceOf(Readable)
|
|
67
|
+
expect(mocks.uploadFrom.mock.calls[0][1]).toBe(`${storageRootPath}/${dummyId}/website.json`)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('FtpConnector assets', () => {
|
|
72
|
+
it('should write an asset to FTP', async () => {
|
|
73
|
+
const assets = [{
|
|
74
|
+
path: 'dummy path',
|
|
75
|
+
content: 'dummy content',
|
|
76
|
+
}]
|
|
77
|
+
await connector.writeAssets(dummySession, dummyId, assets)
|
|
78
|
+
expect(mocks.uploadFrom).toHaveBeenCalledTimes(1)
|
|
79
|
+
expect(mocks.uploadFrom.mock.calls[0][0]).toBeInstanceOf(Readable)
|
|
80
|
+
expect(mocks.uploadFrom.mock.calls[0][1]).toBe(`${storageRootPath}/${dummyId}/${assetsFolder}/${assets[0].path}`)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
@@ -60,16 +60,10 @@ interface FileStatus {
|
|
|
60
60
|
status: JobStatus
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
interface FtpOptions {
|
|
64
|
-
type: ConnectorType
|
|
65
|
-
path?: string
|
|
66
|
-
authorizeUrl?: string
|
|
67
|
-
authorizePath?: string
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface FtpOptionsWithDefaults {
|
|
63
|
+
export interface FtpOptions {
|
|
71
64
|
type: ConnectorType
|
|
72
65
|
path: string
|
|
66
|
+
assetsFolder: string
|
|
73
67
|
authorizeUrl: string
|
|
74
68
|
authorizePath: string
|
|
75
69
|
}
|
|
@@ -235,23 +229,27 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
235
229
|
connectorId = 'ftp'
|
|
236
230
|
displayName = 'Ftp'
|
|
237
231
|
icon = 'ftp'
|
|
238
|
-
options:
|
|
232
|
+
options: FtpOptions
|
|
239
233
|
connectorType: ConnectorType
|
|
234
|
+
color = '#ffffff'
|
|
235
|
+
background = '#0066CC'
|
|
240
236
|
|
|
241
|
-
constructor(config: ServerConfig, opts: FtpOptions) {
|
|
237
|
+
constructor(config: ServerConfig, opts: Partial<FtpOptions>) {
|
|
242
238
|
this.options = {
|
|
243
239
|
path: '',
|
|
240
|
+
assetsFolder: 'assets',
|
|
244
241
|
authorizeUrl: '/api/authorize/ftp/',
|
|
245
242
|
authorizePath: '/api/authorize/ftp/',
|
|
246
243
|
...opts,
|
|
247
|
-
}
|
|
248
|
-
this.
|
|
244
|
+
} as FtpOptions
|
|
245
|
+
if(!this.options.type) throw new Error('missing type in option of FtpConnector')
|
|
246
|
+
this.connectorType = toConnectorEnum(this.options.type)
|
|
249
247
|
}
|
|
250
248
|
|
|
251
249
|
// **
|
|
252
250
|
// Utils
|
|
253
251
|
sessionData(session: FtpSession): FtpSessionData {
|
|
254
|
-
return session[this.options.type] ?? {} as FtpSessionData
|
|
252
|
+
return session[`ftp-${this.options.type}`] ?? {} as FtpSessionData
|
|
255
253
|
}
|
|
256
254
|
|
|
257
255
|
rootPath(session: FtpSession): string {
|
|
@@ -262,23 +260,22 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
262
260
|
|
|
263
261
|
// **
|
|
264
262
|
// FTP methods
|
|
265
|
-
async write(ftp: Client, path: string, content: ConnectorFileContent, progress?: (message: string) => void): Promise<
|
|
263
|
+
private async write(ftp: Client, path: string, content: ConnectorFileContent, progress?: (message: string) => void): Promise<void> {
|
|
266
264
|
ftp.trackProgress(info => {
|
|
267
265
|
progress && progress(`Uploading ${info.bytes / 1000} KB}`)
|
|
268
266
|
})
|
|
269
267
|
progress && progress('Upload started')
|
|
270
268
|
await ftp.uploadFrom(contentToReadable(content), path)
|
|
271
269
|
progress && progress('Upload complete')
|
|
272
|
-
return path
|
|
273
270
|
}
|
|
274
271
|
|
|
275
|
-
async read(ftp: Client, path: string): Promise<Readable> {
|
|
272
|
+
private async read(ftp: Client, path: string): Promise<Readable> {
|
|
276
273
|
const stream = new PassThrough()
|
|
277
274
|
await ftp.downloadTo(stream, path)
|
|
278
275
|
return stream
|
|
279
276
|
}
|
|
280
277
|
|
|
281
|
-
async readdir(ftp: Client, path: string): Promise<FileMeta[]> {
|
|
278
|
+
private async readdir(ftp: Client, path: string): Promise<FileMeta[]> {
|
|
282
279
|
const list = await ftp.list(path)
|
|
283
280
|
return list.map((file) => ({
|
|
284
281
|
name: file.name,
|
|
@@ -290,19 +287,19 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
290
287
|
} as FileMeta))
|
|
291
288
|
}
|
|
292
289
|
|
|
293
|
-
async mkdir(ftp: Client, path: string) {
|
|
290
|
+
private async mkdir(ftp: Client, path: string) {
|
|
294
291
|
return ftp.ensureDir(path)
|
|
295
292
|
}
|
|
296
293
|
|
|
297
|
-
async rmdir(ftp: Client, path: string) {
|
|
294
|
+
private async rmdir(ftp: Client, path: string) {
|
|
298
295
|
return ftp.removeDir(path)
|
|
299
296
|
}
|
|
300
297
|
|
|
301
|
-
async unlink(ftp: Client, path: string) {
|
|
298
|
+
private async unlink(ftp: Client, path: string) {
|
|
302
299
|
return ftp.remove(path)
|
|
303
300
|
}
|
|
304
301
|
|
|
305
|
-
async getClient({host, user, pass, port, secure}): Promise<Client> {
|
|
302
|
+
private async getClient({host, user, pass, port, secure}): Promise<Client> {
|
|
306
303
|
const ftp = new Client()
|
|
307
304
|
await ftp.access({
|
|
308
305
|
host,
|
|
@@ -311,11 +308,10 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
311
308
|
password: pass,
|
|
312
309
|
secure,
|
|
313
310
|
})
|
|
314
|
-
ftp['test'] = uuid()
|
|
315
311
|
return ftp
|
|
316
312
|
}
|
|
317
313
|
|
|
318
|
-
closeClient(ftp: Client) {
|
|
314
|
+
private closeClient(ftp: Client) {
|
|
319
315
|
if(ftp && !ftp.closed) {
|
|
320
316
|
ftp.close()
|
|
321
317
|
} else {
|
|
@@ -335,7 +331,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
335
331
|
}
|
|
336
332
|
}
|
|
337
333
|
|
|
338
|
-
async getOAuthUrl(session: FtpSession): Promise<
|
|
334
|
+
async getOAuthUrl(session: FtpSession): Promise<null> { return null }
|
|
339
335
|
|
|
340
336
|
async getLoginForm(session: FtpSession, redirectTo: string): Promise<string | null> {
|
|
341
337
|
const { host, user, pass, port, secure, publicationPath, storageRootPath, websiteUrl } = this.sessionData(session)
|
|
@@ -362,13 +358,13 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
362
358
|
// Check if the connection is valid
|
|
363
359
|
const ftp = await this.getClient({ host, user, pass, port, secure })
|
|
364
360
|
// Save the token
|
|
365
|
-
session[this.connectorType] = { host, user, pass, port, secure, publicationPath, storageRootPath, websiteUrl }
|
|
361
|
+
session[`ftp-${this.connectorType}`] = { host, user, pass, port, secure, publicationPath, storageRootPath, websiteUrl }
|
|
366
362
|
// Clean up
|
|
367
363
|
this.closeClient(ftp)
|
|
368
364
|
}
|
|
369
365
|
|
|
370
366
|
async logout(session: FtpSession) {
|
|
371
|
-
delete session[this.options.type]
|
|
367
|
+
delete session[`ftp-${this.options.type}`]
|
|
372
368
|
}
|
|
373
369
|
|
|
374
370
|
async getUser(session: FtpSession): Promise<ConnectorUser> {
|
|
@@ -381,7 +377,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
381
377
|
|
|
382
378
|
async isLoggedIn(session: FtpSession) {
|
|
383
379
|
try {
|
|
384
|
-
if (!session[this.options.type]) {
|
|
380
|
+
if (!session[`ftp-${this.options.type}`]) {
|
|
385
381
|
return false
|
|
386
382
|
}
|
|
387
383
|
const ftp = await this.getClient(this.sessionData(session))
|
|
@@ -497,7 +493,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
497
493
|
id: WebsiteId,
|
|
498
494
|
files: ConnectorFile[],
|
|
499
495
|
statusCbk?: StatusCallback,
|
|
500
|
-
): Promise<
|
|
496
|
+
): Promise<void> {
|
|
501
497
|
// Connect to FTP server
|
|
502
498
|
statusCbk && statusCbk({
|
|
503
499
|
message: 'Connecting to FTP server',
|
|
@@ -510,9 +506,9 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
510
506
|
message: 'Making sure that root folder exists',
|
|
511
507
|
status: JobStatus.IN_PROGRESS,
|
|
512
508
|
})
|
|
513
|
-
|
|
509
|
+
// Useless as ftp write will create the folder
|
|
510
|
+
// await this.mkdir(ftp, rootPath)
|
|
514
511
|
// Write files
|
|
515
|
-
const paths: string[] = []
|
|
516
512
|
let lastFile: ConnectorFile | undefined
|
|
517
513
|
try {
|
|
518
514
|
// Sequentially write files
|
|
@@ -521,7 +517,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
521
517
|
message: `Writing file ${file.path}`,
|
|
522
518
|
status: JobStatus.IN_PROGRESS,
|
|
523
519
|
})
|
|
524
|
-
const dstPath = join(this.options.path, rootPath, id, file.path)
|
|
520
|
+
const dstPath = join(this.options.path, rootPath, id, this.options.assetsFolder, file.path)
|
|
525
521
|
lastFile = file
|
|
526
522
|
const result = await this.write(ftp, dstPath, file.content, message => {
|
|
527
523
|
statusCbk && statusCbk({
|
|
@@ -529,14 +525,12 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
529
525
|
status: JobStatus.IN_PROGRESS,
|
|
530
526
|
})
|
|
531
527
|
})
|
|
532
|
-
paths.push(result)
|
|
533
528
|
}
|
|
534
529
|
this.closeClient(ftp)
|
|
535
530
|
statusCbk && statusCbk({
|
|
536
|
-
message: `Finished writing ${
|
|
531
|
+
message: `Finished writing ${files.length} files to ${rootPath}`,
|
|
537
532
|
status: JobStatus.SUCCESS,
|
|
538
533
|
})
|
|
539
|
-
return paths
|
|
540
534
|
} catch(err) {
|
|
541
535
|
// Not sure why it never gets here
|
|
542
536
|
statusCbk && statusCbk({
|
|
@@ -544,7 +538,6 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
544
538
|
status: JobStatus.ERROR,
|
|
545
539
|
})
|
|
546
540
|
this.closeClient(ftp)
|
|
547
|
-
return []
|
|
548
541
|
}
|
|
549
542
|
}
|
|
550
543
|
|
|
@@ -552,7 +545,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
552
545
|
if (!this.sessionData(session)) throw new Error('Not logged in')
|
|
553
546
|
const storageRootPath = this.rootPath(session)
|
|
554
547
|
const ftp = await this.getClient(this.sessionData(session))
|
|
555
|
-
const dirPath = join(this.options.path, storageRootPath, id, path)
|
|
548
|
+
const dirPath = join(this.options.path, storageRootPath, id, this.options.assetsFolder, path)
|
|
556
549
|
const asset = this.read(ftp, dirPath)
|
|
557
550
|
this.closeClient(ftp)
|
|
558
551
|
return asset
|
|
@@ -562,7 +555,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
562
555
|
const storageRootPath = this.rootPath(session)
|
|
563
556
|
const ftp = await this.getClient(this.sessionData(session))
|
|
564
557
|
await Promise.all(
|
|
565
|
-
paths.map((path) => this.unlink(ftp, join(this.options.path, storageRootPath, id, path)))
|
|
558
|
+
paths.map((path) => this.unlink(ftp, join(this.options.path, storageRootPath, id, this.options.assetsFolder, path)))
|
|
566
559
|
)
|
|
567
560
|
this.closeClient(ftp)
|
|
568
561
|
}
|