Skip to content

Commit

Permalink
web: Add btn with bearer and handler for unaccessible object
Browse files Browse the repository at this point in the history
closes #122

Signed-off-by: Mikhail Petrov <[email protected]>
  • Loading branch information
mike-petrov committed Feb 1, 2024
1 parent 3bd400d commit 8450fc1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
Binary file added public/img/icons/manage/unlock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 42 additions & 2 deletions src/Components/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ const File = ({
onModal('loading');
api('GET', `/get/${containerItem.containerId}/${objectItem.address.objectId}`, {}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.bearer}`,
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.token}`,
[BearerOwnerIdHeader]: walletData.account,
[BearerSignatureHeader]: walletData.tokens.object.GET.signature,
[BearerSignatureKeyHeader]: walletData.publicKey,
}).then((data) => {
if (data.header.indexOf("image/") !== -1 || data.header === 'text/plain; charset=utf-8') {
if (data.status !== 200) {
onModal('failed', 'Object is not accessible without a token');
} else if (data.header.indexOf("image/") !== -1 || data.header === 'text/plain; charset=utf-8') {
const fileURL = URL.createObjectURL(data.res);
window.open(fileURL, '_blank');
onModal();
Expand All @@ -202,6 +207,41 @@ const File = ({
height={40}
alt="get an object by link"
/>
<img
src="/img/icons/manage/unlock.png"
className="manage_icon"
onClick={() => {
onModal('loading');
api('GET', `/get/${containerItem.containerId}/${objectItem.address.objectId}`, {}, {
[ContentTypeHeader]: "application/json",
[AuthorizationHeader]: `Bearer ${walletData.tokens.object.GET.bearer}`,
}).then((data) => {
if (data.status !== 200) {
onModal('failed', 'Something went wrong, try again');
} else if (data.header.indexOf("image/") !== -1 || data.header === 'text/plain; charset=utf-8') {
const fileURL = URL.createObjectURL(data.res);
window.open(fileURL, '_blank');
onModal();
} else {
const a = document.createElement('a');
document.body.appendChild(a);
const url = window.URL.createObjectURL(data.res);
a.href = url;
a.download = name;
a.target = '_blank';
a.click();
setTimeout(() => {
onModal();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}, 0);
}
});
}}
width={40}
height={40}
alt="get an object by bearer"
/>
<img
src="/img/icons/manage/download.png"
className="manage_icon"
Expand Down
2 changes: 1 addition & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function api(method, url, params = {}, headers = {}) {
if (method === 'GET' && url.indexOf(`/get/`) !== -1) {
res = await response.blob();
const header = response.headers.get('Content-Type');
resolve({ header, res });
resolve({ header, res, status: response.status });
} else if (response.status === 413) {
reject('413 Request Entity Too Large');
} else if (response) {
Expand Down

0 comments on commit 8450fc1

Please sign in to comment.