mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) show size as <link> for links
This commit is contained in:
parent
e18ddb2e18
commit
846f4aa78f
5 changed files with 138 additions and 6 deletions
|
|
@ -230,6 +230,7 @@ function getAttribute(type) {
|
|||
return 'target="_blank" ';
|
||||
}
|
||||
|
||||
module.exports._getSize = getSize;
|
||||
function getSize(file) {
|
||||
const {
|
||||
size,
|
||||
|
|
@ -239,6 +240,9 @@ function getSize(file) {
|
|||
if (type === 'directory')
|
||||
return '<dir>';
|
||||
|
||||
if (/link/.test(type))
|
||||
return '<link>';
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
|||
63
common/cloudfunc.spec.js
Normal file
63
common/cloudfunc.spec.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
const cloudfunc = require('./cloudfunc');
|
||||
const {
|
||||
_getSize,
|
||||
} = cloudfunc;
|
||||
|
||||
test('cloudfunc: getSize: dir', (t) => {
|
||||
const type = 'directory';
|
||||
const size = 0;
|
||||
const result = _getSize({
|
||||
type,
|
||||
size,
|
||||
});
|
||||
|
||||
const expected = '<dir>';
|
||||
|
||||
t.equal(result, expected, 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudfunc: getSize: link: dir', (t) => {
|
||||
const type = 'directory-link';
|
||||
const size = 0;
|
||||
const result = _getSize({
|
||||
type,
|
||||
size,
|
||||
});
|
||||
|
||||
const expected = '<link>';
|
||||
|
||||
t.equal(result, expected, 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudfunc: getSize: link: file', (t) => {
|
||||
const type = 'file-link';
|
||||
const size = 0;
|
||||
const result = _getSize({
|
||||
type,
|
||||
size,
|
||||
});
|
||||
|
||||
const expected = '<link>';
|
||||
|
||||
t.equal(result, expected, 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudfunc: getSize: file', (t) => {
|
||||
const type = 'file';
|
||||
const size = '100.00kb';
|
||||
const result = _getSize({
|
||||
type,
|
||||
size,
|
||||
});
|
||||
|
||||
const expected = '100.00kb';
|
||||
|
||||
t.equal(result, expected, 'should equal');
|
||||
t.end();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue