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;
};
getEncodeUrl = (url) => {
const tmp = url.split('/');
return tmp.map((t) => encodeURIComponent(t)).join('/');
};
get resources() {
return [
{
@ -44,19 +49,19 @@ class SwiftClient extends Base {
{
key: 'create',
generate: (name) => {
return this.request.put(encodeURIComponent(name));
return this.request.put(this.getEncodeUrl(name));
},
},
{
key: 'showMetadata',
generate: (name) => {
return this.request.head(encodeURIComponent(name));
return this.request.head(this.getEncodeUrl(name));
},
},
{
key: 'updateMetadata',
generate: (name, headers) => {
return this.request.post(encodeURIComponent(name), null, null, {
return this.request.post(this.getEncodeUrl(name), null, null, {
headers,
});
},
@ -64,27 +69,21 @@ class SwiftClient extends Base {
{
key: 'uploadFile',
generate: (container, name, content, conf) => {
const url = `${encodeURIComponent(
container
)}/${encodeURIComponent(name)}`;
const url = this.getEncodeUrl(`${container}/${name}`);
return this.request.put(url, content, null, conf);
},
},
{
key: 'createFolder',
generate: (container, name) => {
const url = `${encodeURIComponent(
container
)}/${encodeURIComponent(name)}`;
const url = this.getEncodeUrl(`${container}/${name}`);
return this.request.put(url);
},
},
{
key: 'showObjectMetadata',
generate: (container, objectName) => {
const url = `${encodeURIComponent(
container
)}/${encodeURIComponent(objectName)}`;
const url = this.getEncodeUrl(`${container}/${objectName}`);
return this.request.head(url);
},
},
@ -93,7 +92,7 @@ class SwiftClient extends Base {
generate: (fromContaier, fromName, toContainer, toName) => {
const url = `${fromContaier}/${fromName}`;
const headers = {
Destination: encodeURIComponent(`${toContainer}/${toName}`),
Destination: this.getEncodeUrl(`${toContainer}/${toName}`),
};
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 Base from 'containers/List';
import globalObjectStore, { ObjectStore } from 'stores/swift/object';
import { toLocalTimeFilter, bytesFitler } from 'utils/index';
import { bytesFitler } from 'utils/index';
import { allCanReadPolicy } from 'resources/policy';
import { toJS } from 'mobx';
import { isEqual } from 'lodash';
@ -182,7 +182,6 @@ export default class ContainerObject extends Base {
{
title: t('Name'),
dataIndex: 'shortName',
stringify: (name, record) => name || record.id,
render: (name, record) => {
const { type, container } = record;
if (type === 'folder') {
@ -212,7 +211,6 @@ export default class ContainerObject extends Base {
dataIndex: 'last_modified',
isHideable: true,
valueRender: 'sinceTime',
stringify: (value) => toLocalTimeFilter(value),
},
{
title: t('Detail Info'),

View File

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

View File

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

View File

@ -67,50 +67,38 @@ export class ObjectStore extends Base {
get paramsFunc() {
return (params) => {
const { current, container, folder, search = '', ...rest } = params;
return {
path: `${folder}${search}`,
delimiter: `/`,
const { current, container, folder, search = '', path, ...rest } = params;
const realPath = path || (folder || search ? `${folder}${search}` : '');
const newParams = {
format: 'json',
...rest,
};
if (realPath) {
newParams.path = realPath;
} else {
newParams.delimiter = '/';
}
return newParams;
};
}
getShortName = (name, folder) => name.substring((folder || '').length);
getItemType = (it) => {
if (it.subdir) {
return 'folder';
}
const { name } = it;
if (name[name.length - 1] === '/') {
return 'folder';
}
return 'file';
getShortName = (item, folder) => {
const { name, subdir } = item;
const lName = subdir || name;
return lName.substring((folder || '').length) || lName;
};
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) {
return 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);
return this.updateData(items);
}
async detailFetchByClient(resourceParams) {
@ -141,7 +129,8 @@ export class ObjectStore extends Base {
folder,
type: this.getItemType(it),
hasCopy,
shortName: it.name && this.getShortName(it.name, folder),
shortName: this.getShortName(it, folder),
name: it.subdir || it.name,
};
});
};