feature: cloudcmd: add ability to hide dot files (#307)

This commit is contained in:
coderiaser 2024-08-17 13:10:43 +03:00
parent 9dbd812b3d
commit ddf4542b75
11 changed files with 203 additions and 126 deletions

View file

@ -16,6 +16,13 @@ const Path = store();
Path('/');
const filterOutDotFiles = ({showDotFiles}) => ({name}) => {
if (showDotFiles)
return true;
return !name.startsWith('.');
};
module.exports.FS = FS;
module.exports.apiURL = '/api/v1';
module.exports.MAX_FILE_SIZE = 500 * 1024;
@ -118,6 +125,7 @@ module.exports.buildFromJSON = (params) => {
template,
sort = 'name',
order = 'asc',
showDotFiles,
} = params;
const templateFile = template.file;
@ -195,6 +203,7 @@ module.exports.buildFromJSON = (params) => {
}
fileTable += files
.filter(filterOutDotFiles({showDotFiles}))
.map(updateField)
.map((file) => {
const name = encode(file.name);

View file

@ -142,3 +142,36 @@ test('cloudfunc: getSize: file', (t) => {
t.equal(result, expected);
t.end();
});
test('cloudfunc: buildFromJSON: showDotFiles: false', (t) => {
const data = {
path: '/media/',
files: [{
date: '30.08.2016',
mode: 'rwx rwx rwx',
name: '.floppy',
owner: 'root',
size: '7b',
type: 'directory-link',
}],
};
const html = buildFromJSON({
prefix: '',
template,
data,
showDotFiles: false,
});
const $ = cheerio.load(html);
const el = $('[data-name="js-file-LmZsb3BweQ=="]');
const result = el
.find('[data-name="js-name"]')
.text();
const expected = '';
t.equal(result, expected);
t.end();
});