* * @param {...any} args [username, password, hostname, port, ftps, active, name]
(...args)
| 14 | * @param {...any} args [username, password, hostname, port, ftps, active, name] |
| 15 | */ |
| 16 | async addFtp(...args) { |
| 17 | let stopConnection = false; |
| 18 | const { |
| 19 | username, // |
| 20 | password, |
| 21 | hostname, |
| 22 | port, |
| 23 | ftps, |
| 24 | active, |
| 25 | alias, |
| 26 | } = await prompt(...args); |
| 27 | const security = ftps ? "ftps" : "ftp"; |
| 28 | const mode = active ? "active" : "passive"; |
| 29 | const ftp = Ftp(hostname, username, password, port, security, mode); |
| 30 | try { |
| 31 | loader.create(strings["add ftp"], strings["connecting..."], { |
| 32 | timeout: 10000, |
| 33 | callback() { |
| 34 | stopConnection = true; |
| 35 | }, |
| 36 | }); |
| 37 | const [home] = await Promise.all([ftp.getWorkingDirectory(), loadAd()]); |
| 38 | |
| 39 | if (stopConnection) { |
| 40 | stopConnection = false; |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | const url = Url.formate({ |
| 45 | protocol: "ftp:", |
| 46 | username, |
| 47 | password, |
| 48 | hostname, |
| 49 | port, |
| 50 | path: "/", |
| 51 | query: { |
| 52 | mode, |
| 53 | security, |
| 54 | }, |
| 55 | }); |
| 56 | |
| 57 | const res = { |
| 58 | url, |
| 59 | alias, |
| 60 | name: alias, |
| 61 | type: "ftp", |
| 62 | home: null, |
| 63 | }; |
| 64 | |
| 65 | if (home !== "/") { |
| 66 | res.home = home; |
| 67 | } |
| 68 | loader.destroy(); |
| 69 | await helpers.showInterstitialIfReady(); |
| 70 | return res; |
| 71 | } catch (err) { |
| 72 | if (stopConnection) { |
| 73 | stopConnection = false; |