From 2b265dc7509f2617bd5800032881d6941c9cf64c Mon Sep 17 00:00:00 2001 From: Desmond Kyeremeh Date: Sun, 18 Jun 2023 21:49:59 +0000 Subject: [PATCH] Use base-64 for btoa --- package.json | 4 ++-- src/lfs.utils.js | 10 ++++------ tests/int-tests/api.spec.js | 3 ++- yarn.lock | 10 +++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index a918568..40f7d31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "elfinder-node", - "version": "1.0.1", + "version": "1.0.2", "description": "A NodeJS connector/backend for elFinder file manager", "main": "src/elfinder.js", "author": "d.kyeremeh@dekyfin.com", @@ -8,11 +8,11 @@ "dependencies": { "adm-zip": "^0.5.10", "archiver": "^1.2.0", + "base-64": "^1.0.0", "express": "^4.15.2", "express-busboy": "^10.1.0", "fs-extra": "^11.1.1", "jimp": "^0.2.27", - "lzutf8": "^0.3.5", "mime-types": "^2.1.12", "promise": "^8.3.0", "underscore": "^1.8.3" diff --git a/src/lfs.utils.js b/src/lfs.utils.js index bdaaaf7..21ceae4 100644 --- a/src/lfs.utils.js +++ b/src/lfs.utils.js @@ -1,4 +1,4 @@ -const lz = require('lzutf8'); //Remove after decoupling +const base64 = require('base-64'); const path = require('path'); //Remove const mime = require('mime-types'); const promise = require('promise'); @@ -67,7 +67,7 @@ exports.decode = function (dir) { .replace(/_/g, '/') .replace(/\./g, '='); - relative = lz.decompress(relative + '==', { + relative = base64.decode(relative + '==', { inputEncoding: 'Base64', }); name = path.basename(relative); @@ -84,10 +84,8 @@ exports.decode = function (dir) { //Used by exports.info, api.opne, api.tmb, api.zipdl exports.encode = function (dir) { const info = exports.parse(dir); - const relative = lz - .compress(info.path, { - outputEncoding: 'Base64', - }) + const relative = base64 + .encode(info.path) .replace(/=+$/g, '') .replace(/\+/g, '-') .replace(/\//g, '_') diff --git a/tests/int-tests/api.spec.js b/tests/int-tests/api.spec.js index 0e43611..3abf8f4 100644 --- a/tests/int-tests/api.spec.js +++ b/tests/int-tests/api.spec.js @@ -3,6 +3,7 @@ const app = require('../app'); const qs = require('qs'); const fs = require('fs-extra'); const { resolve } = require('path'); +const base64 = require('base-64'); const request = require('supertest')(app); const volume = 'v0_Lw'; @@ -14,7 +15,7 @@ const files = { zip: resolve(__dirname, '../files/zip.zip'), }; -const encodePath = (path) => 'v0_' + btoa(path); +const encodePath = (path) => 'v0_' + base64.encode(path); const url = (query = {}) => { return `/connector?${qs.stringify(query)}`; diff --git a/yarn.lock b/yarn.lock index 7c892d9..c3324b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -340,6 +340,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +base-64@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/base-64/-/base-64-1.0.0.tgz#09d0f2084e32a3fd08c2475b973788eee6ae8f4a" + integrity sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg== + base64-js@^1.3.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -1774,11 +1779,6 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -lzutf8@^0.3.5: - version "0.3.5" - resolved "https://registry.yarnpkg.com/lzutf8/-/lzutf8-0.3.5.tgz#c4e0237c6b22942ea084909b7f4033d28b25d24d" - integrity sha512-IguWjQkXnfFuE93+IQ5ur/ITwDacfq5gxXL1mZIt+2nvVgVZnl20iUBOSdlRStYh6ptbBnKNffZzCA5KZ3yILQ== - make-dir@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"