Fix anonymous downloads URL generation (#6800)

Fixes #6778
master
Harshavardhana 6 years ago committed by kannappanr
parent 5f6d717b7a
commit 712abc7958
  1. 4
      browser/app/js/objects/__tests__/actions.test.js
  2. 90
      browser/app/js/objects/actions.js
  3. 55
      browser/ui-assets.go

@ -26,6 +26,8 @@ jest.mock("../../web", () => ({
.fn(() => true) .fn(() => true)
.mockReturnValueOnce(true) .mockReturnValueOnce(true)
.mockReturnValueOnce(false) .mockReturnValueOnce(false)
.mockReturnValueOnce(true)
.mockReturnValueOnce(true)
.mockReturnValueOnce(false), .mockReturnValueOnce(false),
ListObjects: jest.fn(({ bucketName }) => { ListObjects: jest.fn(({ bucketName }) => {
if (bucketName === "test-deny") { if (bucketName === "test-deny") {
@ -405,7 +407,7 @@ describe("Objects actions", () => {
store.dispatch(actionsObjects.downloadObject("obj1")) store.dispatch(actionsObjects.downloadObject("obj1"))
const url = `${ const url = `${
window.location.origin window.location.origin
}${minioBrowserPrefix}/download/bk1/${encodeURI("pre1/obj1")}?token=''` }${minioBrowserPrefix}/download/bk1/${encodeURI("pre1/obj1")}?token=`
expect(setLocation).toHaveBeenCalledWith(url) expect(setLocation).toHaveBeenCalledWith(url)
}) })

@ -16,11 +16,7 @@
import web from "../web" import web from "../web"
import history from "../history" import history from "../history"
import { import { sortObjectsByName, sortObjectsBySize, sortObjectsByDate } from "../utils"
sortObjectsByName,
sortObjectsBySize,
sortObjectsByDate
} from "../utils"
import { getCurrentBucket } from "../buckets/selectors" import { getCurrentBucket } from "../buckets/selectors"
import { getCurrentPrefix, getCheckedList } from "./selectors" import { getCurrentPrefix, getCheckedList } from "./selectors"
import * as alertActions from "../alert/actions" import * as alertActions from "../alert/actions"
@ -60,10 +56,7 @@ export const appendList = (objects, marker, isTruncated) => ({
export const fetchObjects = append => { export const fetchObjects = append => {
return function(dispatch, getState) { return function(dispatch, getState) {
const { const {buckets: {currentBucket}, objects: {currentPrefix, marker}} = getState()
buckets: { currentBucket },
objects: { currentPrefix, marker }
} = getState()
if (currentBucket) { if (currentBucket) {
return web return web
.ListObjects({ .ListObjects({
@ -110,7 +103,7 @@ export const fetchObjects = append => {
export const sortObjects = sortBy => { export const sortObjects = sortBy => {
return function(dispatch, getState) { return function(dispatch, getState) {
const { objects } = getState() const {objects} = getState()
const sortOrder = objects.sortBy == sortBy ? !objects.sortOrder : true const sortOrder = objects.sortBy == sortBy ? !objects.sortOrder : true
dispatch(setSortBy(sortBy)) dispatch(setSortBy(sortBy))
dispatch(setSortOrder(sortOrder)) dispatch(setSortOrder(sortOrder))
@ -210,30 +203,39 @@ export const shareObject = (object, days, hours, minutes) => {
const currentPrefix = getCurrentPrefix(getState()) const currentPrefix = getCurrentPrefix(getState())
const objectName = `${currentPrefix}${object}` const objectName = `${currentPrefix}${object}`
const expiry = days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60 const expiry = days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60
return web if (web.LoggedIn()) {
.PresignedGet({ return web
host: location.host, .PresignedGet({
bucket: currentBucket, host: location.host,
object: objectName, bucket: currentBucket,
expiry object: objectName
}) })
.then(obj => { .then(obj => {
dispatch(showShareObject(object, obj.url)) dispatch(showShareObject(object, obj.url))
dispatch( dispatch(
alertActions.set({ alertActions.set({
type: "success", 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( dispatch(
alertActions.set({ alertActions.set({
type: "danger", type: "danger",
message: err.message message: err.message
}) })
) )
}) })
} else {
dispatch(showShareObject(object, `${location.host}` + '/' + `${currentBucket}` + '/' + encodeURI(objectName)))
dispatch(
alertActions.set({
type: "success",
message: `Object shared.`
})
)
}
} }
} }
@ -279,7 +281,7 @@ export const downloadObject = object => {
} else { } else {
const url = `${ const url = `${
window.location.origin window.location.origin
}${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=''` }${minioBrowserPrefix}/download/${currentBucket}/${encObjectName}?token=`
window.location = url window.location = url
} }
} }
@ -308,7 +310,7 @@ export const downloadCheckedObjects = () => {
objects: getCheckedList(state) objects: getCheckedList(state)
} }
if (!web.LoggedIn()) { if (!web.LoggedIn()) {
const requestUrl = location.origin + "/minio/zip?token=''" const requestUrl = location.origin + "/minio/zip?token="
downloadZip(requestUrl, req, dispatch) downloadZip(requestUrl, req, dispatch)
} else { } else {
return web return web
@ -319,14 +321,13 @@ export const downloadCheckedObjects = () => {
}${minioBrowserPrefix}/zip?token=${res.token}` }${minioBrowserPrefix}/zip?token=${res.token}`
downloadZip(requestUrl, req, dispatch) downloadZip(requestUrl, req, dispatch)
}) })
.catch(err => .catch(err => dispatch(
dispatch( alertActions.set({
alertActions.set({ type: "danger",
type: "danger", message: err.message
message: err.message })
})
)
) )
)
} }
} }
} }
@ -349,8 +350,7 @@ const downloadZip = (url, req, dispatch) => {
var separator = req.prefix.length > 1 ? "-" : "" var separator = req.prefix.length > 1 ? "-" : ""
anchor.href = blobUrl anchor.href = blobUrl
anchor.download = anchor.download = req.bucketName + separator + req.prefix.slice(0, -1) + ".zip"
req.bucketName + separator + req.prefix.slice(0, -1) + ".zip"
anchor.click() anchor.click()
window.URL.revokeObjectURL(blobUrl) window.URL.revokeObjectURL(blobUrl)

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save