|
|
|
@ -19,7 +19,7 @@ import history from "../history" |
|
|
|
|
import { |
|
|
|
|
sortObjectsByName, |
|
|
|
|
sortObjectsBySize, |
|
|
|
|
sortObjectsByDate |
|
|
|
|
sortObjectsByDate, |
|
|
|
|
} from "../utils" |
|
|
|
|
import { getCurrentBucket } from "../buckets/selectors" |
|
|
|
|
import { getCurrentPrefix, getCheckedList } from "./selectors" |
|
|
|
@ -31,7 +31,7 @@ import { |
|
|
|
|
SORT_BY_SIZE, |
|
|
|
|
SORT_BY_LAST_MODIFIED, |
|
|
|
|
SORT_ORDER_ASC, |
|
|
|
|
SORT_ORDER_DESC |
|
|
|
|
SORT_ORDER_DESC, |
|
|
|
|
} from "../constants" |
|
|
|
|
|
|
|
|
|
export const SET_LIST = "objects/SET_LIST" |
|
|
|
@ -48,35 +48,35 @@ export const CHECKED_LIST_REMOVE = "objects/CHECKED_LIST_REMOVE" |
|
|
|
|
export const CHECKED_LIST_RESET = "objects/CHECKED_LIST_RESET" |
|
|
|
|
export const SET_LIST_LOADING = "objects/SET_LIST_LOADING" |
|
|
|
|
|
|
|
|
|
export const setList = objects => ({ |
|
|
|
|
export const setList = (objects) => ({ |
|
|
|
|
type: SET_LIST, |
|
|
|
|
objects |
|
|
|
|
objects, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const resetList = () => ({ |
|
|
|
|
type: RESET_LIST |
|
|
|
|
type: RESET_LIST, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const setListLoading = listLoading => ({ |
|
|
|
|
export const setListLoading = (listLoading) => ({ |
|
|
|
|
type: SET_LIST_LOADING, |
|
|
|
|
listLoading |
|
|
|
|
listLoading, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const fetchObjects = () => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
dispatch(resetList()) |
|
|
|
|
const { |
|
|
|
|
buckets: { currentBucket }, |
|
|
|
|
objects: { currentPrefix } |
|
|
|
|
objects: { currentPrefix }, |
|
|
|
|
} = getState() |
|
|
|
|
if (currentBucket) { |
|
|
|
|
dispatch(setListLoading(true)) |
|
|
|
|
return web |
|
|
|
|
.ListObjects({ |
|
|
|
|
bucketName: currentBucket, |
|
|
|
|
prefix: currentPrefix |
|
|
|
|
prefix: currentPrefix, |
|
|
|
|
}) |
|
|
|
|
.then(res => { |
|
|
|
|
.then((res) => { |
|
|
|
|
// we need to check if the bucket name and prefix are the same as
|
|
|
|
|
// when the request was made before updating the displayed objects
|
|
|
|
|
if ( |
|
|
|
@ -85,10 +85,10 @@ export const fetchObjects = () => { |
|
|
|
|
) { |
|
|
|
|
let objects = [] |
|
|
|
|
if (res.objects) { |
|
|
|
|
objects = res.objects.map(object => { |
|
|
|
|
objects = res.objects.map((object) => { |
|
|
|
|
return { |
|
|
|
|
...object, |
|
|
|
|
name: object.name.replace(currentPrefix, "") |
|
|
|
|
name: object.name.replace(currentPrefix, ""), |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
@ -104,13 +104,13 @@ export const fetchObjects = () => { |
|
|
|
|
dispatch(setListLoading(false)) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
.catch((err) => { |
|
|
|
|
if (web.LoggedIn()) { |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "danger", |
|
|
|
|
message: err.message, |
|
|
|
|
autoClear: true |
|
|
|
|
autoClear: true, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
dispatch(resetList()) |
|
|
|
@ -123,8 +123,8 @@ export const fetchObjects = () => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const sortObjects = sortBy => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
export const sortObjects = (sortBy) => { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
const { objects } = getState() |
|
|
|
|
let sortOrder = SORT_ORDER_ASC |
|
|
|
|
// Reverse sort order if the list is already sorted on same field
|
|
|
|
@ -149,18 +149,18 @@ const sortObjectsList = (list, sortBy, sortOrder) => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const setSortBy = sortBy => ({ |
|
|
|
|
export const setSortBy = (sortBy) => ({ |
|
|
|
|
type: SET_SORT_BY, |
|
|
|
|
sortBy |
|
|
|
|
sortBy, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const setSortOrder = sortOrder => ({ |
|
|
|
|
export const setSortOrder = (sortOrder) => ({ |
|
|
|
|
type: SET_SORT_ORDER, |
|
|
|
|
sortOrder |
|
|
|
|
sortOrder, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const selectPrefix = prefix => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
export const selectPrefix = (prefix) => { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
dispatch(setCurrentPrefix(prefix)) |
|
|
|
|
dispatch(fetchObjects()) |
|
|
|
|
dispatch(resetCheckedList()) |
|
|
|
@ -169,49 +169,49 @@ export const selectPrefix = prefix => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const setCurrentPrefix = prefix => { |
|
|
|
|
export const setCurrentPrefix = (prefix) => { |
|
|
|
|
return { |
|
|
|
|
type: SET_CURRENT_PREFIX, |
|
|
|
|
prefix |
|
|
|
|
prefix, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const setPrefixWritable = prefixWritable => ({ |
|
|
|
|
export const setPrefixWritable = (prefixWritable) => ({ |
|
|
|
|
type: SET_PREFIX_WRITABLE, |
|
|
|
|
prefixWritable |
|
|
|
|
prefixWritable, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const deleteObject = object => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
export const deleteObject = (object) => { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
const currentBucket = getCurrentBucket(getState()) |
|
|
|
|
const currentPrefix = getCurrentPrefix(getState()) |
|
|
|
|
const objectName = `${currentPrefix}${object}` |
|
|
|
|
return web |
|
|
|
|
.RemoveObject({ |
|
|
|
|
bucketName: currentBucket, |
|
|
|
|
objects: [objectName] |
|
|
|
|
objects: [objectName], |
|
|
|
|
}) |
|
|
|
|
.then(() => { |
|
|
|
|
dispatch(removeObject(object)) |
|
|
|
|
}) |
|
|
|
|
.catch(e => { |
|
|
|
|
.catch((e) => { |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "danger", |
|
|
|
|
message: e.message |
|
|
|
|
message: e.message, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const removeObject = object => ({ |
|
|
|
|
export const removeObject = (object) => ({ |
|
|
|
|
type: REMOVE, |
|
|
|
|
object |
|
|
|
|
object, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const deleteCheckedObjects = () => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
const checkedObjects = getCheckedList(getState()) |
|
|
|
|
for (let i = 0; i < checkedObjects.length; i++) { |
|
|
|
|
dispatch(deleteObject(checkedObjects[i])) |
|
|
|
@ -221,7 +221,7 @@ export const deleteCheckedObjects = () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const shareObject = (object, days, hours, minutes) => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
const currentBucket = getCurrentBucket(getState()) |
|
|
|
|
const currentPrefix = getCurrentPrefix(getState()) |
|
|
|
|
const objectName = `${currentPrefix}${object}` |
|
|
|
@ -232,22 +232,22 @@ export const shareObject = (object, days, hours, minutes) => { |
|
|
|
|
host: location.host, |
|
|
|
|
bucket: currentBucket, |
|
|
|
|
object: objectName, |
|
|
|
|
expiry: expiry |
|
|
|
|
expiry: expiry, |
|
|
|
|
}) |
|
|
|
|
.then(obj => { |
|
|
|
|
.then((obj) => { |
|
|
|
|
dispatch(showShareObject(object, obj.url)) |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "success", |
|
|
|
|
message: `Object shared. Expires in ${days} days ${hours} hours ${minutes} minutes` |
|
|
|
|
message: `Object shared. Expires in ${days} days ${hours} hours ${minutes} minutes`, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
.catch((err) => { |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "danger", |
|
|
|
|
message: err.message |
|
|
|
|
message: err.message, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
@ -265,7 +265,7 @@ export const shareObject = (object, days, hours, minutes) => { |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "success", |
|
|
|
|
message: `Object shared.` |
|
|
|
|
message: `Object shared.`, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -276,18 +276,44 @@ export const showShareObject = (object, url) => ({ |
|
|
|
|
type: SET_SHARE_OBJECT, |
|
|
|
|
show: true, |
|
|
|
|
object, |
|
|
|
|
url |
|
|
|
|
url, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const hideShareObject = (object, url) => ({ |
|
|
|
|
type: SET_SHARE_OBJECT, |
|
|
|
|
show: false, |
|
|
|
|
object: "", |
|
|
|
|
url: "" |
|
|
|
|
url: "", |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const downloadObject = object => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
export const getObjectURL = (object, callback) => { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
const currentBucket = getCurrentBucket(getState()) |
|
|
|
|
const currentPrefix = getCurrentPrefix(getState()) |
|
|
|
|
const objectName = `${currentPrefix}${object}` |
|
|
|
|
const encObjectName = encodeURI(objectName) |
|
|
|
|
if (web.LoggedIn()) { |
|
|
|
|
return web |
|
|
|
|
.CreateURLToken() |
|
|
|
|
.then((res) => { |
|
|
|
|
const url = `${window.location.origin}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=${res.token}` |
|
|
|
|
callback(url) |
|
|
|
|
}) |
|
|
|
|
.catch((err) => { |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "danger", |
|
|
|
|
message: err.message, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
const url = `${window.location.origin}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=` |
|
|
|
|
callback(url) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
export const downloadObject = (object) => { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
const currentBucket = getCurrentBucket(getState()) |
|
|
|
|
const currentPrefix = getCurrentPrefix(getState()) |
|
|
|
|
const objectName = `${currentPrefix}${object}` |
|
|
|
@ -295,52 +321,46 @@ export const downloadObject = object => { |
|
|
|
|
if (web.LoggedIn()) { |
|
|
|
|
return web |
|
|
|
|
.CreateURLToken() |
|
|
|
|
.then(res => { |
|
|
|
|
const url = `${ |
|
|
|
|
window.location.origin |
|
|
|
|
}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=${ |
|
|
|
|
res.token |
|
|
|
|
}` |
|
|
|
|
.then((res) => { |
|
|
|
|
const url = `${window.location.origin}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=${res.token}` |
|
|
|
|
window.location = url |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
.catch((err) => { |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "danger", |
|
|
|
|
message: err.message |
|
|
|
|
message: err.message, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
const url = `${ |
|
|
|
|
window.location.origin |
|
|
|
|
}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=` |
|
|
|
|
const url = `${window.location.origin}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=` |
|
|
|
|
window.location = url |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const checkObject = object => ({ |
|
|
|
|
export const checkObject = (object) => ({ |
|
|
|
|
type: CHECKED_LIST_ADD, |
|
|
|
|
object |
|
|
|
|
object, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const uncheckObject = object => ({ |
|
|
|
|
export const uncheckObject = (object) => ({ |
|
|
|
|
type: CHECKED_LIST_REMOVE, |
|
|
|
|
object |
|
|
|
|
object, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const resetCheckedList = () => ({ |
|
|
|
|
type: CHECKED_LIST_RESET |
|
|
|
|
type: CHECKED_LIST_RESET, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
export const downloadCheckedObjects = () => { |
|
|
|
|
return function(dispatch, getState) { |
|
|
|
|
return function (dispatch, getState) { |
|
|
|
|
const state = getState() |
|
|
|
|
const req = { |
|
|
|
|
bucketName: getCurrentBucket(state), |
|
|
|
|
prefix: getCurrentPrefix(state), |
|
|
|
|
objects: getCheckedList(state) |
|
|
|
|
objects: getCheckedList(state), |
|
|
|
|
} |
|
|
|
|
if (!web.LoggedIn()) { |
|
|
|
|
const requestUrl = location.origin + "/minio/zip?token=" |
|
|
|
@ -348,17 +368,15 @@ export const downloadCheckedObjects = () => { |
|
|
|
|
} else { |
|
|
|
|
return web |
|
|
|
|
.CreateURLToken() |
|
|
|
|
.then(res => { |
|
|
|
|
const requestUrl = `${ |
|
|
|
|
location.origin |
|
|
|
|
}${minioBrowserPrefix}/zip?token=${res.token}` |
|
|
|
|
.then((res) => { |
|
|
|
|
const requestUrl = `${location.origin}${minioBrowserPrefix}/zip?token=${res.token}` |
|
|
|
|
downloadZip(requestUrl, req, dispatch) |
|
|
|
|
}) |
|
|
|
|
.catch(err => |
|
|
|
|
.catch((err) => |
|
|
|
|
dispatch( |
|
|
|
|
alertActions.set({ |
|
|
|
|
type: "danger", |
|
|
|
|
message: err.message |
|
|
|
|
message: err.message, |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
@ -374,11 +392,11 @@ const downloadZip = (url, req, dispatch) => { |
|
|
|
|
xhr.open("POST", url, true) |
|
|
|
|
xhr.responseType = "blob" |
|
|
|
|
|
|
|
|
|
xhr.onload = function(e) { |
|
|
|
|
xhr.onload = function (e) { |
|
|
|
|
if (this.status == 200) { |
|
|
|
|
dispatch(resetCheckedList()) |
|
|
|
|
var blob = new Blob([this.response], { |
|
|
|
|
type: "octet/stream" |
|
|
|
|
type: "octet/stream", |
|
|
|
|
}) |
|
|
|
|
var blobUrl = window.URL.createObjectURL(blob) |
|
|
|
|
var separator = req.prefix.length > 1 ? "-" : "" |
|
|
|
|