mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 17:05:17 +00:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import {tryToCatch} from 'try-to-catch';
|
|
import * as Dialog from '#dom/dialog';
|
|
import {encode} from '../../common/entity.js';
|
|
import * as Images from './images.mjs';
|
|
import IO from './io/index.js';
|
|
|
|
const handleError = (promise) => async (...args) => {
|
|
const [e, data] = await tryToCatch(promise, ...args);
|
|
|
|
if (!e)
|
|
return [e, data];
|
|
|
|
const encoded = encode(e.message);
|
|
|
|
Images.show.error(encoded);
|
|
Dialog.alert(encoded);
|
|
|
|
return [e, data];
|
|
};
|
|
|
|
export const remove = handleError(IO.delete);
|
|
export const patch = handleError(IO.patch);
|
|
export const write = handleError(IO.write);
|
|
export const createDirectory = handleError(IO.createDirectory);
|
|
export const read = handleError(IO.read);
|
|
export const copy = handleError(IO.copy);
|
|
export const pack = handleError(IO.pack);
|
|
export const extract = handleError(IO.extract);
|
|
export const move = handleError(IO.move);
|
|
export const rename = handleError(IO.rename);
|
|
|
|
export const Config = {
|
|
read: handleError(IO.Config.read),
|
|
write: handleError(IO.Config.write),
|
|
};
|
|
|
|
export const Markdown = {
|
|
read: handleError(IO.Markdown.read),
|
|
render: handleError(IO.Markdown.render),
|
|
};
|