underpost 2.8.866 → 2.8.871

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +52 -36
  2. package/bin/build.js +1 -0
  3. package/bin/deploy.js +30 -1
  4. package/bin/file.js +3 -0
  5. package/bin/util.js +1 -56
  6. package/cli.md +88 -86
  7. package/conf.js +1 -1
  8. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  9. package/manifests/deployment/mongo-express/deployment.yaml +12 -12
  10. package/manifests/maas/nvim.sh +91 -0
  11. package/package.json +1 -10
  12. package/src/api/file/file.service.js +28 -8
  13. package/src/api/user/user.router.js +24 -0
  14. package/src/api/user/user.service.js +3 -4
  15. package/src/cli/cluster.js +2 -13
  16. package/src/cli/cron.js +0 -1
  17. package/src/cli/db.js +0 -19
  18. package/src/cli/deploy.js +17 -26
  19. package/src/cli/fs.js +1 -0
  20. package/src/cli/index.js +1 -0
  21. package/src/cli/run.js +9 -2
  22. package/src/client/components/core/CalendarCore.js +1 -1
  23. package/src/client/components/core/CssCore.js +12 -0
  24. package/src/client/components/core/Docs.js +2 -2
  25. package/src/client/components/core/FullScreen.js +19 -28
  26. package/src/client/components/core/Input.js +1 -0
  27. package/src/client/components/core/Modal.js +66 -63
  28. package/src/client/components/core/ObjectLayerEngine.js +229 -4
  29. package/src/client/components/core/ObjectLayerEngineModal.js +441 -0
  30. package/src/client/components/core/Panel.js +4 -1
  31. package/src/client/components/core/PanelForm.js +1 -1
  32. package/src/client/components/core/Router.js +29 -25
  33. package/src/client/components/core/ToggleSwitch.js +15 -1
  34. package/src/client/components/core/VanillaJs.js +12 -13
  35. package/src/client/public/default/assets/mailer/api-user-default-avatar.png +0 -0
  36. package/src/index.js +1 -1
  37. package/src/server/client-build.js +3 -11
  38. package/src/server/client-icons.js +6 -78
  39. package/src/server/conf.js +20 -64
  40. package/src/server/process.js +2 -1
  41. package/test/api.test.js +3 -2
  42. package/bin/cyberia0.js +0 -78
@@ -1,80 +1,17 @@
1
1
  import { favicons } from 'favicons';
2
- // TODO: search alternatives
3
- // import textToImage from 'text-to-image';
4
2
  import { loggerFactory } from './logger.js';
5
3
  import fs from 'fs-extra';
6
- import { getCapVariableName, s4 } from '../client/components/core/CommonJs.js';
7
- import { FileFactory } from '../api/file/file.service.js';
8
- import { svg, png, png3x } from 'font-awesome-assets';
4
+ import { getCapVariableName } from '../client/components/core/CommonJs.js';
9
5
 
10
6
  const logger = loggerFactory(import.meta);
11
7
 
12
- const faBase64Png = (faId = 'check', width = 100, height = 100, color = '#209e00') => {
13
- const b64Src = png3x(faId, color, width, height);
14
- return b64Src.split('src="data:image/png;base64,')[1].split('"')[0];
15
- };
16
-
17
- const defaultBaseTextImgOptions = {
18
- debug: true,
19
- fontFamily: 'Arial',
20
- fontWeight: 'bold',
21
- bgColor: 'black',
22
- textColor: 'white',
23
- debugFilename: 'src/client/public/text-image.png',
24
- verticalAlign: 'center',
25
- textAlign: 'center',
26
- };
27
-
28
- const defaultBaseTextImgOptionsSizes = {
29
- '70x70': {
30
- maxWidth: 70,
31
- customHeight: 70,
32
- fontSize: 25,
33
- margin: 10,
34
- },
35
- '100x100': {
36
- maxWidth: 100,
37
- customHeight: 100,
38
- fontSize: 30,
39
- margin: 12,
40
- },
41
- '100x300': {
42
- maxWidth: 300,
43
- customHeight: 100,
44
- fontSize: 30,
45
- margin: 12,
46
- },
47
- '1200x1200': {
48
- maxWidth: 1200,
49
- customHeight: 1200,
50
- fontSize: 500,
51
- margin: 50,
52
- },
53
- };
54
-
55
- const buildTextImg = async (text = 'APP', options, size = '1200x1200') => {
56
- options = { ...defaultBaseTextImgOptions, ...defaultBaseTextImgOptionsSizes[size], ...options };
57
- // await textToImage.generate(text, options);
58
- };
59
-
60
- const getBufferPngText = async ({ text, textColor, bgColor, size, debugFilename }) => {
61
- if (!text) text = 'Hello World!';
62
- if (!textColor) textColor = '#000000';
63
- if (!bgColor) bgColor = '#ffffff';
64
- if (!size) size = '100x300';
65
- if (!debugFilename) debugFilename = `./${s4()}${s4()}${s4()}.png`;
66
- await buildTextImg(text, { textColor, bgColor, size, debugFilename }, size);
67
- if (!fs.existsSync(debugFilename)) return Buffer.alloc(0); // Return empty buffer if file not found
68
- const bufferImage = fs.readFileSync(debugFilename);
69
- fs.removeSync(debugFilename);
70
- return bufferImage;
71
- };
72
-
73
8
  const buildIcons = async ({
74
9
  publicClientId,
75
- metadata: { title, description, keywords, author, thumbnail, themeColor },
10
+ metadata: { title, description, keywords, author, thumbnail, themeColor, baseBuildIconReference },
76
11
  }) => {
77
- const source = `src/client/public/${publicClientId}/assets/logo/base-icon.png`; // Source image(s). `string`, `buffer` or array of `string`
12
+ const source = baseBuildIconReference
13
+ ? baseBuildIconReference
14
+ : `src/client/public/${publicClientId}/assets/logo/base-icon.png`; // Source image(s). `string`, `buffer` or array of `string`
78
15
 
79
16
  const configuration = {
80
17
  path: '/', // Path for overriding default icons path. `string`
@@ -149,13 +86,4 @@ const buildIcons = async ({
149
86
  }
150
87
  };
151
88
 
152
- const getDefaultProfileImageId = async (File) => {
153
- const faId = 'user';
154
- const tmpFilePath = `./tmp/${faId}-${s4() + s4()}.svg`;
155
- fs.writeFileSync(tmpFilePath, svg(faId, '#f5f5f5d1'), 'utf8');
156
- const file = await new File(FileFactory.svg(fs.readFileSync(tmpFilePath), `${faId}.svg`)).save();
157
- fs.removeSync(tmpFilePath);
158
- return file._id;
159
- };
160
-
161
- export { buildIcons, buildTextImg, defaultBaseTextImgOptions, faBase64Png, getBufferPngText, getDefaultProfileImageId };
89
+ export { buildIcons };
@@ -9,17 +9,12 @@ import {
9
9
  timer,
10
10
  } from '../client/components/core/CommonJs.js';
11
11
  import * as dir from 'path';
12
- import cliProgress from 'cli-progress';
13
- import cliSpinners from 'cli-spinners';
14
- import logUpdate from 'log-update';
15
12
  import colors from 'colors';
16
13
  import { loggerFactory } from './logger.js';
17
14
  import { shellExec } from './process.js';
18
15
  import { DefaultConf } from '../../conf.js';
19
- import read from 'read';
20
16
  import splitFile from 'split-file';
21
- import axios from 'axios';
22
- import { ssrFactory } from './client-formatted.js';
17
+ import UnderpostRootEnv from '../cli/env.js';
23
18
 
24
19
  colors.enable();
25
20
 
@@ -32,7 +27,7 @@ const Config = {
32
27
  build: async function (deployContext = 'dd-default', deployList, subConf) {
33
28
  if (typeof process.argv[2] === 'string' && process.argv[2].startsWith('dd-')) deployContext = process.argv[2];
34
29
  if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
35
- fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
30
+ UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
36
31
  if (fs.existsSync(`./engine-private/replica/${deployContext}`))
37
32
  return loadConf(deployContext, process.env.NODE_ENV, subConf);
38
33
  else if (deployContext.startsWith('dd-')) return loadConf(deployContext, process.env.NODE_ENV, subConf);
@@ -48,17 +43,17 @@ const Config = {
48
43
  if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true });
49
44
  fs.writeFileSync(
50
45
  `${folder}/.env.production`,
51
- fs.readFileSync('./.env.production', 'utf8').replace('dd-default', deployId),
46
+ fs.readFileSync('./.env.production', 'utf8').replaceAll('dd-default', deployId),
52
47
  'utf8',
53
48
  );
54
49
  fs.writeFileSync(
55
50
  `${folder}/.env.development`,
56
- fs.readFileSync('./.env.development', 'utf8').replace('dd-default', deployId),
51
+ fs.readFileSync('./.env.development', 'utf8').replaceAll('dd-default', deployId),
57
52
  'utf8',
58
53
  );
59
54
  fs.writeFileSync(
60
55
  `${folder}/.env.test`,
61
- fs.readFileSync('./.env.test', 'utf8').replace('dd-default', deployId),
56
+ fs.readFileSync('./.env.test', 'utf8').replaceAll('dd-default', deployId),
62
57
  'utf8',
63
58
  );
64
59
  fs.writeFileSync(`${folder}/package.json`, fs.readFileSync('./package.json', 'utf8'), 'utf8');
@@ -562,16 +557,24 @@ const buildPortProxyRouter = (port, proxyRouter) => {
562
557
  // build router
563
558
  Object.keys(hosts).map((hostKey) => {
564
559
  let { host, path, target, proxy, peer } = hosts[hostKey];
565
- if (process.argv.includes('localhost') && process.env.NODE_ENV === 'development') host = `localhost`;
560
+ if (process.env.NODE_ENV === 'development') host = `localhost`;
561
+
562
+ if (!proxy.includes(port)) {
563
+ logger.warn('Proxy port not set on conf', { port, host, path, proxy, target });
564
+ if (process.env.NODE_ENV === 'production') {
565
+ logger.warn('Omitting host', { host, path, target });
566
+ return;
567
+ }
568
+ }
566
569
 
567
- if (!proxy.includes(port)) return;
568
570
  const absoluteHost = [80, 443].includes(port)
569
571
  ? `${host}${path === '/' ? '' : path}`
570
572
  : `${host}:${port}${path === '/' ? '' : path}`;
571
573
 
572
- if (process.argv.includes('localhost')) {
573
- if (!(absoluteHost in router)) router[absoluteHost] = target;
574
- } else router[absoluteHost] = target;
574
+ if (absoluteHost in router)
575
+ logger.warn('Overwrite: Absolute host already exists on router', { absoluteHost, target });
576
+
577
+ router[absoluteHost] = target;
575
578
  }); // order router
576
579
 
577
580
  if (Object.keys(router).length === 0) return router;
@@ -583,51 +586,6 @@ const buildPortProxyRouter = (port, proxyRouter) => {
583
586
  return reOrderRouter;
584
587
  };
585
588
 
586
- const cliBar = async (time = 5000) => {
587
- // create new progress bar
588
- const b = new cliProgress.SingleBar({
589
- format: 'Delay | {bar} | {percentage}% || {value}/{total} Chunks || Speed: {speed}',
590
- barCompleteChar: '\u2588',
591
- barIncompleteChar: '\u2591',
592
- hideCursor: true,
593
- });
594
-
595
- const maxValueDisplay = 200;
596
- const minValueDisplay = 0;
597
- const steps = 10;
598
- const incrementValue = 200 / steps;
599
- const delayTime = time / steps;
600
- // initialize the bar - defining payload token "speed" with the default value "N/A"
601
- b.start(maxValueDisplay, minValueDisplay, {
602
- speed: 'N/A',
603
- });
604
-
605
- // update values
606
- // b1.increment();
607
- // b1.update(20);
608
-
609
- for (const step of range(1, steps)) {
610
- b.increment(incrementValue);
611
- await timer(delayTime);
612
- }
613
-
614
- // stop the bar
615
- b.stop();
616
- };
617
-
618
- const cliSpinner = async (time = 5000, message0, message1, color, type = 'dots') => {
619
- const { frames, interval } = cliSpinners[type];
620
- const steps = parseInt(time / interval);
621
- let index = 0;
622
- for (const step of range(1, steps)) {
623
- const msg = `${message0 ? message0 : ''}${frames[index]}${message1 ? message1 : ''}`;
624
- logUpdate(color ? msg[color] : msg);
625
- await timer(interval);
626
- index++;
627
- if (index === frames.length) index = 0;
628
- }
629
- };
630
-
631
589
  const buildReplicaId = ({ deployId, replica }) => `${deployId}-${replica.slice(1)}`;
632
590
 
633
591
  const getDataDeploy = (
@@ -769,9 +727,9 @@ const validateTemplatePath = (absolutePath = '') => {
769
727
  };
770
728
 
771
729
  const awaitDeployMonitor = async (init = false, deltaMs = 1000) => {
772
- if (init) fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
730
+ if (init) UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
773
731
  await timer(deltaMs);
774
- if (fs.existsSync(`./tmp/await-deploy`)) return await awaitDeployMonitor();
732
+ if (UnderpostRootEnv.API.get('await-deploy')) return await awaitDeployMonitor();
775
733
  };
776
734
 
777
735
  const getCronBackUpFolder = (host = '', path = '') => {
@@ -983,8 +941,6 @@ export {
983
941
  buildWsSrc,
984
942
  cloneSrcComponents,
985
943
  buildProxyRouter,
986
- cliBar,
987
- cliSpinner,
988
944
  getDataDeploy,
989
945
  validateTemplatePath,
990
946
  buildReplicaId,
@@ -5,6 +5,7 @@ import dotenv from 'dotenv';
5
5
  import fs from 'fs-extra';
6
6
  import { loggerFactory } from './logger.js';
7
7
  import clipboard from 'clipboardy';
8
+ import UnderpostRootEnv from '../cli/env.js';
8
9
 
9
10
  dotenv.config();
10
11
 
@@ -47,7 +48,7 @@ const ProcessController = {
47
48
  this.logger.info(`process on exit`, args);
48
49
  });
49
50
  this.onSigListen();
50
- if (fs.existsSync(`./tmp/await-deploy`)) fs.remove(`./tmp/await-deploy`);
51
+ UnderpostRootEnv.API.delete('await-deploy');
51
52
  },
52
53
  };
53
54
 
package/test/api.test.js CHANGED
@@ -21,12 +21,13 @@ const BASE_URL =
21
21
 
22
22
  describe(`GET 'Test' API Request `, async () => {
23
23
  {
24
- const url = `${BASE_URL}/test/youtube-id/?url=https://www.youtube.com/watch?v=o4f42SbyDMk`;
24
+ const youtubeId = '2aib-pmgUdQ';
25
+ const url = `${BASE_URL}/test/youtube-id/?url=https://www.youtube.com/watch?v=${youtubeId}`;
25
26
  it(`youtube id from raw youtube url`, async () => {
26
27
  logger.info('request info', { url });
27
28
  const res = await axios.get(url);
28
29
  logger.info('response', res.data);
29
- return expect(res.data.data).equal('o4f42SbyDMk');
30
+ return expect(res.data.data).equal(youtubeId);
30
31
  });
31
32
  }
32
33
  {
package/bin/cyberia0.js DELETED
@@ -1,78 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- import dotenv from 'dotenv';
4
- import { Command } from 'commander';
5
- import fs from 'fs-extra';
6
- import { pbcopy, shellExec } from '../src/server/process.js';
7
- import Jimp from 'jimp';
8
- import Underpost from '../src/index.js';
9
- import { loggerFactory } from '../src/server/logger.js';
10
- import { DataBaseProvider } from '../src/db/DataBaseProvider.js';
11
-
12
- dotenv.config();
13
-
14
- const logger = loggerFactory(import.meta);
15
-
16
- const deployId = process.env.DEFAULT_DEPLOY_ID;
17
- const host = process.env.DEFAULT_DEPLOY_HOST;
18
- const path = process.env.DEFAULT_DEPLOY_PATH;
19
-
20
- const confServerPath = `./engine-private/conf/${deployId}/conf.server.json`;
21
- const confServer = JSON.parse(fs.readFileSync(confServerPath, 'utf8'));
22
- const { db } = confServer[host][path];
23
-
24
- logger.info('env', {
25
- deployId,
26
- host,
27
- path,
28
- db,
29
- });
30
-
31
- await DataBaseProvider.load({
32
- apis: ['object-layer'],
33
- host,
34
- path,
35
- db,
36
- });
37
-
38
- const ObjectLayer = DataBaseProvider.instance[`${host}${path}`].mongoose.models.ObjectLayer;
39
-
40
- const program = new Command();
41
-
42
- program.name('cyberia').description(`content generator cli ${Underpost.version}`).version(Underpost.version);
43
-
44
- const pngDirectoryIteratorByObjectLayerType = async (
45
- objectLayerType = 'skin',
46
- callback = ({ path, objectLayerType, objectLayerId, direction, frame }) => {},
47
- ) => {
48
- for (const objectLayerId of await fs.readdir(`./src/client/public/cyberia/assets/${objectLayerType}`)) {
49
- for (const direction of await fs.readdir(
50
- `./src/client/public/cyberia/assets/${objectLayerType}/${objectLayerId}`,
51
- )) {
52
- const dirFolder = `./src/client/public/cyberia/assets/${objectLayerType}/${objectLayerId}/${direction}`;
53
- if (!fs.statSync(dirFolder).isDirectory()) continue;
54
- for (const frame of await fs.readdir(dirFolder)) {
55
- const imageFilePath = `./src/client/public/cyberia/assets/${objectLayerType}/${objectLayerId}/${direction}/${frame}`;
56
- await callback({ path: imageFilePath, objectLayerType, objectLayerId, direction, frame });
57
- }
58
- }
59
- }
60
- };
61
-
62
- program
63
- .command('ol')
64
- .option('--import [object-layer-type]', 'Import object layer from type storage png image')
65
- .action(async (options = { import: false }) => {
66
- if (options.import) {
67
- await pngDirectoryIteratorByObjectLayerType(
68
- options.import,
69
- async ({ path, objectLayerType, objectLayerId, direction, frame }) => {
70
- console.log(path, { objectLayerType, objectLayerId, direction, frame });
71
- },
72
- );
73
- }
74
- await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
75
- })
76
- .description('Object layer management');
77
-
78
- program.parse();