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