mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(server) convert fs to fs.promises
This commit is contained in:
parent
8992a1c7bc
commit
b803021ce2
4 changed files with 14 additions and 21 deletions
|
|
@ -1,17 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const {readFile} = require('fs').promises;
|
||||
const {join} = require('path');
|
||||
const {
|
||||
callbackify,
|
||||
promisify,
|
||||
} = require('util');
|
||||
const {callbackify} = require('util');
|
||||
|
||||
const pullout = require('pullout');
|
||||
const ponse = require('ponse');
|
||||
const threadIt = require('thread-it');
|
||||
|
||||
const readFile = promisify(fs.readFile);
|
||||
const parse = threadIt(join(__dirname, 'worker'));
|
||||
|
||||
const root = require('../root');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
const DIR_SERVER = './';
|
||||
const DIR_COMMON = '../common/';
|
||||
|
||||
const fs = require('fs');
|
||||
const {realpath} = require('fs').promises;
|
||||
const {promisify} = require('util');
|
||||
|
||||
const flop = require('flop');
|
||||
|
|
@ -36,18 +36,18 @@ const {FS} = CloudFunc;
|
|||
const Columns = require(`${DIR_SERVER}/columns`);
|
||||
const Template = require(`${DIR_SERVER}/template`);
|
||||
|
||||
const flopRead = promisify(flop.read);
|
||||
|
||||
const tokenize = (fn, a) => (b) => fn(a, b);
|
||||
const getReadDir = (config) => {
|
||||
if (!config('dropbox'))
|
||||
return promisify(flop.read);
|
||||
return flopRead;
|
||||
|
||||
const {readDir} = onceRequire('@cloudcmd/dropbox');
|
||||
|
||||
return tokenize(readDir, config('dropboxToken'));
|
||||
};
|
||||
|
||||
const realpath = promisify(fs.realpath);
|
||||
|
||||
/**
|
||||
* routing of server queries
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -190,7 +190,9 @@ test('cloudcmd: route: file: fs', async (t) => {
|
|||
options,
|
||||
});
|
||||
|
||||
t.equal(body, '', 'should equal');
|
||||
const expected = 'EISDIR: illegal operation on a directory, read';
|
||||
|
||||
t.equal(body, expected, 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -239,11 +241,10 @@ test('cloudcmd: route: not found', async (t) => {
|
|||
|
||||
test('cloudcmd: route: realpath: error', async (t) => {
|
||||
const error = 'realpath error';
|
||||
const {realpath} = fs;
|
||||
const {realpath} = fs.promises;
|
||||
|
||||
fs.realpath = (name, fn) => {
|
||||
fn(error);
|
||||
fs.realpath = realpath;
|
||||
fs.promises.realpath = async () => {
|
||||
throw error;
|
||||
};
|
||||
|
||||
const config = {
|
||||
|
|
@ -265,8 +266,7 @@ test('cloudcmd: route: realpath: error', async (t) => {
|
|||
options,
|
||||
});
|
||||
|
||||
/*eslint require-atomic-updates:0*/
|
||||
fs.realpath = realpath;
|
||||
fs.promises.realpath = realpath;
|
||||
|
||||
t.ok(/^ENOENT/.test(body), 'should return error');
|
||||
t.end();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const {homedir} = require('os');
|
||||
const fs = require('fs');
|
||||
const {readFile} = require('fs').promises;
|
||||
|
||||
const {join} = require('path');
|
||||
const {promisify} = require('util');
|
||||
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const currify = require('currify');
|
||||
|
|
@ -18,8 +17,6 @@ threadIt.init();
|
|||
// warm up worker cache
|
||||
transpile('');
|
||||
|
||||
const readFile = promisify(fs.readFile);
|
||||
|
||||
const URL = '/api/v1/user-menu';
|
||||
const DEFAULT_MENU_PATH = join(__dirname, '../static/user-menu.js');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue