|
1 | 1 | import {axiosInstance} from "./axiosInstance";
|
2 | 2 | import urls from "./endpoint";
|
| 3 | +import {addColonAtLast, isLocalRemoteName} from "./Tools"; |
3 | 4 |
|
4 | 5 | /**
|
5 | 6 | * getStats returns the current rclone stats.
|
6 | 7 | * @returns {Promise<unknown>}
|
7 | 8 | */
|
8 |
| -export function getStats () { |
9 |
| - console.log("HI"); |
| 9 | +export const getStats = () => { |
10 | 10 | return new Promise((resolve, reject) => {
|
11 | 11 | axiosInstance.post(urls.stats).then(res => {
|
12 | 12 | resolve(res.data);
|
13 | 13 | }, error => {
|
14 | 14 | reject(error);
|
15 | 15 | })
|
16 | 16 | })
|
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * |
| 21 | + * @returns {Promise<unknown>} |
| 22 | + */ |
| 23 | +export const getCurrentBandwidthSetting = () => { |
| 24 | + return new Promise((resolve, reject) => { |
| 25 | + axiosInstance.post(urls.bwlimit).then(res => { |
| 26 | + resolve(res.data); |
| 27 | + }, error => { |
| 28 | + reject(error); |
| 29 | + }) |
| 30 | + }) |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * setCurrentBandwidthSetting changes the current bandwidth limit of the rclone backend. |
| 35 | + * @param newRate {string} Human readable format of size eg: 1M|2M|1.2G specifying 1MB, 2MB, 1.2GB respectively. |
| 36 | + * @returns {Promise<unknown>} |
| 37 | + */ |
| 38 | +export const setCurrentBandwidthSetting = (newRate) => { |
| 39 | + return new Promise((resolve, reject) => { |
| 40 | + axiosInstance.post(urls.bwlimit, {rate: newRate}).then(res => { |
| 41 | + resolve(res.data); |
| 42 | + }, error => { |
| 43 | + reject(error); |
| 44 | + }) |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +/** |
| 49 | + * Create a public link for a supported remote |
| 50 | + * @param remoteName {string} |
| 51 | + * @param remotePath {string} |
| 52 | + * @returns {Function} |
| 53 | + */ |
| 54 | +export const createPublicLink = (remoteName, remotePath) => { |
| 55 | + return new Promise((resolve, reject) => { |
| 56 | + axiosInstance.post(urls.createPublicLink, {fs: remoteName, remote: remotePath}).then(res => { |
| 57 | + resolve(res.data); |
| 58 | + }, error => { |
| 59 | + reject(error); |
| 60 | + }) |
| 61 | + }) |
| 62 | +}; |
17 | 63 |
|
| 64 | +/** |
| 65 | + * getAllProviders returns all the possible providers supported by the rclone backend |
| 66 | + * @returns {Promise<unknown>} |
| 67 | + */ |
| 68 | +export const getAllProviders = () => { |
| 69 | + return new Promise((resolve, reject) => { |
| 70 | + axiosInstance.post(urls.getProviders).then(res => { |
| 71 | + resolve(res.data.providers); |
| 72 | + }, error => { |
| 73 | + reject(error); |
| 74 | + }) |
| 75 | + }) |
18 | 76 | }
|
| 77 | + |
| 78 | +/** |
| 79 | + * getConfigDump return the configured remotes from the rclone backend |
| 80 | + * @returns {Promise<unknown>} |
| 81 | + */ |
| 82 | +export const getConfigDump = () => { |
| 83 | + return new Promise((resolve, reject) => { |
| 84 | + axiosInstance.post(urls.getConfigDump).then(res => { |
| 85 | + resolve(res.data); |
| 86 | + }, error => { |
| 87 | + reject(error); |
| 88 | + }) |
| 89 | + }) |
| 90 | +} |
| 91 | +/** |
| 92 | + * getFsInfo fetches the information regarding features, hashes from the rclone backend. Stores into redux store. |
| 93 | + * @param remoteName {string} The name of the remote |
| 94 | + * @returns {Function} |
| 95 | + */ |
| 96 | +export const getFsInfo = (remoteName) => { |
| 97 | + let sentRemoteName; |
| 98 | + if(!isLocalRemoteName(remoteName)) { |
| 99 | + sentRemoteName = addColonAtLast(remoteName.split(':')[0]); |
| 100 | + } |
| 101 | + return new Promise((resolve, reject) => { |
| 102 | + axiosInstance.post(urls.getFsInfo, { |
| 103 | + fs: sentRemoteName |
| 104 | + }).then(res => { |
| 105 | + resolve(res.data); |
| 106 | + }, error => { |
| 107 | + reject(error); |
| 108 | + }) |
| 109 | + }) |
| 110 | +} |
| 111 | + |
| 112 | +/** |
| 113 | + * getFilesList fetches the files for a specified remote path (remoteName + remotePath). Stores into redux store. |
| 114 | + * @param fs {string} Name of the remote config/ ("/" for local path). May contain abc:bucketName for bucket based remotes |
| 115 | + * @param remotePath {string} Name of the path in the remote |
| 116 | + * @returns {Function} |
| 117 | + */ |
| 118 | +export const getFilesList = (fs, remotePath) => { |
| 119 | + return new Promise((resolve, reject) => { |
| 120 | + if(!fs || fs === ""){ |
| 121 | + reject("Invalid fs specified") |
| 122 | + } |
| 123 | + |
| 124 | + // check if it is a local path |
| 125 | + fs = fs.indexOf('/') !== 0 ? addColonAtLast(fs) : fs; |
| 126 | + |
| 127 | + axiosInstance.post(urls.getFsInfo, { |
| 128 | + fs, |
| 129 | + remote: remotePath |
| 130 | + }).then(res => { |
| 131 | + resolve(res.data); |
| 132 | + }, error => { |
| 133 | + reject(error); |
| 134 | + }) |
| 135 | + }) |
| 136 | +} |
| 137 | + |
| 138 | +/** |
| 139 | + * getRemoteInfo fetches the information about a provider. |
| 140 | + * @param remoteName |
| 141 | + * @returns {Promise<unknown>} |
| 142 | + */ |
| 143 | +export const getRemoteInfo = (remoteName) => { |
| 144 | + |
| 145 | + return new Promise((resolve, reject) => { |
| 146 | + |
| 147 | + if(!remoteName) { |
| 148 | + reject("Invalid remote name specified") |
| 149 | + return |
| 150 | + } |
| 151 | + |
| 152 | + if (!isLocalRemoteName(remoteName)) { |
| 153 | + remoteName = addColonAtLast(remoteName); |
| 154 | + } |
| 155 | + axiosInstance.post(urls.getAbout, { |
| 156 | + fs: remoteName |
| 157 | + }).then(res => { |
| 158 | + resolve(res.data); |
| 159 | + }, error => { |
| 160 | + reject(error); |
| 161 | + }) |
| 162 | + }) |
| 163 | + |
| 164 | +} |
| 165 | + |
| 166 | +/** |
| 167 | + * getRemoteInfo fetches the information about a provider. |
| 168 | + * @param remoteName |
| 169 | + * @returns {Promise<unknown>} |
| 170 | + */ |
| 171 | +export const getRcloneVersion = () => { |
| 172 | + return new Promise((resolve, reject) => { |
| 173 | + axiosInstance.post(urls.getRcloneVersion).then(res => { |
| 174 | + resolve(res.data); |
| 175 | + }, error => { |
| 176 | + reject(error); |
| 177 | + }) |
| 178 | + }) |
| 179 | +} |
| 180 | + |
0 commit comments