feature: common: entity: migrate to ESM

This commit is contained in:
coderiaser 2026-02-02 22:21:24 +02:00
parent c3b71653bb
commit ebabad948f
10 changed files with 61 additions and 66 deletions

View file

@ -2,7 +2,7 @@
/* global CloudCmd */
import createElement from '@cloudcmd/create-element';
import {getTitle, FS} from '#common/cloudfunc';
import {encode, decode} from '../../common/entity.js';
import {encode, decode} from '#common/entity';
let Title;

View file

@ -1,7 +1,7 @@
import {tryToCatch} from 'try-to-catch';
import * as Dialog from '#dom/dialog';
import {encode} from '../../common/entity.js';
import * as Images from '#dom/images';
import {encode} from '#common/entity';
import IO from './io/index.js';
const handleError = (promise) => async (...args) => {

View file

@ -11,8 +11,8 @@ import createElement from '@cloudcmd/create-element';
import * as Events from '#dom/events';
import * as Files from '#dom/files';
import {getTitle} from '#common/cloudfunc';
import * as input from './input.mjs';
import * as Images from '#dom/images';
import * as input from './input.mjs';
const {Dialog, setTitle} = DOM;

View file

@ -4,7 +4,7 @@ import {promisify} from 'es6-promisify';
import exec from 'execon';
import load from 'load.js';
import {tryToCatch} from 'try-to-catch';
import {encode} from '../../../common/entity.js';
import {encode} from '#common/entity';
import {removeExtension} from './remove-extension.mjs';
import {setListeners} from './set-listeners.mjs';
import {getNextCurrentName} from './get-next-current-name.mjs';
@ -51,19 +51,19 @@ export const init = promisify((callback) => {
exec.series([
DOM.loadSocket,
async (callback) => {
if (config('dropbox'))
return callback();
const {prefix, prefixSocket} = CloudCmd;
await loadAll();
await initOperations(prefix, prefixSocket, callback);
},
if (config('dropbox'))
return callback();
const {prefix, prefixSocket} = CloudCmd;
await loadAll();
await initOperations(prefix, prefixSocket, callback);
},
(callback) => {
Loaded = true;
Images.hide();
callback();
},
Loaded = true;
Images.hide();
callback();
},
], callback);
});

View file

@ -1,4 +1,5 @@
/* global CloudCmd, DOM */
import '../../../css/user-menu.css';
import currify from 'currify';
import wraptile from 'wraptile';
import {fullstore} from 'fullstore';
@ -8,7 +9,6 @@ import {tryCatch} from 'try-catch';
import {tryToCatch} from 'try-to-catch';
import {codeFrameColumns} from '@babel/code-frame';
import * as Dialog from '#dom/dialog';
import '../../../css/user-menu.css';
import * as Images from '#dom/images';
import {getUserMenu} from './get-user-menu.mjs';
import {navigate} from './navigate.mjs';

View file

@ -10,13 +10,13 @@ import {time} from '#common/util';
import * as Files from '#dom/files';
import * as Events from '#dom/events';
import {FS} from '#common/cloudfunc';
import * as Images from '#dom/images';
import {
isImage,
isAudio,
getType,
} from './types.mjs';
import * as Images from '#dom/images';
import {encode} from '../../../common/entity.js';
import {encode} from '#common/entity';
const CloudCmd = globalThis.CloudCmd || {};
const DOM = globalThis.DOM || {};

View file

@ -1,7 +1,7 @@
import rendy from 'rendy';
import currify from 'currify';
import store from 'fullstore';
import {encode} from './entity.js';
import {encode} from '#common/entity';
export const getHeaderField = currify(_getHeaderField);
@ -168,7 +168,6 @@ export const buildFromJSON = (params) => {
Path(path);
fileTable += `${header}<ul data-name="js-files" class="files">`;
/* Если мы не в корне */
if (path !== '/') {
const dotDot = getDotDot(path);
@ -199,43 +198,43 @@ export const buildFromJSON = (params) => {
fileTable += files
.filter(filterOutDotFiles({
showDotFiles,
}))
showDotFiles,
}))
.map(updateField)
.map((file) => {
const name = encode(file.name);
const link = prefix + FS + path + name;
const {
type,
mode,
date,
owner,
size,
} = file;
const linkResult = rendy(templateLink, {
link,
title: name,
name,
attribute: getAttribute(file.type),
});
const dataName = _getDataName(file.name);
const attribute = `draggable="true" ${dataName}`;
return rendy(templateFile, {
tag: 'li',
attribute,
className: '',
type,
name: linkResult,
size,
date,
owner,
mode,
});
})
const name = encode(file.name);
const link = prefix + FS + path + name;
const {
type,
mode,
date,
owner,
size,
} = file;
const linkResult = rendy(templateLink, {
link,
title: name,
name,
attribute: getAttribute(file.type),
});
const dataName = _getDataName(file.name);
const attribute = `draggable="true" ${dataName}`;
return rendy(templateFile, {
tag: 'li',
attribute,
className: '',
type,
name: linkResult,
size,
date,
owner,
mode,
});
})
.join('');
fileTable += '</ul>';

View file

@ -1,7 +1,4 @@
'use strict';
const Entities = {
// '&nbsp;': ' ',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
@ -9,7 +6,7 @@ const Entities = {
const keys = Object.keys(Entities);
module.exports.encode = (str) => {
export const encode = (str) => {
for (const code of keys) {
const char = Entities[code];
const reg = RegExp(char, 'g');
@ -20,7 +17,7 @@ module.exports.encode = (str) => {
return str;
};
module.exports.decode = (str) => {
export const decode = (str) => {
for (const code of keys) {
const char = Entities[code];
const reg = RegExp(code, 'g');

View file

@ -1,7 +1,5 @@
'use strict';
const {test} = require('supertape');
const entity = require('./entity');
import {test} from 'supertape';
import * as entity from '#common/entity';
test('cloudcmd: entity: encode', (t) => {
const result = entity.encode('<hello> ');

View file

@ -230,7 +230,8 @@
"#dom/storage": "./client/dom/storage.mjs",
"#dom/rest": "./client/dom/rest.mjs",
"#common/util": "./common/util.mjs",
"#common/cloudfunc": "./common/cloudfunc.mjs"
"#common/cloudfunc": "./common/cloudfunc.mjs",
"#common/entity": "./common/entity.mjs"
},
"engines": {
"node": ">=22"