mirror of
https://github.com/strapi/strapi.git
synced 2025-09-18 21:08:54 +00:00
update options format
This commit is contained in:
parent
71e8285e27
commit
6254b58d0e
@ -9,18 +9,30 @@ import { IDestinationProvider, ProviderType, Stream } from '../../types';
|
|||||||
// import { encrypt } from '../encryption';
|
// import { encrypt } from '../encryption';
|
||||||
|
|
||||||
export interface ILocalFileDestinationProviderOptions {
|
export interface ILocalFileDestinationProviderOptions {
|
||||||
backupFilePath: string;
|
|
||||||
|
|
||||||
// Encryption
|
// Encryption
|
||||||
encrypted?: boolean;
|
encryption: {
|
||||||
encryptionKey?: string;
|
enabled: boolean;
|
||||||
|
key: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Compressions
|
||||||
|
compression: {
|
||||||
|
enabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
// File
|
||||||
|
file: {
|
||||||
|
path: string;
|
||||||
|
maxSize?: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createLocalFileDestinationProvider = (options: ILocalFileDestinationProviderOptions) => {
|
export const createLocalFileDestinationProvider = (
|
||||||
|
options: ILocalFileDestinationProviderOptions
|
||||||
|
) => {
|
||||||
return new LocalFileDestinationProvider(options);
|
return new LocalFileDestinationProvider(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class LocalFileDestinationProvider implements IDestinationProvider {
|
class LocalFileDestinationProvider implements IDestinationProvider {
|
||||||
name: string = 'destination::local-file';
|
name: string = 'destination::local-file';
|
||||||
type: ProviderType = 'destination';
|
type: ProviderType = 'destination';
|
||||||
@ -31,7 +43,7 @@ class LocalFileDestinationProvider implements IDestinationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(): void | Promise<void> {
|
bootstrap(): void | Promise<void> {
|
||||||
const rootDir = this.options.backupFilePath;
|
const rootDir = this.options.file.path;
|
||||||
const dirExists = fs.existsSync(rootDir);
|
const dirExists = fs.existsSync(rootDir);
|
||||||
|
|
||||||
if (dirExists) {
|
if (dirExists) {
|
||||||
@ -46,7 +58,7 @@ class LocalFileDestinationProvider implements IDestinationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rollback(): void | Promise<void> {
|
rollback(): void | Promise<void> {
|
||||||
fs.rmSync(this.options.backupFilePath, { force: true, recursive: true });
|
fs.rmSync(this.options.file.path, { force: true, recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
getMetadata() {
|
getMetadata() {
|
||||||
@ -54,23 +66,10 @@ class LocalFileDestinationProvider implements IDestinationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getEntitiesStream(): Duplex {
|
getEntitiesStream(): Duplex {
|
||||||
const options = {
|
|
||||||
encryption: {
|
|
||||||
enabled: true,
|
|
||||||
key: 'Hello World!',
|
|
||||||
},
|
|
||||||
compression: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
file: {
|
|
||||||
maxSize: 100000,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const filePathFactory = (fileIndex: number = 0) => {
|
const filePathFactory = (fileIndex: number = 0) => {
|
||||||
return path.join(
|
return path.join(
|
||||||
// Backup path
|
// Backup path
|
||||||
this.options.backupFilePath,
|
this.options.file.path,
|
||||||
// "entities/" directory
|
// "entities/" directory
|
||||||
'entities',
|
'entities',
|
||||||
// "entities_00000.jsonl" file
|
// "entities_00000.jsonl" file
|
||||||
@ -84,7 +83,7 @@ class LocalFileDestinationProvider implements IDestinationProvider {
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Compression
|
// Compression
|
||||||
if (options.compression?.enabled) {
|
if (this.options.compression?.enabled) {
|
||||||
streams.push(zip.createGzip());
|
streams.push(zip.createGzip());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +93,7 @@ class LocalFileDestinationProvider implements IDestinationProvider {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// FS write stream
|
// FS write stream
|
||||||
streams.push(createMultiFilesWriteStream(filePathFactory, options.file?.maxSize));
|
streams.push(createMultiFilesWriteStream(filePathFactory, this.options.file.maxSize));
|
||||||
|
|
||||||
return chain(streams);
|
return chain(streams);
|
||||||
}
|
}
|
||||||
@ -116,7 +115,7 @@ class LocalFileDestinationProvider implements IDestinationProvider {
|
|||||||
const filePathFactory = (fileIndex: number = 0) => {
|
const filePathFactory = (fileIndex: number = 0) => {
|
||||||
return path.join(
|
return path.join(
|
||||||
// Backup path
|
// Backup path
|
||||||
this.options.backupFilePath,
|
this.options.file.path,
|
||||||
// "links/" directory
|
// "links/" directory
|
||||||
'links',
|
'links',
|
||||||
// "links_00000.jsonl" file
|
// "links_00000.jsonl" file
|
||||||
@ -180,7 +179,7 @@ const createMultiFilesWriteStream = (
|
|||||||
|
|
||||||
// Check that by adding this new chunk of data, we
|
// Check that by adding this new chunk of data, we
|
||||||
// are not going to reach the maximum file size.
|
// are not going to reach the maximum file size.
|
||||||
if (maxSize && (fileSize + chunk.length > maxSize)) {
|
if (maxSize && fileSize + chunk.length > maxSize) {
|
||||||
// Update the counters' value
|
// Update the counters' value
|
||||||
fileIndex++;
|
fileIndex++;
|
||||||
fileSize = 0;
|
fileSize = 0;
|
||||||
|
@ -12,21 +12,29 @@ const getDefaultExportBackupName = () => `strapi-backup`;
|
|||||||
const logger = console;
|
const logger = console;
|
||||||
|
|
||||||
module.exports = async (args) => {
|
module.exports = async (args) => {
|
||||||
if (!args.output) {
|
|
||||||
Object.assign(args, { output: getDefaultExportBackupName() });
|
|
||||||
}
|
|
||||||
|
|
||||||
// From strapi
|
// From strapi
|
||||||
const source = createLocalStrapiSourceProvider({
|
const inputOptions = {
|
||||||
getStrapi() {
|
getStrapi() {
|
||||||
return strapi().load();
|
return strapi().load();
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
const source = createLocalStrapiSourceProvider(inputOptions);
|
||||||
|
|
||||||
// To file
|
// To file
|
||||||
const destination = createLocalFileDestinationProvider({
|
const outputOptions = {
|
||||||
backupFilePath: args.output,
|
file: {
|
||||||
});
|
path: args.output || getDefaultExportBackupName(),
|
||||||
|
},
|
||||||
|
encryption: {
|
||||||
|
enabled: args.encrypt,
|
||||||
|
key: args.key,
|
||||||
|
},
|
||||||
|
compression: {
|
||||||
|
enabled: args.compress,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const destination = createLocalFileDestinationProvider(outputOptions);
|
||||||
|
|
||||||
// create transfer engine
|
// create transfer engine
|
||||||
const engine = createTransferEngine(source, destination, {
|
const engine = createTransferEngine(source, destination, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user