@dnax/core 0.46.0 → 0.46.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/lib/media/sftp.ts +23 -15
- package/package.json +1 -1
package/lib/media/sftp.ts
CHANGED
|
@@ -30,13 +30,16 @@ class FilesystemSftpAdapter {
|
|
|
30
30
|
|
|
31
31
|
async connect() {
|
|
32
32
|
await this.#sftp
|
|
33
|
-
.connect(
|
|
33
|
+
.connect({
|
|
34
|
+
...this.config,
|
|
35
|
+
})
|
|
34
36
|
.then((e) => {
|
|
35
37
|
this.#connected = true;
|
|
36
38
|
})
|
|
37
39
|
.catch((err) => {
|
|
38
|
-
console.
|
|
40
|
+
console.error(err?.message);
|
|
39
41
|
});
|
|
42
|
+
//.finally(() => {});
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
async sync(
|
|
@@ -44,6 +47,7 @@ class FilesystemSftpAdapter {
|
|
|
44
47
|
type: "add" | "change" | "unlink" | "addDir" | "unlinkDir"
|
|
45
48
|
) {
|
|
46
49
|
try {
|
|
50
|
+
if (!this.#connected) return;
|
|
47
51
|
let remotePathDest =
|
|
48
52
|
this.config.remoteDir + p?.replace(process.cwd(), "");
|
|
49
53
|
let remoteDir = path.dirname(remotePathDest);
|
|
@@ -99,24 +103,28 @@ class FilesystemSftpAdapter {
|
|
|
99
103
|
buildPath += col?.slug + "/" + col?.media?.visibility;
|
|
100
104
|
let watchLocalDir = path.resolve(process.cwd() + "/" + buildPath);
|
|
101
105
|
|
|
102
|
-
await this.connect()
|
|
103
|
-
|
|
106
|
+
await this.connect()
|
|
107
|
+
.then(async (ops) => {
|
|
108
|
+
let remoteDir = this.config.remoteDir + buildPath;
|
|
104
109
|
|
|
105
|
-
|
|
110
|
+
let remoteDirExisis = await this.#sftp.exists(remoteDir);
|
|
106
111
|
|
|
107
|
-
|
|
112
|
+
//console.log("remoteDirExisis", remoteDir, remoteDirExisis);
|
|
108
113
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
if (!remoteDirExisis) {
|
|
115
|
+
await this.#sftp.mkdir(remoteDir, true).catch((err) => {});
|
|
116
|
+
// console.log("Watch", watchLocalDir);
|
|
112
117
|
|
|
113
|
-
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
this.watchDir(watchLocalDir);
|
|
120
|
+
}, 1000);
|
|
121
|
+
} else {
|
|
114
122
|
this.watchDir(watchLocalDir);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.catch((err) => {
|
|
126
|
+
console.error(err?.message);
|
|
127
|
+
});
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
|