2020-06-08 10:29:24 +00:00
|
|
|
import apiClient from '../../../utils/apiClient';
|
2017-07-11 15:37:43 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2019-07-24 16:55:58 +00:00
|
|
|
import { startLoader, stopLoader } from './loader';
|
2017-07-11 15:37:43 +00:00
|
|
|
|
2019-07-24 16:55:58 +00:00
|
|
|
function setAssets(assets, totalSize) {
|
2017-07-11 15:37:43 +00:00
|
|
|
return {
|
|
|
|
type: ActionTypes.SET_ASSETS,
|
2019-07-24 16:55:58 +00:00
|
|
|
assets,
|
|
|
|
totalSize
|
2017-07-11 15:37:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-30 04:37:10 +00:00
|
|
|
export function getAssets() {
|
2019-07-24 16:55:58 +00:00
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(startLoader());
|
2020-06-08 10:29:24 +00:00
|
|
|
apiClient.get('/S3/objects')
|
2017-07-11 15:37:43 +00:00
|
|
|
.then((response) => {
|
2019-07-24 16:55:58 +00:00
|
|
|
dispatch(setAssets(response.data.assets, response.data.totalSize));
|
|
|
|
dispatch(stopLoader());
|
2017-07-11 15:37:43 +00:00
|
|
|
})
|
2019-07-24 16:55:58 +00:00
|
|
|
.catch(() => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.ERROR
|
|
|
|
});
|
|
|
|
dispatch(stopLoader());
|
|
|
|
});
|
2017-07-11 15:37:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-10 22:42:23 +00:00
|
|
|
export function deleteAsset(assetKey) {
|
2017-07-11 15:37:43 +00:00
|
|
|
return {
|
2019-09-10 22:42:23 +00:00
|
|
|
type: ActionTypes.DELETE_ASSET,
|
|
|
|
key: assetKey
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deleteAssetRequest(assetKey) {
|
|
|
|
return (dispatch) => {
|
2020-06-08 10:29:24 +00:00
|
|
|
apiClient.delete(`/S3/${assetKey}`)
|
2019-09-10 22:42:23 +00:00
|
|
|
.then((response) => {
|
|
|
|
dispatch(deleteAsset(assetKey));
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.ERROR
|
|
|
|
});
|
|
|
|
});
|
2017-07-11 15:37:43 +00:00
|
|
|
};
|
|
|
|
}
|