mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) IO.cp -> IO.copy
This commit is contained in:
parent
13307f3861
commit
5041930685
9 changed files with 48 additions and 11 deletions
|
|
@ -62,11 +62,15 @@ module.exports.read = async (url, dataType = 'text') => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.cp = async (data) => {
|
module.exports.copy = async (from, to, names) => {
|
||||||
return await sendRequest({
|
return await sendRequest({
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url: '/cp',
|
url: '/copy',
|
||||||
data,
|
data: {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
names,
|
||||||
|
},
|
||||||
imgPosition,
|
imgPosition,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ module.exports.delete = handleError(IO.delete);
|
||||||
module.exports.patch = handleError(IO.patch);
|
module.exports.patch = handleError(IO.patch);
|
||||||
module.exports.write = handleError(IO.write);
|
module.exports.write = handleError(IO.write);
|
||||||
module.exports.read = handleError(IO.read);
|
module.exports.read = handleError(IO.read);
|
||||||
module.exports.cp = handleError(IO.cp);
|
module.exports.copy = handleError(IO.copy);
|
||||||
module.exports.pack = handleError(IO.pack);
|
module.exports.pack = handleError(IO.pack);
|
||||||
module.exports.extract = handleError(IO.extract);
|
module.exports.extract = handleError(IO.extract);
|
||||||
module.exports.move = handleError(IO.move);
|
module.exports.move = handleError(IO.move);
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@
|
||||||
"@cloudcmd/fileop": "^4.0.0",
|
"@cloudcmd/fileop": "^4.0.0",
|
||||||
"@cloudcmd/move-files": "^3.0.0",
|
"@cloudcmd/move-files": "^3.0.0",
|
||||||
"@cloudcmd/read-files-sync": "^2.0.0",
|
"@cloudcmd/read-files-sync": "^2.0.0",
|
||||||
"@putout/plugin-cloudcmd": "^1.0.0",
|
"@putout/plugin-cloudcmd": "^1.1.0",
|
||||||
"apart": "^2.0.0",
|
"apart": "^2.0.0",
|
||||||
"chalk": "^4.0.0",
|
"chalk": "^4.0.0",
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
|
|
|
||||||
2
server/fixture-user-menu/io-cp-fix.js
Normal file
2
server/fixture-user-menu/io-cp-fix.js
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
'use strict';
|
||||||
|
await IO.copy(dirPath, mp3Dir, mp3Names);
|
||||||
5
server/fixture-user-menu/io-cp.js
Normal file
5
server/fixture-user-menu/io-cp.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
await IO.cp({
|
||||||
|
from: dirPath,
|
||||||
|
to: mp3Dir,
|
||||||
|
names: mp3Names,
|
||||||
|
});
|
||||||
|
|
@ -219,7 +219,7 @@ function onPUT({name, config, body}, callback) {
|
||||||
} case 'rename':
|
} case 'rename':
|
||||||
return rename(rootDir, files.from, files.to, callback);
|
return rename(rootDir, files.from, files.to, callback);
|
||||||
|
|
||||||
case 'cp':
|
case 'copy':
|
||||||
if (!files.from || !files.names || !files.to)
|
if (!files.from || !files.names || !files.to)
|
||||||
return callback(body);
|
return callback(body);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,13 @@ const userMenuFile = readFileSync(userMenuPath, 'utf8');
|
||||||
const fixtureDir = join(__dirname, 'fixture-user-menu');
|
const fixtureDir = join(__dirname, 'fixture-user-menu');
|
||||||
const fixtureMoveName = join(fixtureDir, 'io-mv.js');
|
const fixtureMoveName = join(fixtureDir, 'io-mv.js');
|
||||||
const fixtureMoveFixName = join(fixtureDir, 'io-mv-fix.js');
|
const fixtureMoveFixName = join(fixtureDir, 'io-mv-fix.js');
|
||||||
|
const fixtureCopyName = join(fixtureDir, 'io-cp.js');
|
||||||
|
const fixtureCopyFixName = join(fixtureDir, 'io-cp-fix.js');
|
||||||
|
|
||||||
const fixtureMove = readFileSync(fixtureMoveName, 'utf8');
|
const fixtureMove = readFileSync(fixtureMoveName, 'utf8');
|
||||||
const fixtureMoveFix = readFileSync(fixtureMoveFixName, 'utf8');
|
const fixtureMoveFix = readFileSync(fixtureMoveFixName, 'utf8');
|
||||||
|
const fixtureCopy = readFileSync(fixtureCopyName, 'utf8');
|
||||||
|
const fixtureCopyFix = readFileSync(fixtureCopyFixName, 'utf8');
|
||||||
|
|
||||||
test('cloudcmd: user menu', async (t) => {
|
test('cloudcmd: user menu', async (t) => {
|
||||||
const options = {
|
const options = {
|
||||||
|
|
@ -39,7 +43,7 @@ test('cloudcmd: user menu', async (t) => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.only('cloudcmd: user menu: io.mv', async (t) => {
|
test('cloudcmd: user menu: io.mv', async (t) => {
|
||||||
const options = {
|
const options = {
|
||||||
menuName: '.cloudcmd.menu.js',
|
menuName: '.cloudcmd.menu.js',
|
||||||
};
|
};
|
||||||
|
|
@ -61,3 +65,25 @@ test.only('cloudcmd: user menu: io.mv', async (t) => {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('cloudcmd: user menu: io.cp', async (t) => {
|
||||||
|
const options = {
|
||||||
|
menuName: '.cloudcmd.menu.js',
|
||||||
|
};
|
||||||
|
|
||||||
|
const {readFile} = fs.promises;
|
||||||
|
|
||||||
|
fs.promises.readFile = stub().returns(fixtureCopy);
|
||||||
|
const userMenu = reRequire('./user-menu');
|
||||||
|
const {request} = serveOnce(userMenu);
|
||||||
|
|
||||||
|
const {body} = await request.get(`/api/v1/user-menu?dir=${__dirname}`, {
|
||||||
|
options,
|
||||||
|
});
|
||||||
|
|
||||||
|
threadIt.terminate();
|
||||||
|
fs.promises.readFile = readFile;
|
||||||
|
|
||||||
|
t.equal(fixtureCopyFix, body, 'should equal');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,25 +19,25 @@ const {request} = require('serve-once')(cloudcmd, {
|
||||||
configManager,
|
configManager,
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cloudcmd: rest: cp', async (t) => {
|
test('cloudcmd: rest: copy', async (t) => {
|
||||||
const tmp = join(fixtureDir, 'tmp');
|
const tmp = join(fixtureDir, 'tmp');
|
||||||
const files = {
|
const files = {
|
||||||
from: '/fixture/',
|
from: '/fixture/',
|
||||||
to: '/fixture/tmp',
|
to: '/fixture/tmp',
|
||||||
names: [
|
names: [
|
||||||
'cp.txt',
|
'copy.txt',
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
mkdirSync(tmp);
|
mkdirSync(tmp);
|
||||||
|
|
||||||
const {body} = await request.put(`/api/v1/cp`, {
|
const {body} = await request.put(`/api/v1/copy`, {
|
||||||
body: files,
|
body: files,
|
||||||
});
|
});
|
||||||
|
|
||||||
rimraf.sync(tmp);
|
rimraf.sync(tmp);
|
||||||
|
|
||||||
t.equal(body, 'copy: ok("["cp.txt"]")', 'should return result');
|
t.equal(body, 'copy: ok("["copy.txt"]")', 'should return result');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue