@silexlabs/silex 3.0.0-alpha.43 → 3.0.0-alpha.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/client/api.d.ts +6 -6
- package/dist/client/client/config.d.ts +26 -211
- package/dist/client/client/events.d.ts +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 +17 -16
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -1
- package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +81 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js +373 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -0
- package/dist/plugins/server/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 +3 -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 +31 -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,26 +229,31 @@ 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 {
|
|
256
|
+
console.log('rootPath', this.sessionData(session), session)
|
|
258
257
|
return this.connectorType === ConnectorType.STORAGE ?
|
|
259
258
|
requiredParam<string>(this.sessionData(session).storageRootPath, 'storage root path') :
|
|
260
259
|
requiredParam<string>(this.sessionData(session).publicationPath, 'publication path')
|
|
@@ -262,23 +261,22 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
262
261
|
|
|
263
262
|
// **
|
|
264
263
|
// FTP methods
|
|
265
|
-
async write(ftp: Client, path: string, content: ConnectorFileContent, progress?: (message: string) => void): Promise<
|
|
264
|
+
private async write(ftp: Client, path: string, content: ConnectorFileContent, progress?: (message: string) => void): Promise<void> {
|
|
266
265
|
ftp.trackProgress(info => {
|
|
267
266
|
progress && progress(`Uploading ${info.bytes / 1000} KB}`)
|
|
268
267
|
})
|
|
269
268
|
progress && progress('Upload started')
|
|
270
269
|
await ftp.uploadFrom(contentToReadable(content), path)
|
|
271
270
|
progress && progress('Upload complete')
|
|
272
|
-
return path
|
|
273
271
|
}
|
|
274
272
|
|
|
275
|
-
async read(ftp: Client, path: string): Promise<Readable> {
|
|
273
|
+
private async read(ftp: Client, path: string): Promise<Readable> {
|
|
276
274
|
const stream = new PassThrough()
|
|
277
275
|
await ftp.downloadTo(stream, path)
|
|
278
276
|
return stream
|
|
279
277
|
}
|
|
280
278
|
|
|
281
|
-
async readdir(ftp: Client, path: string): Promise<FileMeta[]> {
|
|
279
|
+
private async readdir(ftp: Client, path: string): Promise<FileMeta[]> {
|
|
282
280
|
const list = await ftp.list(path)
|
|
283
281
|
return list.map((file) => ({
|
|
284
282
|
name: file.name,
|
|
@@ -290,19 +288,19 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
290
288
|
} as FileMeta))
|
|
291
289
|
}
|
|
292
290
|
|
|
293
|
-
async mkdir(ftp: Client, path: string) {
|
|
291
|
+
private async mkdir(ftp: Client, path: string) {
|
|
294
292
|
return ftp.ensureDir(path)
|
|
295
293
|
}
|
|
296
294
|
|
|
297
|
-
async rmdir(ftp: Client, path: string) {
|
|
295
|
+
private async rmdir(ftp: Client, path: string) {
|
|
298
296
|
return ftp.removeDir(path)
|
|
299
297
|
}
|
|
300
298
|
|
|
301
|
-
async unlink(ftp: Client, path: string) {
|
|
299
|
+
private async unlink(ftp: Client, path: string) {
|
|
302
300
|
return ftp.remove(path)
|
|
303
301
|
}
|
|
304
302
|
|
|
305
|
-
async getClient({host, user, pass, port, secure}): Promise<Client> {
|
|
303
|
+
private async getClient({host, user, pass, port, secure}): Promise<Client> {
|
|
306
304
|
const ftp = new Client()
|
|
307
305
|
await ftp.access({
|
|
308
306
|
host,
|
|
@@ -311,11 +309,10 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
311
309
|
password: pass,
|
|
312
310
|
secure,
|
|
313
311
|
})
|
|
314
|
-
ftp['test'] = uuid()
|
|
315
312
|
return ftp
|
|
316
313
|
}
|
|
317
314
|
|
|
318
|
-
closeClient(ftp: Client) {
|
|
315
|
+
private closeClient(ftp: Client) {
|
|
319
316
|
if(ftp && !ftp.closed) {
|
|
320
317
|
ftp.close()
|
|
321
318
|
} else {
|
|
@@ -335,7 +332,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
335
332
|
}
|
|
336
333
|
}
|
|
337
334
|
|
|
338
|
-
async getOAuthUrl(session: FtpSession): Promise<
|
|
335
|
+
async getOAuthUrl(session: FtpSession): Promise<null> { return null }
|
|
339
336
|
|
|
340
337
|
async getLoginForm(session: FtpSession, redirectTo: string): Promise<string | null> {
|
|
341
338
|
const { host, user, pass, port, secure, publicationPath, storageRootPath, websiteUrl } = this.sessionData(session)
|
|
@@ -362,13 +359,13 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
362
359
|
// Check if the connection is valid
|
|
363
360
|
const ftp = await this.getClient({ host, user, pass, port, secure })
|
|
364
361
|
// Save the token
|
|
365
|
-
session[this.connectorType] = { host, user, pass, port, secure, publicationPath, storageRootPath, websiteUrl }
|
|
362
|
+
session[`ftp-${this.connectorType}`] = { host, user, pass, port, secure, publicationPath, storageRootPath, websiteUrl }
|
|
366
363
|
// Clean up
|
|
367
364
|
this.closeClient(ftp)
|
|
368
365
|
}
|
|
369
366
|
|
|
370
367
|
async logout(session: FtpSession) {
|
|
371
|
-
delete session[this.options.type]
|
|
368
|
+
delete session[`ftp-${this.options.type}`]
|
|
372
369
|
}
|
|
373
370
|
|
|
374
371
|
async getUser(session: FtpSession): Promise<ConnectorUser> {
|
|
@@ -381,7 +378,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
381
378
|
|
|
382
379
|
async isLoggedIn(session: FtpSession) {
|
|
383
380
|
try {
|
|
384
|
-
if (!session[this.options.type]) {
|
|
381
|
+
if (!session[`ftp-${this.options.type}`]) {
|
|
385
382
|
return false
|
|
386
383
|
}
|
|
387
384
|
const ftp = await this.getClient(this.sessionData(session))
|
|
@@ -497,7 +494,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
497
494
|
id: WebsiteId,
|
|
498
495
|
files: ConnectorFile[],
|
|
499
496
|
statusCbk?: StatusCallback,
|
|
500
|
-
): Promise<
|
|
497
|
+
): Promise<void> {
|
|
501
498
|
// Connect to FTP server
|
|
502
499
|
statusCbk && statusCbk({
|
|
503
500
|
message: 'Connecting to FTP server',
|
|
@@ -510,9 +507,9 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
510
507
|
message: 'Making sure that root folder exists',
|
|
511
508
|
status: JobStatus.IN_PROGRESS,
|
|
512
509
|
})
|
|
513
|
-
|
|
510
|
+
// Useless as ftp write will create the folder
|
|
511
|
+
// await this.mkdir(ftp, rootPath)
|
|
514
512
|
// Write files
|
|
515
|
-
const paths: string[] = []
|
|
516
513
|
let lastFile: ConnectorFile | undefined
|
|
517
514
|
try {
|
|
518
515
|
// Sequentially write files
|
|
@@ -521,7 +518,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
521
518
|
message: `Writing file ${file.path}`,
|
|
522
519
|
status: JobStatus.IN_PROGRESS,
|
|
523
520
|
})
|
|
524
|
-
const dstPath = join(this.options.path, rootPath, id, file.path)
|
|
521
|
+
const dstPath = join(this.options.path, rootPath, id, this.options.assetsFolder, file.path)
|
|
525
522
|
lastFile = file
|
|
526
523
|
const result = await this.write(ftp, dstPath, file.content, message => {
|
|
527
524
|
statusCbk && statusCbk({
|
|
@@ -529,14 +526,12 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
529
526
|
status: JobStatus.IN_PROGRESS,
|
|
530
527
|
})
|
|
531
528
|
})
|
|
532
|
-
paths.push(result)
|
|
533
529
|
}
|
|
534
530
|
this.closeClient(ftp)
|
|
535
531
|
statusCbk && statusCbk({
|
|
536
|
-
message: `Finished writing ${
|
|
532
|
+
message: `Finished writing ${files.length} files to ${rootPath}`,
|
|
537
533
|
status: JobStatus.SUCCESS,
|
|
538
534
|
})
|
|
539
|
-
return paths
|
|
540
535
|
} catch(err) {
|
|
541
536
|
// Not sure why it never gets here
|
|
542
537
|
statusCbk && statusCbk({
|
|
@@ -544,7 +539,6 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
544
539
|
status: JobStatus.ERROR,
|
|
545
540
|
})
|
|
546
541
|
this.closeClient(ftp)
|
|
547
|
-
return []
|
|
548
542
|
}
|
|
549
543
|
}
|
|
550
544
|
|
|
@@ -552,7 +546,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
552
546
|
if (!this.sessionData(session)) throw new Error('Not logged in')
|
|
553
547
|
const storageRootPath = this.rootPath(session)
|
|
554
548
|
const ftp = await this.getClient(this.sessionData(session))
|
|
555
|
-
const dirPath = join(this.options.path, storageRootPath, id, path)
|
|
549
|
+
const dirPath = join(this.options.path, storageRootPath, id, this.options.assetsFolder, path)
|
|
556
550
|
const asset = this.read(ftp, dirPath)
|
|
557
551
|
this.closeClient(ftp)
|
|
558
552
|
return asset
|
|
@@ -562,7 +556,7 @@ export default class FtpConnector implements StorageConnector<FtpSession> {
|
|
|
562
556
|
const storageRootPath = this.rootPath(session)
|
|
563
557
|
const ftp = await this.getClient(this.sessionData(session))
|
|
564
558
|
await Promise.all(
|
|
565
|
-
paths.map((path) => this.unlink(ftp, join(this.options.path, storageRootPath, id, path)))
|
|
559
|
+
paths.map((path) => this.unlink(ftp, join(this.options.path, storageRootPath, id, this.options.assetsFolder, path)))
|
|
566
560
|
)
|
|
567
561
|
this.closeClient(ftp)
|
|
568
562
|
}
|