diff --git a/src/Components/EACLPanel/EACLPanel.js b/src/Components/EACLPanel/EACLPanel.js
index 726d390..c01b6ec 100644
--- a/src/Components/EACLPanel/EACLPanel.js
+++ b/src/Components/EACLPanel/EACLPanel.js
@@ -16,11 +16,6 @@ export default function EACLPanel({
setLoadContainers,
eACLParams,
setEACLParams,
- ContentTypeHeader,
- AuthorizationHeader,
- BearerOwnerIdHeader,
- BearerSignatureHeader,
- BearerSignatureKeyHeader,
isEdit = true,
isErrorParent,
}) {
@@ -44,11 +39,10 @@ export default function EACLPanel({
api('PUT', `/containers/${containerId}/eacl?walletConnect=true`, {
"records": eACLParams.filter((item) => delete item.isOpen),
}, {
- [ContentTypeHeader]: "application/json",
- [AuthorizationHeader]: `Bearer ${walletData.tokens.container.SETEACL.token}`,
- [BearerOwnerIdHeader]: walletData.account.address,
- [BearerSignatureHeader]: walletData.tokens.container.SETEACL.signature,
- [BearerSignatureKeyHeader]: walletData.publicKey,
+ "Authorization": `Bearer ${walletData.tokens.container.SETEACL.token}`,
+ "X-Bearer-Owner-Id": walletData.account.address,
+ "X-Bearer-Signature": walletData.tokens.container.SETEACL.signature,
+ "X-Bearer-Signature-Key": walletData.publicKey,
}).then((e) => {
setLoadingForm(false);
if (e.message) {
diff --git a/src/Components/TreeView/TreeView.js b/src/Components/TreeView/TreeView.js
index 45cd73e..f17f228 100644
--- a/src/Components/TreeView/TreeView.js
+++ b/src/Components/TreeView/TreeView.js
@@ -3,6 +3,7 @@ import {
Heading,
Section,
} from 'react-bulma-components';
+import { formatBytes } from '../../Functions/handle';
import api from '../../api';
const Tree = ({ children }) => {
@@ -11,7 +12,6 @@ const Tree = ({ children }) => {
const Branch = ({
params,
- formatBytes,
objectPath,
containerItem,
containerChildren,
@@ -19,11 +19,6 @@ const Branch = ({
onGetObjects,
containerIndex,
onModal,
- ContentTypeHeader,
- AuthorizationHeader,
- BearerOwnerIdHeader,
- BearerSignatureHeader,
- BearerSignatureKeyHeader,
}) => {
return (
@@ -31,7 +26,6 @@ const Branch = ({
)))}
{containerChildren[objectPath]['/'] && containerChildren[objectPath]['/'].map((objectItem, objectIndex) => (
))}
@@ -94,18 +76,11 @@ const Folder = ({ name, children }) => {
};
const File = ({
- params,
- formatBytes,
name,
containerItem,
objectItem,
walletData,
onModal,
- ContentTypeHeader,
- AuthorizationHeader,
- BearerOwnerIdHeader,
- BearerSignatureHeader,
- BearerSignatureKeyHeader,
}) => {
const [isOpen, setIsOpen] = useState(false);
const [objectDate, setObjectDate] = useState(null);
@@ -113,12 +88,8 @@ const File = ({
const handleToggle = e => {
setIsOpen(!isOpen);
if (!isOpen) {
- api('GET', `/objects/${containerItem.containerId}/${objectItem.address.objectId}?walletConnect=true`, {}, {
- [ContentTypeHeader]: "application/json",
- [AuthorizationHeader]: `Bearer ${walletData.tokens.object.token}`,
- [BearerOwnerIdHeader]: walletData.account.address,
- [BearerSignatureHeader]: walletData.tokens.object.signature,
- [BearerSignatureKeyHeader]: walletData.publicKey,
+ api('HEAD', `/objects/${containerItem.containerId}/by_id/${objectItem.address.objectId}`, {}, {
+ "Authorization": `Bearer ${walletData.tokens.object.bearer}`,
}).then((e) => {
setObjectDate(e);
});
@@ -171,12 +142,20 @@ const File = ({
Attributes
- {objectDate.attributes.map((attribute) => (
-
- {`${attribute.key}: `}
- {attribute.value}
-
- ))}
+ {objectDate ? (
+ <>
+ {Object.keys(objectDate.attributes).map((attributeKey) => (
+
+ {`${attributeKey}: `}
+ {objectDate.attributes[attributeKey]}
+
+ ))}
+
+ Content-Type:
+ {objectDate.contentType}
+
+ >
+ ) : '-'}
Manage
@@ -187,9 +166,8 @@ const File = ({
className="manage_icon"
onClick={() => {
onModal('loading');
- api('GET', `/get/${containerItem.containerId}/${objectItem.address.objectId}`, {}, {
- [ContentTypeHeader]: "application/json",
- [AuthorizationHeader]: `Bearer ${walletData.tokens.object.bearer}`,
+ api('GET', `/objects/${containerItem.containerId}/by_id/${objectItem.address.objectId}`, {}, {
+ "Authorization": `Bearer ${walletData.tokens.object.bearer}`,
}).then((data) => {
if (data.message) {
onModal('failed', data.message);
@@ -223,9 +201,8 @@ const File = ({
className="manage_icon"
onClick={() => {
onModal('loading');
- api('GET', `/get/${containerItem.containerId}/${objectItem.address.objectId}`, {}, {
- [ContentTypeHeader]: "application/json",
- [AuthorizationHeader]: `Bearer ${walletData.tokens.object.bearer}`,
+ api('GET', `/objects/${containerItem.containerId}/by_id/${objectItem.address.objectId}`, {}, {
+ "Authorization": `Bearer ${walletData.tokens.object.bearer}`,
}).then((data) => {
if (data.message) {
onModal('failed', data.message);
@@ -257,7 +234,9 @@ const File = ({
className="manage_icon"
onClick={() => {
onModal('loading');
- api('HEAD', `/get/${containerItem.containerId}/${objectItem.address.objectId}`).then((e) => {
+ api('HEAD', `/objects/${containerItem.containerId}/by_id/${objectItem.address.objectId}`, {}, {
+ "Authorization": `Bearer ${walletData.tokens.object.bearer}`,
+ }).then((e) => {
onModal('shareObjectLink', {
type: e === 200 ? 'public' : 'private',
containerId: containerItem.containerId,
@@ -304,19 +283,12 @@ Tree.Folder = Folder;
Tree.Branch = Branch;
export default function TreeView({
- params,
- formatBytes,
containerItem,
walletData,
onModal,
containerIndex,
onGetObjects,
objects,
- ContentTypeHeader,
- AuthorizationHeader,
- BearerOwnerIdHeader,
- BearerSignatureHeader,
- BearerSignatureKeyHeader,
}) {
return (
@@ -324,8 +296,6 @@ export default function TreeView({
{objectPath !== '/' && (
)}
{Object.keys(objects).length === (index + 1) && objects['/'] && objects['/'].map((objectItem, objectIndex) => (
))}
diff --git a/src/Functions/handle.js b/src/Functions/handle.js
index 754a03f..c711f72 100644
--- a/src/Functions/handle.js
+++ b/src/Functions/handle.js
@@ -73,3 +73,12 @@ export function formatForContainerName(attributes, containerId) {
}
return containerId;
}
+
+export function formatBytes(bytes) {
+ const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
+ let i = 0
+ for (i; bytes >= 1024; i += 1) {
+ bytes /= 1024;
+ }
+ return `${bytes === 0 ? bytes : bytes.toFixed(1)} ${units[i]}`;
+}
diff --git a/src/Getobject.js b/src/Getobject.js
index d226185..269bc8a 100644
--- a/src/Getobject.js
+++ b/src/Getobject.js
@@ -6,13 +6,11 @@ import {
Heading,
Box,
} from 'react-bulma-components';
+import { formatBytes } from './Functions/handle';
import api from './api';
const Getobject = ({
onModal,
- formatBytes,
- ContentTypeHeader,
- AuthorizationHeader,
}) => {
const [searchParams] = useSearchParams();
const [objectData, setObjectData] = useState(null);
@@ -26,10 +24,9 @@ const Getobject = ({
const payload = {};
if (token) {
- payload[ContentTypeHeader] = "application/json";
- payload[AuthorizationHeader] = `Bearer ${token}`;
+ payload["Authorization"] = `Bearer ${token}`;
}
- api('GET', `/objects/${containerId}/${objectId}?fullBearer=true`, {}, payload).then((e) => {
+ api('HEAD', `/objects/${containerId}/by_id/${objectId}`, {}, payload).then((e) => {
if (e.message) {
onModal('failed', e.message);
} else {
@@ -43,10 +40,9 @@ const Getobject = ({
const payload = {};
if (params.token) {
- payload[ContentTypeHeader] = "application/json";
- payload[AuthorizationHeader] = `Bearer ${params.token}`;
+ payload["Authorization"] = `Bearer ${params.token}`;
}
- api('GET', `/get/${params.containerId}/${params.objectId}`, {}, payload).then((data) => {
+ api('GET', `/objects/${params.containerId}/by_id/${params.objectId}`, {}, payload).then((data) => {
if (data.message) {
onModal('failed', data.message);
} else {
@@ -54,7 +50,7 @@ const Getobject = ({
document.body.appendChild(a);
const url = window.URL.createObjectURL(data.res);
a.href = url;
- a.download = objectData['x-attribute-filename'] ? objectData['x-attribute-filename'] : params.objectId;
+ a.download = objectData.filename ? objectData.filename : params.objectId;
a.target = '_blank';
a.click();
setTimeout(() => {
@@ -98,12 +94,20 @@ const Getobject = ({
Attributes
- {objectData ? objectData.attributes.map((attribute) => (
-
- {`${attribute.key}: `}
- {attribute.value}
-
- )) : '-'}
+ {objectData ? (
+ <>
+ {Object.keys(objectData.attributes).map((attributeKey) => (
+
+ {`${attributeKey}: `}
+ {objectData.attributes[attributeKey]}
+
+ ))}
+
+ Content-Type:
+ {objectData.contentType}
+
+ >
+ ) : '-'}
Manage
diff --git a/src/Profile.js b/src/Profile.js
index 7230c78..1d572f1 100644
--- a/src/Profile.js
+++ b/src/Profile.js
@@ -18,7 +18,6 @@ function formatAddress(address) {
const Profile = ({
params,
- formatBytes,
NeoFSContract,
activeNet,
walletData,
@@ -31,11 +30,6 @@ const Profile = ({
neolineN3,
isLoadContainers,
setLoadContainers,
- ContentTypeHeader,
- AuthorizationHeader,
- BearerOwnerIdHeader,
- BearerSignatureHeader,
- BearerSignatureKeyHeader,
onAuth,
}) => {
const [isLoading, setIsLoading] = useState(false);
@@ -288,8 +282,6 @@ const Profile = ({
{containers.map((containerItem, index) => (
))}
diff --git a/src/api.js b/src/api.js
index 57035fd..6bc8f34 100644
--- a/src/api.js
+++ b/src/api.js
@@ -5,9 +5,8 @@ async function serverRequest(method, url, params, headers) {
method,
headers,
}
- if (json['headers']['Content-Type'] === 'multipart/form-data') {
+ if (json['headers']['Content-Type']) {
json['body'] = params;
- delete json['headers']['Content-Type'];
} else if (Object.keys(params).length > 0) {
json['body'] = JSON.stringify(params);
json['headers']['Content-Type'] = 'application/json';
@@ -30,10 +29,22 @@ export default function api(method, url, params = {}, headers = {}) {
});
} else {
let res = response;
- if (method === 'GET' && url.indexOf(`/get/`) !== -1 && response.status === 200) {
+ if (method === 'GET' && url.indexOf(`/by_id/`) !== -1 && response.status === 200) {
res = await response.blob();
const header = response.headers.get('Content-Type');
resolve({ header, res, status: response.status });
+ } else if (method === 'HEAD' && url.indexOf(`/by_id/`) !== -1 && response.status === 200) {
+ const attributes = response.headers.get('x-attributes') ? JSON.parse(response.headers.get('x-attributes')) : {};
+ const res = {
+ 'containerId': response.headers.get('x-container-Id'),
+ 'objectId': response.headers.get('x-object-id'),
+ 'ownerId': response.headers.get('x-owner-Id'),
+ 'filename': attributes['FileName'],
+ 'attributes': attributes,
+ 'contentType': response.headers.get('Content-Type'),
+ 'objectSize': response.headers.get('Content-Length') ? response.headers.get('Content-Length') : response.headers.get('x-neofs-payload-length'),
+ }
+ resolve(res);
} else if (method === 'HEAD') {
resolve(response.status);
} else if (response.status === 413) {