Merge "feat: Support ceph rgw swift"

This commit is contained in:
Zuul 2021-12-22 07:20:40 +00:00 committed by Gerrit Code Review
commit 5b288e6daa
5 changed files with 47 additions and 54 deletions

View File

@ -29,6 +29,11 @@ class SwiftClient extends Base {
return url ? `${prefix}/${url}` : prefix; return url ? `${prefix}/${url}` : prefix;
}; };
getEncodeUrl = (url) => {
const tmp = url.split('/');
return tmp.map((t) => encodeURIComponent(t)).join('/');
};
get resources() { get resources() {
return [ return [
{ {
@ -44,19 +49,19 @@ class SwiftClient extends Base {
{ {
key: 'create', key: 'create',
generate: (name) => { generate: (name) => {
return this.request.put(encodeURIComponent(name)); return this.request.put(this.getEncodeUrl(name));
}, },
}, },
{ {
key: 'showMetadata', key: 'showMetadata',
generate: (name) => { generate: (name) => {
return this.request.head(encodeURIComponent(name)); return this.request.head(this.getEncodeUrl(name));
}, },
}, },
{ {
key: 'updateMetadata', key: 'updateMetadata',
generate: (name, headers) => { generate: (name, headers) => {
return this.request.post(encodeURIComponent(name), null, null, { return this.request.post(this.getEncodeUrl(name), null, null, {
headers, headers,
}); });
}, },
@ -64,27 +69,21 @@ class SwiftClient extends Base {
{ {
key: 'uploadFile', key: 'uploadFile',
generate: (container, name, content, conf) => { generate: (container, name, content, conf) => {
const url = `${encodeURIComponent( const url = this.getEncodeUrl(`${container}/${name}`);
container
)}/${encodeURIComponent(name)}`;
return this.request.put(url, content, null, conf); return this.request.put(url, content, null, conf);
}, },
}, },
{ {
key: 'createFolder', key: 'createFolder',
generate: (container, name) => { generate: (container, name) => {
const url = `${encodeURIComponent( const url = this.getEncodeUrl(`${container}/${name}`);
container
)}/${encodeURIComponent(name)}`;
return this.request.put(url); return this.request.put(url);
}, },
}, },
{ {
key: 'showObjectMetadata', key: 'showObjectMetadata',
generate: (container, objectName) => { generate: (container, objectName) => {
const url = `${encodeURIComponent( const url = this.getEncodeUrl(`${container}/${objectName}`);
container
)}/${encodeURIComponent(objectName)}`;
return this.request.head(url); return this.request.head(url);
}, },
}, },
@ -93,7 +92,7 @@ class SwiftClient extends Base {
generate: (fromContaier, fromName, toContainer, toName) => { generate: (fromContaier, fromName, toContainer, toName) => {
const url = `${fromContaier}/${fromName}`; const url = `${fromContaier}/${fromName}`;
const headers = { const headers = {
Destination: encodeURIComponent(`${toContainer}/${toName}`), Destination: this.getEncodeUrl(`${toContainer}/${toName}`),
}; };
return this.request.copy(url, null, { headers }); return this.request.copy(url, null, { headers });
}, },

View File

@ -17,7 +17,7 @@ import { observer, inject } from 'mobx-react';
import { Popover, Col, Row, Skeleton } from 'antd'; import { Popover, Col, Row, Skeleton } from 'antd';
import Base from 'containers/List'; import Base from 'containers/List';
import globalObjectStore, { ObjectStore } from 'stores/swift/object'; import globalObjectStore, { ObjectStore } from 'stores/swift/object';
import { toLocalTimeFilter, bytesFitler } from 'utils/index'; import { bytesFitler } from 'utils/index';
import { allCanReadPolicy } from 'resources/policy'; import { allCanReadPolicy } from 'resources/policy';
import { toJS } from 'mobx'; import { toJS } from 'mobx';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
@ -182,7 +182,6 @@ export default class ContainerObject extends Base {
{ {
title: t('Name'), title: t('Name'),
dataIndex: 'shortName', dataIndex: 'shortName',
stringify: (name, record) => name || record.id,
render: (name, record) => { render: (name, record) => {
const { type, container } = record; const { type, container } = record;
if (type === 'folder') { if (type === 'folder') {
@ -212,7 +211,6 @@ export default class ContainerObject extends Base {
dataIndex: 'last_modified', dataIndex: 'last_modified',
isHideable: true, isHideable: true,
valueRender: 'sinceTime', valueRender: 'sinceTime',
stringify: (value) => toLocalTimeFilter(value),
}, },
{ {
title: t('Detail Info'), title: t('Detail Info'),

View File

@ -17,7 +17,7 @@ import { observer, inject } from 'mobx-react';
import { Popover, Col, Row, Skeleton } from 'antd'; import { Popover, Col, Row, Skeleton } from 'antd';
import Base from 'containers/List'; import Base from 'containers/List';
import globalContainerStore, { ContainerStore } from 'stores/swift/container'; import globalContainerStore, { ContainerStore } from 'stores/swift/container';
import { toLocalTimeFilter, bytesFitler } from 'utils/index'; import { bytesFitler } from 'utils/index';
import { allCanChangePolicy } from 'resources/policy'; import { allCanChangePolicy } from 'resources/policy';
import { getStrFromTimestamp } from 'utils/time'; import { getStrFromTimestamp } from 'utils/time';
import { swiftEndpoint } from 'client/client/constants'; import { swiftEndpoint } from 'client/client/constants';
@ -130,7 +130,6 @@ export default class Container extends Base {
this.getLinkRender('containerDetail', name || record.id, { this.getLinkRender('containerDetail', name || record.id, {
id: record.id, id: record.id,
}), }),
stringify: (name, record) => name || record.id,
}, },
{ {
title: t('Size'), title: t('Size'),
@ -142,7 +141,6 @@ export default class Container extends Base {
dataIndex: 'last_modified', dataIndex: 'last_modified',
isHideable: true, isHideable: true,
valueRender: 'sinceTime', valueRender: 'sinceTime',
stringify: (value) => toLocalTimeFilter(value),
}, },
{ {
title: t('Detail Info'), title: t('Detail Info'),

View File

@ -25,6 +25,15 @@ export class ContainerStore extends Base {
return ''; return '';
} }
get paramsFunc() {
return (params) => {
return {
...params,
format: 'json',
};
};
}
get mapper() { get mapper() {
return (data) => ({ return (data) => ({
...data, ...data,

View File

@ -67,50 +67,38 @@ export class ObjectStore extends Base {
get paramsFunc() { get paramsFunc() {
return (params) => { return (params) => {
const { current, container, folder, search = '', ...rest } = params; const { current, container, folder, search = '', path, ...rest } = params;
return { const realPath = path || (folder || search ? `${folder}${search}` : '');
path: `${folder}${search}`, const newParams = {
delimiter: `/`, format: 'json',
...rest, ...rest,
}; };
if (realPath) {
newParams.path = realPath;
} else {
newParams.delimiter = '/';
}
return newParams;
}; };
} }
getShortName = (name, folder) => name.substring((folder || '').length); getShortName = (item, folder) => {
const { name, subdir } = item;
getItemType = (it) => { const lName = subdir || name;
if (it.subdir) { return lName.substring((folder || '').length) || lName;
return 'folder';
}
const { name } = it;
if (name[name.length - 1] === '/') {
return 'folder';
}
return 'file';
}; };
async listDidFetch(items, _, filters) { isFolder = (item) => item.subdir || item.name.slice(-1) === '/';
getItemType = (it) => {
return this.isFolder(it) ? 'folder' : 'file';
};
async listDidFetch(items) {
if (items.length === 0) { if (items.length === 0) {
return items; return items;
} }
return this.updateData(items);
const { container } = filters;
const needFetch = items.some((it) => it.subdir);
if (!needFetch) {
return this.updateData(items);
}
const result = await this.client.list(container);
const newItems = items.map((it) => {
if (it.subdir) {
const item = result.find((r) => r.name === it.subdir) || {};
return {
...it,
...item,
};
}
return { ...it };
});
return this.updateData(newItems);
} }
async detailFetchByClient(resourceParams) { async detailFetchByClient(resourceParams) {
@ -141,7 +129,8 @@ export class ObjectStore extends Base {
folder, folder,
type: this.getItemType(it), type: this.getItemType(it),
hasCopy, hasCopy,
shortName: it.name && this.getShortName(it.name, folder), shortName: this.getShortName(it, folder),
name: it.subdir || it.name,
}; };
}); });
}; };