Skip to content

refactor: Lint project and remove deprecated code #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2fb584f
add babel and linter
cbaker6 Jun 18, 2023
5f41b16
fix lint errors
cbaker6 Jun 18, 2023
0ef115f
add lint check to CI
cbaker6 Jun 18, 2023
347f7fb
update ci files
cbaker6 Jun 18, 2023
e1a7ab8
Update ci.yml
cbaker6 Jun 18, 2023
8cee9d3
Update ci.yml
cbaker6 Jun 18, 2023
d6a4461
use lockfile version 1
cbaker6 Jun 18, 2023
476b543
Merge branch 'lint' of https://github.com/cbaker6/parse-server-fs-ada…
cbaker6 Jun 18, 2023
4ecd71b
update to async/await
cbaker6 Jun 18, 2023
2e88d02
replace deprecated substr with substring
cbaker6 Jun 18, 2023
e8a84a1
Update ci to use node version for name
cbaker6 Jun 18, 2023
6bc19cc
fix ci cache keys
cbaker6 Jun 18, 2023
f714056
let dependabot keep actions up-to-date
cbaker6 Jun 18, 2023
f5390f5
Merge branch 'lint' of https://github.com/cbaker6/parse-server-fs-ada…
cbaker6 Jun 18, 2023
cb711af
Merge branch 'main' into lint
cbaker6 Jun 18, 2023
9f42fc2
Update ci.yml
cbaker6 Jun 18, 2023
7a4bb5f
update semantic to latest versions
cbaker6 Jun 18, 2023
321a9dc
update to lockfile v2 to match server
cbaker6 Jun 18, 2023
03c8899
Update release-automated.yml
cbaker6 Jun 18, 2023
09fc919
move concurrency
cbaker6 Jun 19, 2023
f166c7b
fix for loop
cbaker6 Jun 19, 2023
7f535b2
Merge branch 'lint' of https://github.com/cbaker6/parse-server-fs-ada…
cbaker6 Jun 19, 2023
7f2d7c6
Update .github/dependabot.yml
mtrezza Jun 19, 2023
e2d95f4
remove direct dev dep of babel
cbaker6 Jun 19, 2023
977cbfc
Merge branch 'lint' of https://github.com/cbaker6/parse-server-fs-ada…
cbaker6 Jun 19, 2023
99bd48a
remove babel folder from .gitignore
cbaker6 Jun 19, 2023
bedb96f
temp change to config
cbaker6 Jun 20, 2023
8440606
revert
cbaker6 Jun 20, 2023
e2de28e
Merge branch 'main' into lint
cbaker6 Jan 22, 2024
f29d8f6
update package lock file
cbaker6 Jan 22, 2024
efe0774
nit
cbaker6 Jan 22, 2024
6cde934
Update ci.yml
cbaker6 Jan 22, 2024
dc667eb
revert semantic to server versions
cbaker6 Jan 22, 2024
232eaf4
Merge branch 'lint' of https://github.com/cbaker6/parse-server-fs-ada…
cbaker6 Jan 22, 2024
945746b
Update ci.yml
cbaker6 Jan 22, 2024
e64c635
Update ci.yml
cbaker6 Jan 22, 2024
ceaff76
fix package lock file
cbaker6 Jan 22, 2024
39eecef
remove eslint
cbaker6 Jan 22, 2024
ac2daa8
Update ci.yml
cbaker6 Jan 22, 2024
ba220d0
remove linter
cbaker6 Jan 22, 2024
20bfbab
finish removing lint
cbaker6 Jan 22, 2024
96d4c58
remove spec lint
cbaker6 Jan 22, 2024
6175463
fix tests
cbaker6 Jan 22, 2024
eb5670b
fix tests
cbaker6 Jan 22, 2024
01c7283
remove node 19 test
cbaker6 Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "refactor"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix: "refactor"
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ on:
- '**'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '16', '18' ]
name: Node ${{ matrix.node }}
runs-on: ubuntu-latest
timeout-minutes: 30
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERAGE_OPTION: ./node_modules/.bin/nyc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm ci
- name: Install dependencies
run: npm ci
- run: npm run coverage
- run: bash <(curl -s https://codecov.io/bash)
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
2 changes: 1 addition & 1 deletion .github/workflows/release-automated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Setup Node
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ node_modules

# Optional REPL history
.node_repl_history

# visual studio code
.vscode

# cache folder
.cache
.eslintcache

# Mac DS_Store files
.DS_Store
122 changes: 51 additions & 71 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
// Stores files in local file system
// Requires write access to the server's file system.

var fs = require('fs');
var path = require('path');
var pathSep = require('path').sep;
const fs = require('fs');
const path = require('path');
const pathSep = require('path').sep;
const crypto = require("crypto");
const algorithm = 'aes-256-gcm';

function FileSystemAdapter(options) {
options = options || {};
this._encryptionKey = null;

if (options.encryptionKey !== undefined){
this._encryptionKey = crypto.createHash('sha256').update(String(options.encryptionKey)).digest('base64').substr(0, 32);
if (options.encryptionKey !== undefined) {
this._encryptionKey = crypto.createHash('sha256').update(String(options.encryptionKey)).digest('base64').substring(0, 32);
}
let filesSubDirectory = options.filesSubDirectory || '';
const filesSubDirectory = options.filesSubDirectory || '';
this._filesDir = filesSubDirectory;
this._mkdir(this._getApplicationDir());
if (!this._applicationDirExist()) {
Expand All @@ -26,11 +26,11 @@ function FileSystemAdapter(options) {
}

FileSystemAdapter.prototype.createFile = function(filename, data) {
let filepath = this._getLocalFilePath(filename);
const filepath = this._getLocalFilePath(filename);
const stream = fs.createWriteStream(filepath);
return new Promise((resolve, reject) => {
try{
if(this._encryptionKey !== null){
try {
if (this._encryptionKey !== null) {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(
algorithm,
Expand All @@ -48,21 +48,21 @@ FileSystemAdapter.prototype.createFile = function(filename, data) {
stream.on('finish', function() {
resolve(data);
});
}else{
} else {
stream.write(data);
stream.end();
stream.on('finish', function() {
resolve(data);
});
}
}catch(err){
}
} catch(err) {
return reject(err);
}
});
}

FileSystemAdapter.prototype.deleteFile = function(filename) {
let filepath = this._getLocalFilePath(filename);
const filepath = this._getLocalFilePath(filename);
const chunks = [];
const stream = fs.createReadStream(filepath);
return new Promise((resolve, reject) => {
Expand All @@ -86,7 +86,7 @@ FileSystemAdapter.prototype.deleteFile = function(filename) {
}

FileSystemAdapter.prototype.getFileData = function(filename) {
let filepath = this._getLocalFilePath(filename);
const filepath = this._getLocalFilePath(filename);
const stream = fs.createReadStream(filepath);
stream.read();
return new Promise((resolve, reject) => {
Expand All @@ -96,18 +96,18 @@ FileSystemAdapter.prototype.getFileData = function(filename) {
});
stream.on('end', () => {
const data = Buffer.concat(chunks);
if(this._encryptionKey !== null){
if (this._encryptionKey !== null) {
const authTagLocation = data.length - 16;
const ivLocation = data.length - 32;
const authTag = data.slice(authTagLocation);
const iv = data.slice(ivLocation,authTagLocation);
const encrypted = data.slice(0,ivLocation);
try{
try {
const decipher = crypto.createDecipheriv(algorithm, this._encryptionKey, iv);
decipher.setAuthTag(authTag);
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
const decrypted = Buffer.concat([ decipher.update(encrypted), decipher.final() ]);
return resolve(decrypted);
}catch(err){
} catch(err) {
return reject(err);
}
}
Expand All @@ -119,55 +119,36 @@ FileSystemAdapter.prototype.getFileData = function(filename) {
});
}

FileSystemAdapter.prototype.rotateEncryptionKey = function(options = {}) {
FileSystemAdapter.prototype.rotateEncryptionKey = async function(options = {}) {
const applicationDir = this._getApplicationDir();
var fileNames = [];
var oldKeyFileAdapter = {};
let fileNames = [];
let oldKeyFileAdapter = {};
if (options.oldKey !== undefined) {
oldKeyFileAdapter = new FileSystemAdapter({filesSubDirectory: this._filesDir, encryptionKey: options.oldKey});
}else{
oldKeyFileAdapter = new FileSystemAdapter({filesSubDirectory: this._filesDir});
oldKeyFileAdapter = new FileSystemAdapter({ filesSubDirectory: this._filesDir, encryptionKey: options.oldKey });
} else {
oldKeyFileAdapter = new FileSystemAdapter({ filesSubDirectory: this._filesDir });
}
if (options.fileNames !== undefined){
if (options.fileNames !== undefined) {
fileNames = options.fileNames;
}else{
fileNames = fs.readdirSync(applicationDir);
fileNames = fileNames.filter(fileName => fileName.indexOf('.') !== 0);
} else {
fileNames = fs.readdirSync(applicationDir);
fileNames = fileNames.filter(fileName => fileName.indexOf('.') !== 0);
}
return new Promise((resolve, _reject) => {
var fileNamesNotRotated = fileNames;
var fileNamesRotated = [];
var fileNameTotal = fileNames.length;
var fileNameIndex = 0;
fileNames.forEach(fileName => {
oldKeyFileAdapter
.getFileData(fileName)
.then(plainTextData => {
//Overwrite file with data encrypted with new key
this.createFile(fileName, plainTextData)
.then(() => {
fileNamesRotated.push(fileName);
fileNamesNotRotated = fileNamesNotRotated.filter(function(value){ return value !== fileName;})
fileNameIndex += 1;
if (fileNameIndex == fileNameTotal){
resolve({rotated: fileNamesRotated, notRotated: fileNamesNotRotated});
}
})
.catch(() => {
fileNameIndex += 1;
if (fileNameIndex == fileNameTotal){
resolve({rotated: fileNamesRotated, notRotated: fileNamesNotRotated});
}
})
})
.catch(() => {
fileNameIndex += 1;
if (fileNameIndex == fileNameTotal){
resolve({rotated: fileNamesRotated, notRotated: fileNamesNotRotated});
}
});
});
});

let fileNamesNotRotated = fileNames;
const fileNamesRotated = [];
for (const fileName of fileNames) {
try {
const plainTextData = await oldKeyFileAdapter.getFileData(fileName)
// Overwrite file with data encrypted with new key
await this.createFile(fileName, plainTextData)
fileNamesRotated.push(fileName);
fileNamesNotRotated = fileNamesNotRotated.filter(function(value) { return value !== fileName; });
} catch(err) {
continue;
}
}
return { rotated: fileNamesRotated, notRotated: fileNamesNotRotated };
}

FileSystemAdapter.prototype.getFileLocation = function(config, filename) {
Expand All @@ -177,20 +158,20 @@ FileSystemAdapter.prototype.getFileLocation = function(config, filename) {
/*
Helpers
--------------- */
FileSystemAdapter.prototype._getApplicationDir = function() {
FileSystemAdapter.prototype._getApplicationDir = function() {
if (this._filesDir) {
return path.join('files', this._filesDir);
} else {
return 'files';
}
}
}

FileSystemAdapter.prototype._applicationDirExist = function() {
return fs.existsSync(this._getApplicationDir());
}

FileSystemAdapter.prototype._getLocalFilePath = function(filename) {
let applicationDir = this._getApplicationDir();
const applicationDir = this._getApplicationDir();
if (!fs.existsSync(applicationDir)) {
this._mkdir(applicationDir);
}
Expand All @@ -199,20 +180,19 @@ FileSystemAdapter.prototype._getLocalFilePath = function(filename) {

FileSystemAdapter.prototype._mkdir = function(dirPath) {
// snippet found on -> https://gist.github.com/danherbert-epam/3960169
let dirs = dirPath.split(pathSep);
var root = "";
const dirs = dirPath.split(pathSep);
let root = "";

while (dirs.length > 0) {
var dir = dirs.shift();
const dir = dirs.shift();
if (dir === "") { // If directory starts with a /, the first path will be an empty string.
root = pathSep;
}
if (!fs.existsSync(path.join(root, dir))) {
try {
fs.mkdirSync(path.join(root, dir));
}
catch (e) {
if ( e.code == 'EACCES' ) {
} catch (err) {
if (err.code == 'EACCES') {
throw new Error("PERMISSION ERROR: In order to use the FileSystemAdapter, write access to the server's file system is required.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"url": "https://github.com/parse-community/parse-server-fs-adapter"
},
"scripts": {
"test": "jasmine",
"coverage": "nyc jasmine"
"coverage": "nyc jasmine",
"test": "jasmine"
},
"keywords": [
"parse-server",
Expand Down
4 changes: 2 additions & 2 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function config() {
// Get branch
const branch = ref.split('/').pop();
console.log(`Running on branch: ${branch}`);

// Set changelog file
//const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
const changelogFile = `./CHANGELOG.md`;
Expand Down Expand Up @@ -108,7 +108,7 @@ async function readFile(filePath) {

function getReleaseComment() {
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}';
let comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
return comment;
}

Expand Down
Loading