feature: cloudfunc: override date format (#459)

This commit is contained in:
coderiaser 2026-03-17 21:09:20 +02:00
parent 170b4da211
commit daf8387516
3 changed files with 63 additions and 6 deletions

View file

@ -1,17 +1,19 @@
import {rendy} from 'rendy';
import currify from 'currify';
import store from 'fullstore';
import {fullstore} from 'fullstore';
import {encode} from '#common/entity';
const id = (a) => a;
export const dateFormatter = fullstore(id);
export const getHeaderField = currify(_getHeaderField);
/* КОНСТАНТЫ (общие для клиента и сервера)*/
/* название программы */
const NAME = 'Cloud Commander';
export const FS = '/fs';
const Path = store();
const Path = fullstore();
Path('/');
@ -123,6 +125,8 @@ export const buildFromJSON = (params) => {
showDotFiles,
} = params;
const formatDate = dateFormatter();
const templateFile = template.file;
const templateLink = template.link;
const json = params.data;
@ -230,7 +234,7 @@ export const buildFromJSON = (params) => {
type,
name: linkResult,
size,
date,
date: formatDate(date),
owner,
mode,
});
@ -290,3 +294,4 @@ export function getDotDot(path) {
return dotDot;
}

View file

@ -7,6 +7,7 @@ import {
getPathLink,
buildFromJSON,
_getDataName,
dateFormatter,
} from '#common/cloudfunc';
const templatePath = new URL('../tmpl/fs', import.meta.url).pathname;
@ -219,3 +220,49 @@ test('cloudfunc: _getDataName', (t) => {
t.equal(result, expected);
t.end();
});
test('cloudfunc: buildFromJSON: formatDate', (t) => {
const data = {
path: '/media/',
files: [{
date: '30.08.2016',
mode: 'rwx rwx rwx',
name: '{{}}',
owner: 'root',
size: '7b',
type: 'file',
}],
};
const oldFormatter = dateFormatter();
const formatDate = (str) => {
const [day, month, year] = str.split('.');
const date = new Date(year, month - 1, day);
return date.toLocaleDateString();
};
dateFormatter(formatDate);
const html = buildFromJSON({
prefix: '',
template,
data,
showDotFiles: false,
});
dateFormatter(oldFormatter);
const $ = cheerio.load(html);
const el = $('[data-name="js-file-JTdCJTdCJTdEJTdE"]');
const result = el
.find('[data-name="js-date"]')
.text();
const expected = '8/30/2016';
t.equal(result, expected);
t.end();
});