@notifiles/sdk 1.1.0 → 1.1.2
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/package.json +2 -1
- package/src/lib/cloudLibrary/minio/index.js +2 -0
- package/src/lib/cloudLibrary/minio/previewRemoteUrl.js +20 -0
- package/src/lib/cloudLibrary/minio/syncFolder.js +72 -0
- package/src/lib/fs/dirFilesRescursivePure.js +21 -0
- package/src/template/attach/entry.js +22 -0
- package/src/template/attach/index.js +2 -0
- package/src/template/attach/lib/email.js +59 -0
- package/src/template/attach/lib/pushNotification.js +9 -0
- package/src/template/attach/lib/textMessage.js +9 -0
- package/src/template/attach/path.js +20 -0
- package/src/template/attach/path.test.js +24 -0
- package/src/template/cloudify/lib/email/image/index.js +20 -19
- package/src/template/cloudify/lib/email/index.js +5 -11
- package/src/template/consolidate/lib/email.js +11 -5
- package/src/template/consolidate/lib/image/index.js +6 -3
- package/src/template/consolidate/lib/image/treatLocalFile.js +1 -0
- package/src/template/consolidate/lib/image/treatRemoteFile.js +2 -1
- package/src/template/format/entry.js +9 -3
- package/src/template/optimize/lib/email.js +12 -4
- package/src/template/optimize/lib/image/index.js +8 -4
- package/src/template/sync/lib/email.js +8 -29
- package/src/template/sync/lib/pushNotification.js +4 -11
- package/src/template/{cloudify/lib/remove.js → sync/lib/syncFolder.js} +1 -1
- package/src/template/sync/lib/textMessage.js +4 -11
- package/src/template/update/path.js +6 -1
- package/src/template/cloudify/lib/email/attachments/addAttachment.js +0 -24
- package/src/template/cloudify/lib/email/attachments/index.js +0 -137
- package/src/template/cloudify/lib/email/attachments/treatLocalFile.js +0 -13
- package/src/template/cloudify/lib/email/attachments/treatRemoteFile.js +0 -26
- package/src/template/sync/lib/upload.js +0 -14
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notifiles/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "adoucoure",
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
"twitter": "^1.7.1",
|
|
117
117
|
"underscore": "^1.13.6",
|
|
118
118
|
"unified": "^11.0.4",
|
|
119
|
+
"walk": "^2.3.15",
|
|
119
120
|
"yaml": "^2.4.2"
|
|
120
121
|
},
|
|
121
122
|
"devDependencies": {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { default as isValid } from './isValid.js'
|
|
2
2
|
export { default as upload } from './upload.js'
|
|
3
|
+
export { default as syncFolder } from './syncFolder.js'
|
|
3
4
|
export { default as remove } from './remove.js'
|
|
5
|
+
export { default as previewRemoteUrl } from './previewRemoteUrl.js'
|
|
4
6
|
// export { default as uploadFolder } from './uploadFolder.js'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default async ({
|
|
2
|
+
filename,
|
|
3
|
+
auth,
|
|
4
|
+
// contentType = 'image/png'
|
|
5
|
+
}) => {
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const {
|
|
9
|
+
endPoint,
|
|
10
|
+
bucketName
|
|
11
|
+
} = auth
|
|
12
|
+
|
|
13
|
+
const url = `https://${endPoint}/${bucketName}/${filename}`
|
|
14
|
+
return { url }
|
|
15
|
+
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error(e)
|
|
18
|
+
}
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as Minio from 'minio'
|
|
2
|
+
import { walk } from 'walk'
|
|
3
|
+
|
|
4
|
+
export default async ({
|
|
5
|
+
sourceUrl,
|
|
6
|
+
destinationPath,
|
|
7
|
+
auth,
|
|
8
|
+
// contentType = 'image/png'
|
|
9
|
+
}) => {
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const {
|
|
13
|
+
endPoint,
|
|
14
|
+
accessKey,
|
|
15
|
+
secretKey,
|
|
16
|
+
bucketName
|
|
17
|
+
} = auth
|
|
18
|
+
|
|
19
|
+
const minioClient = new Minio.Client({
|
|
20
|
+
endPoint,
|
|
21
|
+
// port,
|
|
22
|
+
// useSSL,
|
|
23
|
+
accessKey,
|
|
24
|
+
secretKey,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const exists = await minioClient.bucketExists(bucketName)
|
|
28
|
+
if (!exists) {
|
|
29
|
+
return null
|
|
30
|
+
// await minioClient.makeBucket(bucketName, 'us-east-1')
|
|
31
|
+
// console.log('Bucket ' + bucketName + ' created in "us-east-1".')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const metaData = {
|
|
35
|
+
// 'Content-Type': contentType,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const walker = walk(sourceUrl)
|
|
39
|
+
const result = await new Promise((resolve, reject) => {
|
|
40
|
+
walker.on('file', (root, fileStats, next) => {
|
|
41
|
+
const filePath = `${root}/${fileStats.name}`
|
|
42
|
+
const postSourceURl = root.split(sourceUrl)[1]
|
|
43
|
+
let destination = `${destinationPath}/${postSourceURl}/${fileStats.name}`
|
|
44
|
+
destination = destination.replaceAll('//', '/')
|
|
45
|
+
console.log('Upload', filePath)
|
|
46
|
+
|
|
47
|
+
minioClient.fPutObject(
|
|
48
|
+
bucketName,
|
|
49
|
+
destination,
|
|
50
|
+
filePath,
|
|
51
|
+
err => {
|
|
52
|
+
console.log(filePath, 'uploaded')
|
|
53
|
+
if (err) {
|
|
54
|
+
console.error(err)
|
|
55
|
+
reject(err)
|
|
56
|
+
}
|
|
57
|
+
next()
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
walker.on('end', function () {
|
|
62
|
+
console.log('End upload')
|
|
63
|
+
resolve()
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return {}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error(e)
|
|
70
|
+
}
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
const walk = async (dir, filelist = []) => {
|
|
5
|
+
const files = await fs.promises.readdir(dir);
|
|
6
|
+
|
|
7
|
+
for (file of files) {
|
|
8
|
+
const filepath = path.join(dir, file)
|
|
9
|
+
const stat = await fs.promises.stat(filepath)
|
|
10
|
+
|
|
11
|
+
if (stat.isDirectory()) {
|
|
12
|
+
filelist = await walk(filepath, filelist)
|
|
13
|
+
} else {
|
|
14
|
+
filelist.push(file)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return filelist;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default walk
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import adaptSettings from '../../lib/adaptSettings.js'
|
|
2
|
+
import performEmail from './lib/email.js'
|
|
3
|
+
import performTextMessage from './lib/textMessage.js'
|
|
4
|
+
import performPushNotification from './lib/pushNotification.js'
|
|
5
|
+
|
|
6
|
+
export default async ({
|
|
7
|
+
entry,
|
|
8
|
+
settings,
|
|
9
|
+
}) => {
|
|
10
|
+
adaptSettings({ settings })
|
|
11
|
+
return {
|
|
12
|
+
entry: {
|
|
13
|
+
...entry,
|
|
14
|
+
versions: await Promise.all(entry.versions.map(async _entry => {
|
|
15
|
+
let res = await performEmail({ entry: _entry, settings, })
|
|
16
|
+
res = await performTextMessage({ entry: res.entry, settings, })
|
|
17
|
+
res = await performPushNotification({ entry: res.entry, settings, })
|
|
18
|
+
return res.entry
|
|
19
|
+
}))
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import checkFileExists from '../../../lib/fs/checkFileExists.js'
|
|
3
|
+
import fsPath from 'path'
|
|
4
|
+
|
|
5
|
+
export default async (props) => {
|
|
6
|
+
const { entry, settings } = props
|
|
7
|
+
const {
|
|
8
|
+
path,
|
|
9
|
+
buildPaths,
|
|
10
|
+
code,
|
|
11
|
+
} = entry
|
|
12
|
+
|
|
13
|
+
const sharedItemsPath = `${path}/attachments`
|
|
14
|
+
let sharedItems = await fs.promises.readdir(sharedItemsPath)
|
|
15
|
+
let items = (await Promise.all(sharedItems.map(async item => {
|
|
16
|
+
const folderPath = fsPath.join(sharedItemsPath, item)
|
|
17
|
+
const folderPathStat = await fs.promises.stat(folderPath)
|
|
18
|
+
if (!folderPathStat) {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isDir = folderPathStat.isDirectory()
|
|
23
|
+
if (isDir) {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
fileName: item,
|
|
28
|
+
path: `${sharedItemsPath}/${item}`
|
|
29
|
+
}
|
|
30
|
+
}))).filter(a => a)
|
|
31
|
+
|
|
32
|
+
const codeOwnItemsPath = `${path}/attachments/${entry.code}`
|
|
33
|
+
|
|
34
|
+
if ((await checkFileExists(codeOwnItemsPath))) {
|
|
35
|
+
let codeOwnItems = await fs.promises.readdir(codeOwnItemsPath)
|
|
36
|
+
items = [
|
|
37
|
+
...items,
|
|
38
|
+
...(codeOwnItems.map(fileName => ({
|
|
39
|
+
fileName,
|
|
40
|
+
path: `${codeOwnItemsPath}/${fileName}`
|
|
41
|
+
})))
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!items) {
|
|
46
|
+
return { entry }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await Promise.all(items.map(async ({ fileName, path: filePath }) => {
|
|
50
|
+
return fs.promises.cp(
|
|
51
|
+
filePath,
|
|
52
|
+
`${path}/.build/email/${code}/attachments/${fileName}`,
|
|
53
|
+
)
|
|
54
|
+
}))
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
entry
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import perform from './lib/perform.js'
|
|
2
|
+
import getEntries from '../../lib/entries/getAtPath.js'
|
|
3
|
+
import adaptSettings from '../../lib/adaptSettings.js'
|
|
4
|
+
|
|
5
|
+
export default async ({
|
|
6
|
+
path,
|
|
7
|
+
settings
|
|
8
|
+
}) => {
|
|
9
|
+
adaptSettings({ settings })
|
|
10
|
+
let entries = await getEntries({
|
|
11
|
+
path,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
for (var i in entries) {
|
|
15
|
+
const entry = entries[i]
|
|
16
|
+
await perform({ entry, settings })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
describe.skip('cloudify', () => {
|
|
3
|
+
it('cloudifies to minio', async () => {
|
|
4
|
+
const fsPath = (await import('path')).default
|
|
5
|
+
let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER)
|
|
6
|
+
const operation = (await import('./path.js')).default
|
|
7
|
+
|
|
8
|
+
const result = await operation({
|
|
9
|
+
settings: {
|
|
10
|
+
clouds: [{
|
|
11
|
+
id: "minio",
|
|
12
|
+
auth: {
|
|
13
|
+
endPoint: process.env.TEST_MINIO_ENDPOINT,
|
|
14
|
+
accessKey: process.env.TEST_MINIO_ACCESS_KEY,
|
|
15
|
+
secretKey: process.env.TEST_MINIO_SECRET,
|
|
16
|
+
bucketName: process.env.TEST_MINIO_BUCKET_NAME
|
|
17
|
+
}
|
|
18
|
+
}]
|
|
19
|
+
},
|
|
20
|
+
path,
|
|
21
|
+
})
|
|
22
|
+
expect(result).toBeTruthy()
|
|
23
|
+
})
|
|
24
|
+
})
|
|
@@ -16,27 +16,28 @@ export default async ({ child,
|
|
|
16
16
|
src: _url,
|
|
17
17
|
} } = child
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
//#region CACHE
|
|
20
20
|
let _activity = await getActivity({ path })
|
|
21
|
-
if (!settings.forceUploadAssets) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
21
|
+
// if (!settings.forceUploadAssets) {
|
|
22
|
+
// const codeActivity = _activity[entry.code]
|
|
23
|
+
// if (codeActivity) {
|
|
24
|
+
// const files = codeActivity.files
|
|
25
|
+
// if (files && files[_url]) {
|
|
26
|
+
// const cache = files[_url]
|
|
27
|
+
// return {
|
|
28
|
+
// ...child,
|
|
29
|
+
// properties: {
|
|
30
|
+
// ...child.properties,
|
|
31
|
+
// src: cache.url
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
// }
|
|
36
|
+
// }
|
|
37
|
+
//#endregion
|
|
37
38
|
|
|
38
39
|
let result
|
|
39
|
-
const destination =
|
|
40
|
+
const destination = buildPaths.email.assetsContainer
|
|
40
41
|
if (isLocal(_url)) {
|
|
41
42
|
result = await treatLocalFile({ url: _url, path, destination })
|
|
42
43
|
}
|
|
@@ -53,7 +54,7 @@ export default async ({ child,
|
|
|
53
54
|
uploadResult = await upload({
|
|
54
55
|
id: cloud.id,
|
|
55
56
|
sourceUrl,
|
|
56
|
-
filename: `${buildPaths.email.
|
|
57
|
+
filename: `${buildPaths.email.assetsContainerRemote}/${filename}`,
|
|
57
58
|
auth: cloud.auth,
|
|
58
59
|
settings
|
|
59
60
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import hastToHtml from '../../../../lib/remark/hastToHtml.js'
|
|
2
|
-
import treatAttachments from './attachments/index.js'
|
|
3
2
|
import treatImage from './image/index.js'
|
|
4
|
-
|
|
3
|
+
import fs from 'fs'
|
|
5
4
|
|
|
6
5
|
export default async (props) => {
|
|
7
6
|
const { entry, settings } = props
|
|
@@ -15,17 +14,12 @@ export default async (props) => {
|
|
|
15
14
|
buildPaths
|
|
16
15
|
})
|
|
17
16
|
|
|
18
|
-
await treatAttachments({
|
|
19
|
-
path,
|
|
20
|
-
settings,
|
|
21
|
-
buildPaths,
|
|
22
|
-
entry
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
// let md = await mdastToMarkdown({ mdast })
|
|
26
17
|
let body = hastToHtml({ data: _hast })
|
|
27
|
-
// await fs.promises.writeFile(`${path}/.build/html/email.cloud.html`, html)
|
|
28
18
|
|
|
19
|
+
await fs.promises.writeFile(
|
|
20
|
+
buildPaths.email.body,
|
|
21
|
+
body
|
|
22
|
+
)
|
|
29
23
|
|
|
30
24
|
return {
|
|
31
25
|
entry: {
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import hastToHtml from '../../../lib/remark/hastToHtml.js';
|
|
2
2
|
import treatImage from './image/index.js';
|
|
3
3
|
import ensureDirectoryExists from '../../../lib/fs/ensureDirectoryExists.js';
|
|
4
|
+
import fs from 'fs';
|
|
4
5
|
|
|
5
6
|
export default async (props) => {
|
|
6
7
|
const { entry } = props
|
|
7
|
-
const { path, email: { hast } } = entry
|
|
8
|
+
const { path, email: { hast }, buildPaths } = entry
|
|
8
9
|
|
|
9
|
-
const destination = `${path}/.assets`
|
|
10
|
-
await ensureDirectoryExists(destination, false)
|
|
11
10
|
|
|
12
11
|
const _hast = await perform({
|
|
13
12
|
child: hast,
|
|
14
13
|
path,
|
|
14
|
+
buildPaths
|
|
15
15
|
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
let body = hastToHtml({ data: _hast })
|
|
19
19
|
|
|
20
|
+
await fs.promises.writeFile(
|
|
21
|
+
buildPaths.email.body,
|
|
22
|
+
body
|
|
23
|
+
)
|
|
24
|
+
|
|
20
25
|
return {
|
|
21
26
|
entry: {
|
|
22
27
|
...entry,
|
|
@@ -30,7 +35,7 @@ export default async (props) => {
|
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
const perform = async (props) => {
|
|
33
|
-
const { child, path } = props
|
|
38
|
+
const { child, path, buildPaths } = props
|
|
34
39
|
let _child = { ...child }
|
|
35
40
|
|
|
36
41
|
if (child.properties && child.properties.dataNotifilesDoNotConsolidate) {
|
|
@@ -41,7 +46,8 @@ const perform = async (props) => {
|
|
|
41
46
|
case 'img': {
|
|
42
47
|
_child = await treatImage({
|
|
43
48
|
child: _child,
|
|
44
|
-
path
|
|
49
|
+
path,
|
|
50
|
+
buildPaths
|
|
45
51
|
})
|
|
46
52
|
} break
|
|
47
53
|
default:
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import isLocal from 'is-local'
|
|
2
2
|
import treatLocalFile from './treatLocalFile.js'
|
|
3
3
|
import treatRemoteFile from './treatRemoteFile.js'
|
|
4
|
+
import ensureDirectoryExists from '../../../../lib/fs/ensureDirectoryExists.js'
|
|
4
5
|
|
|
5
6
|
export default async ({ child,
|
|
6
|
-
path,
|
|
7
|
+
path, buildPaths }) => {
|
|
7
8
|
const { properties: {
|
|
8
9
|
src: url,
|
|
9
10
|
} } = child
|
|
10
11
|
|
|
11
12
|
let result
|
|
12
|
-
const destination =
|
|
13
|
+
const destination = buildPaths.email.assetsContainer
|
|
14
|
+
await ensureDirectoryExists(destination)
|
|
13
15
|
|
|
14
16
|
if (isLocal(url)) {
|
|
15
17
|
if (url.indexOf(destination) !== 0) {
|
|
@@ -23,7 +25,8 @@ export default async ({ child,
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
let filename = result.filename
|
|
26
|
-
const newUrl = `.assets/${filename}`
|
|
28
|
+
// const newUrl = `.assets/${filename}`
|
|
29
|
+
const newUrl = result.path
|
|
27
30
|
return {
|
|
28
31
|
...child,
|
|
29
32
|
properties: {
|
|
@@ -22,30 +22,36 @@ export default async ({
|
|
|
22
22
|
buildPaths: {
|
|
23
23
|
email: {
|
|
24
24
|
container: `${path}/.build/email/${code}`,
|
|
25
|
+
containerRemote: `${entry.slug}/email/${code}`,
|
|
25
26
|
body: `${path}/.build/email/${code}/body.html`,
|
|
26
27
|
bodyFileName: `${entry.slug}/email/${code}/body.html`,
|
|
27
28
|
text: `${path}/.build/email/${code}/text.txt`,
|
|
28
29
|
textFileName: `${entry.slug}/email/${code}/text.txt`,
|
|
29
30
|
subject: `${path}/.build/email/${code}/subject.txt`,
|
|
30
31
|
subjectFileName: `${entry.slug}/email/${code}/subject.txt`,
|
|
31
|
-
assetsContainer: `${
|
|
32
|
+
assetsContainer: `${path}/.build/email/${code}/assets`,
|
|
33
|
+
assetsContainerRemote: `${entry.slug}/email/${code}/assets`,
|
|
32
34
|
attachmentsContainer: `${entry.slug}/email/${code}/attachments`,
|
|
33
35
|
manifestFileNameBuilt: `${path}/.build/email/${code}/manifest.json`,
|
|
34
36
|
manifestFileName: `${entry.slug}/email/${code}/manifest.json`,
|
|
35
37
|
},
|
|
36
38
|
textMessage: {
|
|
37
39
|
container: `${path}/.build/textmessage/${code}`,
|
|
40
|
+
containerRemote: `${entry.slug}/textmessage/${code}`,
|
|
38
41
|
text: `${path}/.build/textmessage/${code}/textmessage.txt`,
|
|
39
42
|
textFileName: `${entry.slug}/textmessage/${code}/textmessage.txt`,
|
|
40
|
-
assetsContainer: `${
|
|
43
|
+
assetsContainer: `${path}/.build/textmessage/${code}/assets`,
|
|
44
|
+
assetsContainerRemote: `${entry.slug}/textmessage/${code}/assets`,
|
|
41
45
|
manifestFileNameBuilt: `${path}/.build/textmessage/${code}/manifest.json`,
|
|
42
46
|
manifestFileName: `${entry.slug}/textmessage/${code}/manifest.json`,
|
|
43
47
|
},
|
|
44
48
|
pushNotification: {
|
|
45
49
|
container: `${path}/.build/pushnotification/${code}`,
|
|
50
|
+
containerRemote: `${entry.slug}/pushnotification/${code}`,
|
|
46
51
|
text: `${path}/.build/pushnotification/${code}/pushnotification.txt`,
|
|
47
52
|
textFileName: `${entry.slug}/pushnotification/${code}/pushnotification.txt`,
|
|
48
|
-
assetsContainer: `${
|
|
53
|
+
assetsContainer: `${path}/.build/pushnotification/${code}/assets`,
|
|
54
|
+
assetsContainerRemote: `${entry.slug}/pushnotification/${code}/assets`,
|
|
49
55
|
manifestFileNameBuilt: `${path}/.build/pushnotification/${code}/manifest.json`,
|
|
50
56
|
manifestFileName: `${entry.slug}/pushnotification/${code}/manifest.json`,
|
|
51
57
|
},
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import hastToHtml from '../../../lib/remark/hastToHtml.js'
|
|
2
2
|
import treatImage from './image/index.js'
|
|
3
|
+
import fs from 'fs'
|
|
3
4
|
|
|
4
5
|
export default async (props) => {
|
|
5
6
|
const { entry } = props
|
|
6
|
-
const { path, email: { hast } } = entry
|
|
7
|
+
const { path, email: { hast }, buildPaths } = entry
|
|
7
8
|
|
|
8
9
|
let _hast = await perform({
|
|
9
10
|
child: hast,
|
|
10
|
-
path
|
|
11
|
+
path,
|
|
12
|
+
buildPaths
|
|
11
13
|
})
|
|
12
14
|
|
|
13
15
|
let body = hastToHtml({ data: _hast })
|
|
14
16
|
|
|
17
|
+
await fs.promises.writeFile(
|
|
18
|
+
buildPaths.email.body,
|
|
19
|
+
body
|
|
20
|
+
)
|
|
21
|
+
|
|
15
22
|
return {
|
|
16
23
|
entry: {
|
|
17
24
|
...entry,
|
|
@@ -25,7 +32,7 @@ export default async (props) => {
|
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
const perform = async (props) => {
|
|
28
|
-
const { child, path } = props
|
|
35
|
+
const { child, path, buildPaths } = props
|
|
29
36
|
let _child = { ...child }
|
|
30
37
|
|
|
31
38
|
if (child.properties && _child.properties.dataNotifilesDoNotOptimize) {
|
|
@@ -36,7 +43,8 @@ const perform = async (props) => {
|
|
|
36
43
|
case 'img': {
|
|
37
44
|
_child = await treatImage({
|
|
38
45
|
child: _child,
|
|
39
|
-
path
|
|
46
|
+
path,
|
|
47
|
+
buildPaths
|
|
40
48
|
})
|
|
41
49
|
} break
|
|
42
50
|
default:
|
|
@@ -2,9 +2,10 @@ import fsPath from 'path'
|
|
|
2
2
|
import isLocal from 'is-local'
|
|
3
3
|
import isRelative from 'is-relative'
|
|
4
4
|
import sharp from 'sharp'
|
|
5
|
+
import fs from 'fs'
|
|
5
6
|
|
|
6
7
|
export default async ({ child,
|
|
7
|
-
path, }) => {
|
|
8
|
+
path, buildPaths }) => {
|
|
8
9
|
const { properties: {
|
|
9
10
|
src: url,
|
|
10
11
|
} } = child
|
|
@@ -22,14 +23,17 @@ export default async ({ child,
|
|
|
22
23
|
default: break
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
const filename =
|
|
26
|
-
const destination = `${
|
|
26
|
+
const filename = `${fsPath.parse(sourceUrl).name}_optimized.webp`
|
|
27
|
+
const destination = `${buildPaths.email.assetsContainer}/${filename}`
|
|
27
28
|
|
|
28
29
|
await sharp(sourceUrl)
|
|
29
30
|
.webp({ quality: 90 })
|
|
30
31
|
.toFile(destination)
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
await fs.promises.rm(sourceUrl)
|
|
34
|
+
|
|
35
|
+
// const newUrl = `assets/${filename}`
|
|
36
|
+
const newUrl = destination
|
|
33
37
|
return {
|
|
34
38
|
...child,
|
|
35
39
|
properties: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import syncFolder from './syncFolder.js'
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import updateActivity from '../../lib/activity/updateToFile.js'
|
|
4
4
|
import getActivity from '../../lib/activity/get.js'
|
|
@@ -10,10 +10,10 @@ export default async (props) => {
|
|
|
10
10
|
const { path, email, buildPaths, } = entry
|
|
11
11
|
const { body, } = email
|
|
12
12
|
|
|
13
|
-
await fs.promises.writeFile(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
13
|
+
// await fs.promises.writeFile(
|
|
14
|
+
// buildPaths.email.body,
|
|
15
|
+
// body
|
|
16
|
+
// )
|
|
17
17
|
|
|
18
18
|
let manifest = await importJSONAsync(
|
|
19
19
|
buildPaths.manifestFileNameBuilt,
|
|
@@ -38,31 +38,10 @@ export default async (props) => {
|
|
|
38
38
|
let uploadResult = null
|
|
39
39
|
for (var i in clouds) {
|
|
40
40
|
const cloud = clouds[i]
|
|
41
|
-
uploadResult = await
|
|
42
|
-
id: cloud.id,
|
|
43
|
-
sourceUrl: buildPaths.email.body,
|
|
44
|
-
filename: buildPaths.email.bodyFileName,
|
|
45
|
-
auth: cloud.auth,
|
|
46
|
-
settings
|
|
47
|
-
})
|
|
48
|
-
uploadResult = await upload({
|
|
49
|
-
id: cloud.id,
|
|
50
|
-
sourceUrl: buildPaths.email.text,
|
|
51
|
-
filename: buildPaths.email.textFileName,
|
|
52
|
-
auth: cloud.auth,
|
|
53
|
-
settings
|
|
54
|
-
})
|
|
55
|
-
uploadResult = await upload({
|
|
56
|
-
id: cloud.id,
|
|
57
|
-
sourceUrl: buildPaths.email.subject,
|
|
58
|
-
filename: buildPaths.email.subjectFileName,
|
|
59
|
-
auth: cloud.auth,
|
|
60
|
-
settings
|
|
61
|
-
})
|
|
62
|
-
uploadResult = await upload({
|
|
41
|
+
uploadResult = await syncFolder({
|
|
63
42
|
id: cloud.id,
|
|
64
|
-
sourceUrl: buildPaths.email.
|
|
65
|
-
|
|
43
|
+
sourceUrl: buildPaths.email.container,
|
|
44
|
+
destinationPath: buildPaths.email.containerRemote,
|
|
66
45
|
auth: cloud.auth,
|
|
67
46
|
settings
|
|
68
47
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import upload from './upload.js'
|
|
2
1
|
import fs from 'fs'
|
|
3
2
|
import updateActivity from '../../lib/activity/updateToFile.js'
|
|
4
3
|
import getActivity from '../../lib/activity/get.js'
|
|
5
4
|
import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
|
|
6
5
|
import checkFileExists from '../../../lib/fs/checkFileExists.js'
|
|
6
|
+
import syncFolder from './syncFolder.js'
|
|
7
7
|
|
|
8
8
|
export default async (props) => {
|
|
9
9
|
|
|
@@ -46,17 +46,10 @@ export default async (props) => {
|
|
|
46
46
|
let uploadResult = null
|
|
47
47
|
for (var i in clouds) {
|
|
48
48
|
const cloud = clouds[i]
|
|
49
|
-
uploadResult = await
|
|
49
|
+
uploadResult = await syncFolder({
|
|
50
50
|
id: cloud.id,
|
|
51
|
-
sourceUrl: buildPaths.pushNotification.
|
|
52
|
-
|
|
53
|
-
auth: cloud.auth,
|
|
54
|
-
settings
|
|
55
|
-
})
|
|
56
|
-
uploadResult = await upload({
|
|
57
|
-
id: cloud.id,
|
|
58
|
-
sourceUrl: buildPaths.pushNotification.manifestFileNameBuilt,
|
|
59
|
-
filename: buildPaths.pushNotification.manifestFileName,
|
|
51
|
+
sourceUrl: buildPaths.pushNotification.container,
|
|
52
|
+
destinationPath: buildPaths.pushNotification.containerRemote,
|
|
60
53
|
auth: cloud.auth,
|
|
61
54
|
settings
|
|
62
55
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import upload from './upload.js'
|
|
2
1
|
import fs from 'fs'
|
|
3
2
|
import updateActivity from '../../lib/activity/updateToFile.js'
|
|
4
3
|
import getActivity from '../../lib/activity/get.js'
|
|
5
4
|
import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
|
|
6
5
|
import checkFileExists from '../../../lib/fs/checkFileExists.js'
|
|
6
|
+
import syncFolder from './syncFolder.js'
|
|
7
7
|
|
|
8
8
|
export default async (props) => {
|
|
9
9
|
|
|
@@ -46,17 +46,10 @@ export default async (props) => {
|
|
|
46
46
|
let uploadResult = null
|
|
47
47
|
for (var i in clouds) {
|
|
48
48
|
const cloud = clouds[i]
|
|
49
|
-
uploadResult = await
|
|
49
|
+
uploadResult = await syncFolder({
|
|
50
50
|
id: cloud.id,
|
|
51
|
-
sourceUrl: buildPaths.textMessage.
|
|
52
|
-
|
|
53
|
-
auth: cloud.auth,
|
|
54
|
-
settings
|
|
55
|
-
})
|
|
56
|
-
uploadResult = await upload({
|
|
57
|
-
id: cloud.id,
|
|
58
|
-
sourceUrl: buildPaths.textMessage.manifestFileNameBuilt,
|
|
59
|
-
filename: buildPaths.textMessage.manifestFileName,
|
|
51
|
+
sourceUrl: buildPaths.textMessage.container,
|
|
52
|
+
destinationPath: buildPaths.textMessage.containerRemote,
|
|
60
53
|
auth: cloud.auth,
|
|
61
54
|
settings
|
|
62
55
|
})
|
|
@@ -7,6 +7,7 @@ import optimize from '../optimize/entry.js'
|
|
|
7
7
|
import version from '../version/entry.js'
|
|
8
8
|
import cloudify from '../cloudify/entry.js'
|
|
9
9
|
import adaptSettings from '../../lib/adaptSettings.js'
|
|
10
|
+
import attach from '../attach/entry.js'
|
|
10
11
|
|
|
11
12
|
export default async ({
|
|
12
13
|
path,
|
|
@@ -32,7 +33,11 @@ export default async ({
|
|
|
32
33
|
entry = (await consolidate({ entry, settings })).entry
|
|
33
34
|
entry = (await optimize({ entry, settings })).entry
|
|
34
35
|
entry = (await cloudify({ entry, settings })).entry
|
|
35
|
-
entry = (await
|
|
36
|
+
entry = (await attach({ entry, settings })).entry
|
|
37
|
+
if (!settings.dryRun) {
|
|
38
|
+
entry = (await sync({ entry, settings })).entry
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
|
|
37
42
|
await version({})
|
|
38
43
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import getActivity from '../../../../lib/activity/get.js'
|
|
2
|
-
import updateActivity from '../../../../lib/activity/updateToFile.js'
|
|
3
|
-
|
|
4
|
-
export default async ({ path, entry, fileName, attachment }) => {
|
|
5
|
-
let activity = await getActivity({ path })
|
|
6
|
-
let attachments = [
|
|
7
|
-
...((activity[entry.code] && activity[entry.code].attachments)
|
|
8
|
-
? activity[entry.code].attachments
|
|
9
|
-
: []),
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
attachments = attachments.filter(a => a.id !== fileName)
|
|
13
|
-
attachments.push(attachment)
|
|
14
|
-
|
|
15
|
-
activity[entry.code] = {
|
|
16
|
-
...(activity[entry.code] ? activity[entry.code] : {}),
|
|
17
|
-
attachments
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
await updateActivity({
|
|
21
|
-
path,
|
|
22
|
-
content: activity,
|
|
23
|
-
})
|
|
24
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import upload from '../../upload.js'
|
|
2
|
-
|
|
3
|
-
import getActivity from '../../../../lib/activity/get.js'
|
|
4
|
-
import updateActivity from '../../../../lib/activity/updateToFile.js'
|
|
5
|
-
import fs from 'fs'
|
|
6
|
-
import checkFileExists from '../../../../../lib/fs/checkFileExists.js'
|
|
7
|
-
import _mimetype from 'mimetype'
|
|
8
|
-
import remove from '../../remove.js'
|
|
9
|
-
import addAttachment from './addAttachment.js'
|
|
10
|
-
|
|
11
|
-
export default async ({ child,
|
|
12
|
-
path,
|
|
13
|
-
settings,
|
|
14
|
-
buildPaths,
|
|
15
|
-
entry
|
|
16
|
-
}) => {
|
|
17
|
-
|
|
18
|
-
let entries = await fs.promises.readdir(`${path}/attachments`)
|
|
19
|
-
let items = entries.map(fileName => ({
|
|
20
|
-
fileName,
|
|
21
|
-
path: `${path}/attachments/${fileName}`
|
|
22
|
-
}))
|
|
23
|
-
|
|
24
|
-
let codeDestination = `${path}/attachments/${entry.code}`
|
|
25
|
-
if ((await checkFileExists(codeDestination))) {
|
|
26
|
-
entries = await fs.promises.readdir(codeDestination)
|
|
27
|
-
items = [
|
|
28
|
-
...items,
|
|
29
|
-
...(entries.map(fileName => ({
|
|
30
|
-
fileName,
|
|
31
|
-
path: `${codeDestination}/${fileName}`
|
|
32
|
-
})))
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!items) {
|
|
37
|
-
return {}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const { clouds } = settings
|
|
41
|
-
|
|
42
|
-
let __activity = await getActivity({ path })
|
|
43
|
-
let previousActivity = __activity[entry.code]
|
|
44
|
-
__activity[entry.code] = {}
|
|
45
|
-
await updateActivity({
|
|
46
|
-
path,
|
|
47
|
-
content: __activity,
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
const uploaded = []
|
|
51
|
-
for (var i in items) {
|
|
52
|
-
const { fileName, path: folderPath } = items[i]
|
|
53
|
-
const fileNameRemote = encodeURI(fileName)
|
|
54
|
-
|
|
55
|
-
const folderPathStat = await fs.promises.stat(folderPath)
|
|
56
|
-
if (!folderPathStat) {
|
|
57
|
-
continue
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const isDir = folderPathStat.isDirectory()
|
|
61
|
-
if (isDir) {
|
|
62
|
-
continue
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (!settings.forceUploadAttachments) {
|
|
66
|
-
if (previousActivity) {
|
|
67
|
-
if (previousActivity.attachments) {
|
|
68
|
-
const attachment = previousActivity.attachments.find(a => a.id === fileName)
|
|
69
|
-
if (attachment) {
|
|
70
|
-
uploaded.push(attachment)
|
|
71
|
-
await addAttachment({ path, entry, fileName, attachment })
|
|
72
|
-
continue
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const mimeType = _mimetype.lookup(folderPath)
|
|
79
|
-
let uploadResult = null
|
|
80
|
-
|
|
81
|
-
for (var i in clouds) {
|
|
82
|
-
const cloud = clouds[i]
|
|
83
|
-
uploadResult = await upload({
|
|
84
|
-
id: cloud.id,
|
|
85
|
-
sourceUrl: folderPath,
|
|
86
|
-
filename: `${buildPaths.email.attachmentsContainer}/${fileNameRemote}`,
|
|
87
|
-
auth: cloud.auth,
|
|
88
|
-
settings
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (!uploadResult || !uploadResult.url) {
|
|
93
|
-
continue
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const attachment = {
|
|
97
|
-
id: fileName,
|
|
98
|
-
fileName,
|
|
99
|
-
url: uploadResult.url,
|
|
100
|
-
mimeType,
|
|
101
|
-
disposition: "attachment",
|
|
102
|
-
relativeFileName: `${buildPaths.email.attachmentsContainer}/${fileNameRemote}`,
|
|
103
|
-
}
|
|
104
|
-
uploaded.push(attachment
|
|
105
|
-
)
|
|
106
|
-
await addAttachment({
|
|
107
|
-
path, entry, fileName, attachment
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const removed = []
|
|
113
|
-
for (var i in previousActivity.attachments) {
|
|
114
|
-
const item = previousActivity.attachments[i]
|
|
115
|
-
const eq = uploaded.find(a => a.id === item.id)
|
|
116
|
-
if (!eq) {
|
|
117
|
-
removed.push(item)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
for (var i in removed) {
|
|
122
|
-
const item = removed[i]
|
|
123
|
-
for (var i in clouds) {
|
|
124
|
-
const cloud = clouds[i]
|
|
125
|
-
await remove({
|
|
126
|
-
id: cloud.id,
|
|
127
|
-
filename: item.relativeFileName,
|
|
128
|
-
auth: cloud.auth,
|
|
129
|
-
settings
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import fsPath from 'path'
|
|
2
|
-
import isRelative from 'is-relative'
|
|
3
|
-
|
|
4
|
-
export default async ({
|
|
5
|
-
url, path, }) => {
|
|
6
|
-
const sourceUrl = isRelative(url) ? fsPath.resolve(path, url) : url
|
|
7
|
-
const filename = fsPath.basename(sourceUrl)
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
filename,
|
|
11
|
-
sourceUrl
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import fsPath from 'path'
|
|
2
|
-
import downloadImage from 'image-downloader'
|
|
3
|
-
|
|
4
|
-
export default async ({ url,
|
|
5
|
-
destination
|
|
6
|
-
}) => {
|
|
7
|
-
try {
|
|
8
|
-
const options = {
|
|
9
|
-
url,
|
|
10
|
-
dest: destination, // will be saved to /path/to/dest/photo
|
|
11
|
-
extractFilename: true,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const item = await downloadImage.image(options)
|
|
15
|
-
// const { filename } = item
|
|
16
|
-
const filename = fsPath.basename(item.filename)
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
filename,
|
|
20
|
-
sourceUrl: destination
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
console.error(e)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default async (props) => {
|
|
2
|
-
|
|
3
|
-
const { id, settings } = props
|
|
4
|
-
|
|
5
|
-
const cloudLibrary = settings.cloudLibrary({ id })
|
|
6
|
-
if (!cloudLibrary) {
|
|
7
|
-
return {
|
|
8
|
-
isValid: false,
|
|
9
|
-
error: new Error('Cloud not supported.')
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return cloudLibrary.upload(props)
|
|
14
|
-
}
|