strapi is not defined when connect use promise
Closed this issue · 1 comments
jm1jm2jm commented
When the connect() method returns with a promise it causes strapi is not defind
class SftpClient {
constructor() {
this.conn = new Client();
}
connect() {
return new Promise((resolve, reject) => {
this.conn
.on("ready", () => {
this.conn.sftp((err, sftp) => {
if (err) return reject(err);
sftp.readdir(remoteDir, (err, list) => {
if (err) return reject(err);
.....do something
});
});
})
.connect({
host: host,
port: "8000",
username: username,
password: password,
});
});
}
}
module.exports = {
sync: async (ctx, next) => {
await next();
const sftpClient = new SftpClient();
try {
await sftpClient.connect();
console.log(sftpClient.fileData, "sftpClient.data");
await strapi.entityService.findOne(
"api::xxx.xxx",
1,
);
} catch (err) {
console.error(err);
return { message: "Failed to sync" };
} finally {
}
},
};
mscdex commented
That error has nothing to do with ssh2
. You're missing whatever library is providing that object.