Merge pull request #7917 from mertcb/migrate/oss
This commit is contained in:
@@ -24,7 +24,11 @@ import { SwiftClient } from '@trendyol-js/openstack-swift-sdk';
|
||||
import { NotFound } from '@trendyol-js/openstack-swift-sdk/lib/types';
|
||||
import { Stream, Readable } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
import { getFileTreeRecursively, getHeadersForFileExtension } from './helpers';
|
||||
import {
|
||||
getFileTreeRecursively,
|
||||
getHeadersForFileExtension,
|
||||
lowerCaseEntityTripletInStoragePath,
|
||||
} from './helpers';
|
||||
import {
|
||||
PublisherBase,
|
||||
PublishRequest,
|
||||
@@ -289,4 +293,67 @@ export class OpenStackSwiftPublish implements PublisherBase {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async migrateDocsCase({
|
||||
removeOriginal = false,
|
||||
concurrency = 25,
|
||||
}): Promise<void> {
|
||||
// Iterate through every file in the root of the publisher.
|
||||
const allObjects = await this.getAllObjectsFromContainer();
|
||||
const limiter = createLimiter(concurrency);
|
||||
await Promise.all(
|
||||
allObjects.map(f =>
|
||||
limiter(async file => {
|
||||
let newPath;
|
||||
try {
|
||||
newPath = lowerCaseEntityTripletInStoragePath(file);
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
this.logger.warn(e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// If all parts are already lowercase, ignore.
|
||||
if (file === newPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.logger.verbose(`Migrating ${file} to ${newPath}`);
|
||||
await this.storageClient.copy(
|
||||
this.containerName,
|
||||
file,
|
||||
this.containerName,
|
||||
newPath,
|
||||
);
|
||||
if (removeOriginal) {
|
||||
await this.storageClient.delete(this.containerName, file);
|
||||
}
|
||||
} catch (e) {
|
||||
assertError(e);
|
||||
this.logger.warn(`Unable to migrate ${file}: ${e.message}`);
|
||||
}
|
||||
}, f),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all object keys from the configured container.
|
||||
*/
|
||||
protected async getAllObjectsFromContainer(
|
||||
{ prefix } = { prefix: '' },
|
||||
): Promise<string[]> {
|
||||
let objects: string[] = [];
|
||||
const OSS_MAX_LIMIT = Math.pow(2, 31) - 1;
|
||||
|
||||
const allObjects = await this.storageClient.list(
|
||||
this.containerName,
|
||||
prefix,
|
||||
OSS_MAX_LIMIT,
|
||||
);
|
||||
objects = allObjects.map((object: any) => object.name);
|
||||
|
||||
return objects;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user