|
| 1 | +import axiosInstance from "../utils/API/API"; |
| 2 | +import urls from "../utils/API/endpoint"; |
| 3 | +import {CREATE_MOUNT, GET_MOUNT_LIST, REMOVE_MOUNT, REQUEST_ERROR, REQUEST_SUCCESS} from "./types"; |
| 4 | + |
| 5 | +/** |
| 6 | + * Get the current mount lists and load into state |
| 7 | + * @returns {function(...[*]=)} |
| 8 | + */ |
| 9 | +export const getMountList = () => { |
| 10 | + return (dispatch) => { |
| 11 | + axiosInstance.post(urls.listMounts).then(res => { |
| 12 | + console.log(res); |
| 13 | + dispatch({ |
| 14 | + type: GET_MOUNT_LIST, |
| 15 | + status: REQUEST_SUCCESS, |
| 16 | + payload: res.data |
| 17 | + }) |
| 18 | + }, (error) => { |
| 19 | + dispatch({ |
| 20 | + type: GET_MOUNT_LIST, |
| 21 | + status: REQUEST_ERROR, |
| 22 | + payload: error |
| 23 | + }) |
| 24 | + }) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Add a new mount location |
| 30 | + * @param fs {string} Name of the remote eg mydrive: |
| 31 | + * @param mountPoint {string} Path to mount on the local filesystem where rclone is running |
| 32 | + * @param mountType {string} One of "cmount", "mount", "mount2": Specifies what mountType rclone should use |
| 33 | + * @returns {function(...[*]=)} |
| 34 | + */ |
| 35 | +export const addMount = (fs, mountPoint, mountType) => { |
| 36 | + if (!fs.endsWith(":")) fs = fs + ":"; |
| 37 | + const type = CREATE_MOUNT |
| 38 | + return (dispatch) => { |
| 39 | + axiosInstance.post(urls.createMount, {fs, mountPoint, mountType}).then(res => { |
| 40 | + dispatch({ |
| 41 | + type, |
| 42 | + status: REQUEST_SUCCESS, |
| 43 | + payload: res.data |
| 44 | + }) |
| 45 | + }, (error) => { |
| 46 | + dispatch({ |
| 47 | + type, |
| 48 | + status: REQUEST_ERROR, |
| 49 | + payload: error |
| 50 | + }) |
| 51 | + }) |
| 52 | + dispatch(getMountList()); |
| 53 | + |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * unmount removes an mounted location "mountPoint" |
| 59 | + * @param mountPoint {string} Path to location where the mount was created. |
| 60 | + * @returns {function(...[*]=)} |
| 61 | + */ |
| 62 | +export const unmount = (mountPoint) => { |
| 63 | + const type = REMOVE_MOUNT; |
| 64 | + return (dispatch) => { |
| 65 | + axiosInstance.post(urls.removeMount, {mountPoint}).then(res => { |
| 66 | + dispatch({ |
| 67 | + type, |
| 68 | + status: REQUEST_SUCCESS, |
| 69 | + payload: res.data |
| 70 | + }) |
| 71 | + |
| 72 | + }, (error) => { |
| 73 | + dispatch({ |
| 74 | + type, |
| 75 | + status: REQUEST_ERROR, |
| 76 | + payload: error |
| 77 | + }) |
| 78 | + }) |
| 79 | + dispatch(getMountList()); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | +/** |
| 85 | + * unmountAll removes all mounts created by mount/mount |
| 86 | + * @returns {function(...[*]=)} |
| 87 | + */ |
| 88 | +export const unmountAll = () => { |
| 89 | + const type = REMOVE_MOUNT; |
| 90 | + return (dispatch) => { |
| 91 | + axiosInstance.post(urls.unmountAll).then(res => { |
| 92 | + dispatch({ |
| 93 | + type, |
| 94 | + status: REQUEST_SUCCESS, |
| 95 | + payload: res.data |
| 96 | + }) |
| 97 | + |
| 98 | + }, (error) => { |
| 99 | + dispatch({ |
| 100 | + type, |
| 101 | + status: REQUEST_ERROR, |
| 102 | + payload: error |
| 103 | + }) |
| 104 | + }) |
| 105 | + dispatch(getMountList()); |
| 106 | + } |
| 107 | +} |
0 commit comments