2018-02-09 21:34:14 -05:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage (C) 2018 MinIO, Inc.
|
2018-02-09 21:34:14 -05:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import web from "../web"
|
|
|
|
import history from "../history"
|
2019-06-25 19:31:50 -04:00
|
|
|
import {
|
|
|
|
sortObjectsByName,
|
|
|
|
sortObjectsBySize,
|
2020-04-08 13:47:47 -04:00
|
|
|
sortObjectsByDate,
|
2019-06-25 19:31:50 -04:00
|
|
|
} from "../utils"
|
2018-02-14 21:34:59 -05:00
|
|
|
import { getCurrentBucket } from "../buckets/selectors"
|
2018-02-20 21:00:43 -05:00
|
|
|
import { getCurrentPrefix, getCheckedList } from "./selectors"
|
2018-02-18 23:07:59 -05:00
|
|
|
import * as alertActions from "../alert/actions"
|
2019-06-25 19:31:50 -04:00
|
|
|
import {
|
|
|
|
minioBrowserPrefix,
|
|
|
|
SORT_BY_NAME,
|
|
|
|
SORT_BY_SIZE,
|
|
|
|
SORT_BY_LAST_MODIFIED,
|
|
|
|
SORT_ORDER_ASC,
|
2020-04-08 13:47:47 -04:00
|
|
|
SORT_ORDER_DESC,
|
2019-06-25 19:31:50 -04:00
|
|
|
} from "../constants"
|
2020-05-02 02:55:53 -04:00
|
|
|
import { getServerInfo, hasServerPublicDomain } from '../browser/selectors'
|
2018-02-09 21:34:14 -05:00
|
|
|
|
|
|
|
export const SET_LIST = "objects/SET_LIST"
|
2019-06-25 19:31:50 -04:00
|
|
|
export const RESET_LIST = "objects/RESET_LIST"
|
2018-02-09 21:34:14 -05:00
|
|
|
export const APPEND_LIST = "objects/APPEND_LIST"
|
2018-02-18 23:07:59 -05:00
|
|
|
export const REMOVE = "objects/REMOVE"
|
2018-02-09 21:34:14 -05:00
|
|
|
export const SET_SORT_BY = "objects/SET_SORT_BY"
|
|
|
|
export const SET_SORT_ORDER = "objects/SET_SORT_ORDER"
|
|
|
|
export const SET_CURRENT_PREFIX = "objects/SET_CURRENT_PREFIX"
|
2018-02-23 22:29:30 -05:00
|
|
|
export const SET_PREFIX_WRITABLE = "objects/SET_PREFIX_WRITABLE"
|
2018-02-18 23:07:59 -05:00
|
|
|
export const SET_SHARE_OBJECT = "objects/SET_SHARE_OBJECT"
|
2018-02-20 21:00:43 -05:00
|
|
|
export const CHECKED_LIST_ADD = "objects/CHECKED_LIST_ADD"
|
|
|
|
export const CHECKED_LIST_REMOVE = "objects/CHECKED_LIST_REMOVE"
|
|
|
|
export const CHECKED_LIST_RESET = "objects/CHECKED_LIST_RESET"
|
2019-06-25 19:31:50 -04:00
|
|
|
export const SET_LIST_LOADING = "objects/SET_LIST_LOADING"
|
2018-02-09 21:34:14 -05:00
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const setList = (objects) => ({
|
2018-02-09 21:34:14 -05:00
|
|
|
type: SET_LIST,
|
2020-04-08 13:47:47 -04:00
|
|
|
objects,
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
|
2018-09-04 16:02:02 -04:00
|
|
|
export const resetList = () => ({
|
2020-04-08 13:47:47 -04:00
|
|
|
type: RESET_LIST,
|
2018-09-04 16:02:02 -04:00
|
|
|
})
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const setListLoading = (listLoading) => ({
|
2019-06-25 19:31:50 -04:00
|
|
|
type: SET_LIST_LOADING,
|
2020-04-08 13:47:47 -04:00
|
|
|
listLoading,
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
|
2019-06-25 19:31:50 -04:00
|
|
|
export const fetchObjects = () => {
|
2020-04-08 13:47:47 -04:00
|
|
|
return function (dispatch, getState) {
|
2019-06-25 19:31:50 -04:00
|
|
|
dispatch(resetList())
|
|
|
|
const {
|
|
|
|
buckets: { currentBucket },
|
2020-04-08 13:47:47 -04:00
|
|
|
objects: { currentPrefix },
|
2019-06-25 19:31:50 -04:00
|
|
|
} = getState()
|
2018-02-27 22:14:49 -05:00
|
|
|
if (currentBucket) {
|
2019-06-25 19:31:50 -04:00
|
|
|
dispatch(setListLoading(true))
|
2018-02-27 22:14:49 -05:00
|
|
|
return web
|
2018-09-20 13:24:09 -04:00
|
|
|
.ListObjects({
|
|
|
|
bucketName: currentBucket,
|
2020-04-08 13:47:47 -04:00
|
|
|
prefix: currentPrefix,
|
2018-09-20 13:24:09 -04:00
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
.then((res) => {
|
2019-06-27 15:13:18 -04:00
|
|
|
// 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 (
|
|
|
|
currentBucket === getCurrentBucket(getState()) &&
|
|
|
|
currentPrefix === getCurrentPrefix(getState())
|
|
|
|
) {
|
|
|
|
let objects = []
|
|
|
|
if (res.objects) {
|
2020-04-08 13:47:47 -04:00
|
|
|
objects = res.objects.map((object) => {
|
2019-06-27 15:13:18 -04:00
|
|
|
return {
|
|
|
|
...object,
|
2020-04-08 13:47:47 -04:00
|
|
|
name: object.name.replace(currentPrefix, ""),
|
2019-06-27 15:13:18 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-06-25 19:31:50 -04:00
|
|
|
|
2019-06-27 15:13:18 -04:00
|
|
|
const sortBy = SORT_BY_LAST_MODIFIED
|
|
|
|
const sortOrder = SORT_ORDER_DESC
|
|
|
|
dispatch(setSortBy(sortBy))
|
|
|
|
dispatch(setSortOrder(sortOrder))
|
|
|
|
const sortedList = sortObjectsList(objects, sortBy, sortOrder)
|
|
|
|
dispatch(setList(sortedList))
|
2019-06-25 19:31:50 -04:00
|
|
|
|
2019-06-27 15:13:18 -04:00
|
|
|
dispatch(setPrefixWritable(res.writable))
|
|
|
|
dispatch(setListLoading(false))
|
|
|
|
}
|
2018-09-20 13:24:09 -04:00
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
.catch((err) => {
|
2018-09-20 13:24:09 -04:00
|
|
|
if (web.LoggedIn()) {
|
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "danger",
|
|
|
|
message: err.message,
|
2020-04-08 13:47:47 -04:00
|
|
|
autoClear: true,
|
2018-09-20 13:24:09 -04:00
|
|
|
})
|
|
|
|
)
|
|
|
|
dispatch(resetList())
|
|
|
|
} else {
|
|
|
|
history.push("/login")
|
|
|
|
}
|
2019-06-25 19:31:50 -04:00
|
|
|
dispatch(setListLoading(false))
|
2018-09-20 13:24:09 -04:00
|
|
|
})
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const sortObjects = (sortBy) => {
|
|
|
|
return function (dispatch, getState) {
|
2019-06-25 19:31:50 -04:00
|
|
|
const { objects } = getState()
|
|
|
|
let sortOrder = SORT_ORDER_ASC
|
|
|
|
// Reverse sort order if the list is already sorted on same field
|
|
|
|
if (objects.sortBy === sortBy && objects.sortOrder === SORT_ORDER_ASC) {
|
|
|
|
sortOrder = SORT_ORDER_DESC
|
|
|
|
}
|
2018-02-09 21:34:14 -05:00
|
|
|
dispatch(setSortBy(sortBy))
|
|
|
|
dispatch(setSortOrder(sortOrder))
|
2019-06-25 19:31:50 -04:00
|
|
|
const sortedList = sortObjectsList(objects.list, sortBy, sortOrder)
|
|
|
|
dispatch(setList(sortedList))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const sortObjectsList = (list, sortBy, sortOrder) => {
|
|
|
|
switch (sortBy) {
|
|
|
|
case SORT_BY_NAME:
|
|
|
|
return sortObjectsByName(list, sortOrder)
|
|
|
|
case SORT_BY_SIZE:
|
|
|
|
return sortObjectsBySize(list, sortOrder)
|
|
|
|
case SORT_BY_LAST_MODIFIED:
|
|
|
|
return sortObjectsByDate(list, sortOrder)
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const setSortBy = (sortBy) => ({
|
2018-02-09 21:34:14 -05:00
|
|
|
type: SET_SORT_BY,
|
2020-04-08 13:47:47 -04:00
|
|
|
sortBy,
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const setSortOrder = (sortOrder) => ({
|
2018-02-09 21:34:14 -05:00
|
|
|
type: SET_SORT_ORDER,
|
2020-04-08 13:47:47 -04:00
|
|
|
sortOrder,
|
2018-02-09 21:34:14 -05:00
|
|
|
})
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const selectPrefix = (prefix) => {
|
|
|
|
return function (dispatch, getState) {
|
2018-02-09 21:34:14 -05:00
|
|
|
dispatch(setCurrentPrefix(prefix))
|
2018-02-14 21:34:59 -05:00
|
|
|
dispatch(fetchObjects())
|
2018-02-20 21:00:43 -05:00
|
|
|
dispatch(resetCheckedList())
|
2018-02-14 21:34:59 -05:00
|
|
|
const currentBucket = getCurrentBucket(getState())
|
2018-02-09 21:34:14 -05:00
|
|
|
history.replace(`/${currentBucket}/${prefix}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const setCurrentPrefix = (prefix) => {
|
2018-02-09 21:34:14 -05:00
|
|
|
return {
|
|
|
|
type: SET_CURRENT_PREFIX,
|
2020-04-08 13:47:47 -04:00
|
|
|
prefix,
|
2018-02-09 21:34:14 -05:00
|
|
|
}
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const setPrefixWritable = (prefixWritable) => ({
|
2018-02-23 22:29:30 -05:00
|
|
|
type: SET_PREFIX_WRITABLE,
|
2020-04-08 13:47:47 -04:00
|
|
|
prefixWritable,
|
2018-02-23 22:29:30 -05:00
|
|
|
})
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const deleteObject = (object) => {
|
|
|
|
return function (dispatch, getState) {
|
2018-02-18 23:07:59 -05:00
|
|
|
const currentBucket = getCurrentBucket(getState())
|
|
|
|
const currentPrefix = getCurrentPrefix(getState())
|
|
|
|
const objectName = `${currentPrefix}${object}`
|
|
|
|
return web
|
|
|
|
.RemoveObject({
|
|
|
|
bucketName: currentBucket,
|
2020-04-08 13:47:47 -04:00
|
|
|
objects: [objectName],
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
dispatch(removeObject(object))
|
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
.catch((e) => {
|
2018-02-18 23:07:59 -05:00
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "danger",
|
2020-04-08 13:47:47 -04:00
|
|
|
message: e.message,
|
2018-03-22 15:25:56 -04:00
|
|
|
})
|
2018-02-18 23:07:59 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const removeObject = (object) => ({
|
2018-02-18 23:07:59 -05:00
|
|
|
type: REMOVE,
|
2020-04-08 13:47:47 -04:00
|
|
|
object,
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
|
2018-02-20 21:00:43 -05:00
|
|
|
export const deleteCheckedObjects = () => {
|
2020-04-08 13:47:47 -04:00
|
|
|
return function (dispatch, getState) {
|
2018-02-20 21:00:43 -05:00
|
|
|
const checkedObjects = getCheckedList(getState())
|
|
|
|
for (let i = 0; i < checkedObjects.length; i++) {
|
|
|
|
dispatch(deleteObject(checkedObjects[i]))
|
|
|
|
}
|
|
|
|
dispatch(resetCheckedList())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 23:07:59 -05:00
|
|
|
export const shareObject = (object, days, hours, minutes) => {
|
2020-04-08 13:47:47 -04:00
|
|
|
return function (dispatch, getState) {
|
2020-05-02 02:55:53 -04:00
|
|
|
const hasServerDomain = hasServerPublicDomain(getState())
|
2018-02-18 23:07:59 -05:00
|
|
|
const currentBucket = getCurrentBucket(getState())
|
|
|
|
const currentPrefix = getCurrentPrefix(getState())
|
|
|
|
const objectName = `${currentPrefix}${object}`
|
|
|
|
const expiry = days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60
|
2018-11-14 21:05:10 -05:00
|
|
|
if (web.LoggedIn()) {
|
|
|
|
return web
|
2020-05-02 02:55:53 -04:00
|
|
|
.GetBucketPolicy({ bucketName: currentBucket, prefix: currentPrefix })
|
|
|
|
.catch(() => ({ policy: null }))
|
|
|
|
.then(({ policy }) => {
|
|
|
|
if (hasServerDomain && ['readonly', 'readwrite'].includes(policy)) {
|
|
|
|
const domain = getServerInfo(getState()).info.domains[0]
|
|
|
|
const url = `${domain}/${currentBucket}/${encodeURI(objectName)}`
|
|
|
|
dispatch(showShareObject(object, url, false))
|
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "success",
|
|
|
|
message: "Object shared."
|
|
|
|
})
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return web
|
|
|
|
.PresignedGet({
|
|
|
|
host: location.host,
|
|
|
|
bucket: currentBucket,
|
|
|
|
object: objectName,
|
|
|
|
expiry: expiry
|
|
|
|
})
|
|
|
|
}
|
2018-11-14 21:05:10 -05:00
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
.then((obj) => {
|
2020-05-02 02:55:53 -04:00
|
|
|
if (!obj) return
|
2018-11-14 21:05:10 -05:00
|
|
|
dispatch(showShareObject(object, obj.url))
|
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "success",
|
2020-04-08 13:47:47 -04:00
|
|
|
message: `Object shared. Expires in ${days} days ${hours} hours ${minutes} minutes`,
|
2018-11-14 21:05:10 -05:00
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
.catch((err) => {
|
2018-11-14 21:05:10 -05:00
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "danger",
|
2020-04-08 13:47:47 -04:00
|
|
|
message: err.message,
|
2018-11-14 21:05:10 -05:00
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
|
|
|
} else {
|
2019-06-25 19:31:50 -04:00
|
|
|
dispatch(
|
|
|
|
showShareObject(
|
|
|
|
object,
|
|
|
|
`${location.host}` +
|
|
|
|
"/" +
|
|
|
|
`${currentBucket}` +
|
|
|
|
"/" +
|
|
|
|
encodeURI(objectName)
|
|
|
|
)
|
|
|
|
)
|
2018-11-14 21:05:10 -05:00
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "success",
|
2020-04-08 13:47:47 -04:00
|
|
|
message: `Object shared.`,
|
2018-11-14 21:05:10 -05:00
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 02:55:53 -04:00
|
|
|
export const showShareObject = (object, url, showExpiryDate = true) => ({
|
2018-02-18 23:07:59 -05:00
|
|
|
type: SET_SHARE_OBJECT,
|
|
|
|
show: true,
|
|
|
|
object,
|
2020-04-08 13:47:47 -04:00
|
|
|
url,
|
2020-05-02 02:55:53 -04:00
|
|
|
showExpiryDate,
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
export const hideShareObject = (object, url) => ({
|
|
|
|
type: SET_SHARE_OBJECT,
|
|
|
|
show: false,
|
|
|
|
object: "",
|
2020-04-08 13:47:47 -04:00
|
|
|
url: "",
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
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) {
|
2018-02-20 21:00:43 -05:00
|
|
|
const currentBucket = getCurrentBucket(getState())
|
|
|
|
const currentPrefix = getCurrentPrefix(getState())
|
|
|
|
const objectName = `${currentPrefix}${object}`
|
|
|
|
const encObjectName = encodeURI(objectName)
|
|
|
|
if (web.LoggedIn()) {
|
|
|
|
return web
|
|
|
|
.CreateURLToken()
|
2020-04-08 13:47:47 -04:00
|
|
|
.then((res) => {
|
|
|
|
const url = `${window.location.origin}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=${res.token}`
|
2018-02-20 21:00:43 -05:00
|
|
|
window.location = url
|
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
.catch((err) => {
|
2018-02-20 21:00:43 -05:00
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "danger",
|
2020-04-08 13:47:47 -04:00
|
|
|
message: err.message,
|
2018-03-22 15:25:56 -04:00
|
|
|
})
|
2018-02-20 21:00:43 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
} else {
|
2020-04-08 13:47:47 -04:00
|
|
|
const url = `${window.location.origin}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=`
|
2018-02-20 21:00:43 -05:00
|
|
|
window.location = url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const checkObject = (object) => ({
|
2018-02-20 21:00:43 -05:00
|
|
|
type: CHECKED_LIST_ADD,
|
2020-04-08 13:47:47 -04:00
|
|
|
object,
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
export const uncheckObject = (object) => ({
|
2018-02-20 21:00:43 -05:00
|
|
|
type: CHECKED_LIST_REMOVE,
|
2020-04-08 13:47:47 -04:00
|
|
|
object,
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
export const resetCheckedList = () => ({
|
2020-04-08 13:47:47 -04:00
|
|
|
type: CHECKED_LIST_RESET,
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
export const downloadCheckedObjects = () => {
|
2020-04-08 13:47:47 -04:00
|
|
|
return function (dispatch, getState) {
|
2018-02-20 21:00:43 -05:00
|
|
|
const state = getState()
|
|
|
|
const req = {
|
|
|
|
bucketName: getCurrentBucket(state),
|
|
|
|
prefix: getCurrentPrefix(state),
|
2020-04-08 13:47:47 -04:00
|
|
|
objects: getCheckedList(state),
|
2018-02-20 21:00:43 -05:00
|
|
|
}
|
|
|
|
if (!web.LoggedIn()) {
|
2018-11-14 21:05:10 -05:00
|
|
|
const requestUrl = location.origin + "/minio/zip?token="
|
2018-02-20 21:00:43 -05:00
|
|
|
downloadZip(requestUrl, req, dispatch)
|
|
|
|
} else {
|
|
|
|
return web
|
|
|
|
.CreateURLToken()
|
2020-04-08 13:47:47 -04:00
|
|
|
.then((res) => {
|
|
|
|
const requestUrl = `${location.origin}${minioBrowserPrefix}/zip?token=${res.token}`
|
2018-02-20 21:00:43 -05:00
|
|
|
downloadZip(requestUrl, req, dispatch)
|
|
|
|
})
|
2020-04-08 13:47:47 -04:00
|
|
|
.catch((err) =>
|
2019-06-25 19:31:50 -04:00
|
|
|
dispatch(
|
|
|
|
alertActions.set({
|
|
|
|
type: "danger",
|
2020-04-08 13:47:47 -04:00
|
|
|
message: err.message,
|
2019-06-25 19:31:50 -04:00
|
|
|
})
|
|
|
|
)
|
2018-02-20 21:00:43 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const downloadZip = (url, req, dispatch) => {
|
|
|
|
var anchor = document.createElement("a")
|
|
|
|
document.body.appendChild(anchor)
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest()
|
|
|
|
xhr.open("POST", url, true)
|
|
|
|
xhr.responseType = "blob"
|
|
|
|
|
2020-04-08 13:47:47 -04:00
|
|
|
xhr.onload = function (e) {
|
2018-02-20 21:00:43 -05:00
|
|
|
if (this.status == 200) {
|
|
|
|
dispatch(resetCheckedList())
|
|
|
|
var blob = new Blob([this.response], {
|
2020-04-08 13:47:47 -04:00
|
|
|
type: "octet/stream",
|
2018-02-20 21:00:43 -05:00
|
|
|
})
|
|
|
|
var blobUrl = window.URL.createObjectURL(blob)
|
|
|
|
var separator = req.prefix.length > 1 ? "-" : ""
|
|
|
|
|
|
|
|
anchor.href = blobUrl
|
2019-06-25 19:31:50 -04:00
|
|
|
anchor.download =
|
|
|
|
req.bucketName + separator + req.prefix.slice(0, -1) + ".zip"
|
2018-02-20 21:00:43 -05:00
|
|
|
|
|
|
|
anchor.click()
|
|
|
|
window.URL.revokeObjectURL(blobUrl)
|
|
|
|
anchor.remove()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.send(JSON.stringify(req))
|
|
|
|
}
|