refactor: Replace deprecated substr with substring (#8644)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
|
|
||||||
const version = parseFloat(process.version.substr(1));
|
const version = parseFloat(process.version.substring(1));
|
||||||
const minimum = parseFloat(pkg.engines.node.match(/\d+/g).join('.'));
|
const minimum = parseFloat(pkg.engines.node.match(/\d+/g).join('.'));
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ export class GridFSBucketAdapter extends FilesAdapter {
|
|||||||
this._algorithm = 'aes-256-gcm';
|
this._algorithm = 'aes-256-gcm';
|
||||||
this._encryptionKey =
|
this._encryptionKey =
|
||||||
encryptionKey !== undefined
|
encryptionKey !== undefined
|
||||||
? crypto.createHash('sha256').update(String(encryptionKey)).digest('base64').substr(0, 32)
|
? crypto
|
||||||
|
.createHash('sha256')
|
||||||
|
.update(String(encryptionKey))
|
||||||
|
.digest('base64')
|
||||||
|
.substring(0, 32)
|
||||||
: null;
|
: null;
|
||||||
const defaultMongoOptions = {
|
const defaultMongoOptions = {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
@@ -138,8 +142,8 @@ export class GridFSBucketAdapter extends FilesAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async rotateEncryptionKey(options = {}) {
|
async rotateEncryptionKey(options = {}) {
|
||||||
var fileNames = [];
|
let fileNames = [];
|
||||||
var oldKeyFileAdapter = {};
|
let oldKeyFileAdapter = {};
|
||||||
const bucket = await this._getBucket();
|
const bucket = await this._getBucket();
|
||||||
if (options.oldKey !== undefined) {
|
if (options.oldKey !== undefined) {
|
||||||
oldKeyFileAdapter = new GridFSBucketAdapter(
|
oldKeyFileAdapter = new GridFSBucketAdapter(
|
||||||
@@ -158,51 +162,22 @@ export class GridFSBucketAdapter extends FilesAdapter {
|
|||||||
fileNames.push(file.filename);
|
fileNames.push(file.filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return new Promise(resolve => {
|
let fileNamesNotRotated = fileNames;
|
||||||
var fileNamesNotRotated = fileNames;
|
const fileNamesRotated = [];
|
||||||
var fileNamesRotated = [];
|
for (const fileName of fileNames) {
|
||||||
var fileNameTotal = fileNames.length;
|
try {
|
||||||
var fileNameIndex = 0;
|
const plainTextData = await oldKeyFileAdapter.getFileData(fileName);
|
||||||
fileNames.forEach(fileName => {
|
// Overwrite file with data encrypted with new key
|
||||||
oldKeyFileAdapter
|
await this.createFile(fileName, plainTextData);
|
||||||
.getFileData(fileName)
|
|
||||||
.then(plainTextData => {
|
|
||||||
//Overwrite file with data encrypted with new key
|
|
||||||
this.createFile(fileName, plainTextData)
|
|
||||||
.then(() => {
|
|
||||||
fileNamesRotated.push(fileName);
|
fileNamesRotated.push(fileName);
|
||||||
fileNamesNotRotated = fileNamesNotRotated.filter(function (value) {
|
fileNamesNotRotated = fileNamesNotRotated.filter(function (value) {
|
||||||
return value !== fileName;
|
return value !== fileName;
|
||||||
});
|
});
|
||||||
fileNameIndex += 1;
|
} catch (err) {
|
||||||
if (fileNameIndex == fileNameTotal) {
|
continue;
|
||||||
resolve({
|
|
||||||
rotated: fileNamesRotated,
|
|
||||||
notRotated: fileNamesNotRotated,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
fileNameIndex += 1;
|
|
||||||
if (fileNameIndex == fileNameTotal) {
|
|
||||||
resolve({
|
|
||||||
rotated: fileNamesRotated,
|
|
||||||
notRotated: fileNamesNotRotated,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
return { rotated: fileNamesRotated, notRotated: fileNamesNotRotated };
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
fileNameIndex += 1;
|
|
||||||
if (fileNameIndex == fileNameTotal) {
|
|
||||||
resolve({
|
|
||||||
rotated: fileNamesRotated,
|
|
||||||
notRotated: fileNamesNotRotated,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileLocation(config, filename) {
|
getFileLocation(config, filename) {
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ const transformAggregateField = fieldName => {
|
|||||||
if (fieldName === '$_updated_at') {
|
if (fieldName === '$_updated_at') {
|
||||||
return 'updatedAt';
|
return 'updatedAt';
|
||||||
}
|
}
|
||||||
return fieldName.substr(1);
|
return fieldName.substring(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateKeys = object => {
|
const validateKeys = object => {
|
||||||
@@ -1921,14 +1921,14 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (object[fieldName] && schema.fields[fieldName].type === 'Polygon') {
|
if (object[fieldName] && schema.fields[fieldName].type === 'Polygon') {
|
||||||
let coords = object[fieldName];
|
let coords = new String(object[fieldName]);
|
||||||
coords = coords.substr(2, coords.length - 4).split('),(');
|
coords = coords.substring(2, coords.length - 2).split('),(');
|
||||||
coords = coords.map(point => {
|
const updatedCoords = coords.map(point => {
|
||||||
return [parseFloat(point.split(',')[1]), parseFloat(point.split(',')[0])];
|
return [parseFloat(point.split(',')[1]), parseFloat(point.split(',')[0])];
|
||||||
});
|
});
|
||||||
object[fieldName] = {
|
object[fieldName] = {
|
||||||
__type: 'Polygon',
|
__type: 'Polygon',
|
||||||
coordinates: coords,
|
coordinates: updatedCoords,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (object[fieldName] && schema.fields[fieldName].type === 'File') {
|
if (object[fieldName] && schema.fields[fieldName].type === 'File') {
|
||||||
@@ -2634,7 +2634,7 @@ function literalizeRegexPart(s: string) {
|
|||||||
const result1: any = s.match(matcher1);
|
const result1: any = s.match(matcher1);
|
||||||
if (result1 && result1.length > 1 && result1.index > -1) {
|
if (result1 && result1.length > 1 && result1.index > -1) {
|
||||||
// process regex that has a beginning and an end specified for the literal text
|
// process regex that has a beginning and an end specified for the literal text
|
||||||
const prefix = s.substr(0, result1.index);
|
const prefix = s.substring(0, result1.index);
|
||||||
const remaining = result1[1];
|
const remaining = result1[1];
|
||||||
|
|
||||||
return literalizeRegexPart(prefix) + createLiteralRegex(remaining);
|
return literalizeRegexPart(prefix) + createLiteralRegex(remaining);
|
||||||
@@ -2644,7 +2644,7 @@ function literalizeRegexPart(s: string) {
|
|||||||
const matcher2 = /\\Q((?!\\E).*)$/;
|
const matcher2 = /\\Q((?!\\E).*)$/;
|
||||||
const result2: any = s.match(matcher2);
|
const result2: any = s.match(matcher2);
|
||||||
if (result2 && result2.length > 1 && result2.index > -1) {
|
if (result2 && result2.length > 1 && result2.index > -1) {
|
||||||
const prefix = s.substr(0, result2.index);
|
const prefix = s.substring(0, result2.index);
|
||||||
const remaining = result2[1];
|
const remaining = result2[1];
|
||||||
|
|
||||||
return literalizeRegexPart(prefix) + createLiteralRegex(remaining);
|
return literalizeRegexPart(prefix) + createLiteralRegex(remaining);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function removeTrailingSlash(str) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
if (str.endsWith('/')) {
|
if (str.endsWith('/')) {
|
||||||
str = str.substr(0, str.length - 1);
|
str = str.substring(0, str.length - 1);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user