museria 0.2.49 → 0.3.2

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 (74) hide show
  1. package/.eslintrc +10 -2
  2. package/.github/workflows/build.yml +3 -3
  3. package/.github/workflows/publish.yml +3 -3
  4. package/README.md +55 -59
  5. package/bin/actions.js +28 -28
  6. package/bin/index.js +4 -4
  7. package/bin/runner.js +1 -1
  8. package/bin/utils.js +6 -2
  9. package/dist/client/museria.client.js +7 -7
  10. package/dist/face/45a265d0f07b31cde85f.ttf +0 -0
  11. package/dist/face/6205fd00fb1b573e9f0f.ttf +0 -0
  12. package/dist/face/8d3cabfc66809162fb4d.woff2 +0 -0
  13. package/dist/face/fb8184add5a3101ad0a3.woff2 +0 -0
  14. package/dist/face/museria.face.js +33 -13
  15. package/dist/face/style.css +13 -11
  16. package/package.json +41 -40
  17. package/src/browser/client/index.js +2 -1
  18. package/src/browser/face/client.js +2 -1
  19. package/src/browser/face/controllers/app/app.html +77 -69
  20. package/src/browser/face/controllers/app/app.js +14 -7
  21. package/src/browser/face/controllers/app/app.scss +2 -22
  22. package/src/browser/face/index.js +3 -3
  23. package/src/browser/face/styles/main.scss +91 -11
  24. package/src/browser/face/styles/vars.scss +0 -1
  25. package/src/client.js +73 -74
  26. package/src/collection/transports/music/index.js +20 -18
  27. package/src/db/transports/database/index.js +7 -5
  28. package/src/db/transports/loki/index.js +30 -25
  29. package/src/errors.js +2 -1
  30. package/src/index.js +8 -6
  31. package/src/node.js +312 -323
  32. package/src/schema.js +27 -29
  33. package/src/server/transports/express/api/butler/controllers.js +7 -10
  34. package/src/server/transports/express/api/butler/routes.js +5 -5
  35. package/src/server/transports/express/api/master/controllers.js +7 -10
  36. package/src/server/transports/express/api/master/routes.js +5 -5
  37. package/src/server/transports/express/api/node/controllers.js +52 -61
  38. package/src/server/transports/express/api/node/routes.js +10 -10
  39. package/src/server/transports/express/api/routes.js +1 -1
  40. package/src/server/transports/express/api/slave/controllers.js +7 -10
  41. package/src/server/transports/express/api/slave/routes.js +6 -6
  42. package/src/server/transports/express/client/controllers.js +40 -61
  43. package/src/server/transports/express/client/routes.js +33 -39
  44. package/src/server/transports/express/controllers.js +10 -21
  45. package/src/server/transports/express/index.js +23 -20
  46. package/src/server/transports/express/midds.js +67 -67
  47. package/src/server/transports/express/routes.js +12 -12
  48. package/src/utils.js +175 -184
  49. package/test/client.js +311 -305
  50. package/test/db/database.js +32 -28
  51. package/test/db/loki.js +78 -74
  52. package/test/group.js +161 -156
  53. package/test/index.js +20 -10
  54. package/test/node.js +461 -460
  55. package/test/routes.js +404 -399
  56. package/test/server/express.js +35 -31
  57. package/test/services.js +25 -18
  58. package/test/tools.js +8 -6
  59. package/test/utils.js +236 -234
  60. package/webpack.client.js +9 -7
  61. package/webpack.face.js +8 -6
  62. package/dist/face/fa-brands-400.eot +0 -0
  63. package/dist/face/fa-brands-400.svg +0 -3717
  64. package/dist/face/fa-brands-400.ttf +0 -0
  65. package/dist/face/fa-brands-400.woff +0 -0
  66. package/dist/face/fa-brands-400.woff2 +0 -0
  67. package/dist/face/fa-solid-900.eot +0 -0
  68. package/dist/face/fa-solid-900.svg +0 -5034
  69. package/dist/face/fa-solid-900.ttf +0 -0
  70. package/dist/face/fa-solid-900.woff +0 -0
  71. package/dist/face/fa-solid-900.woff2 +0 -0
  72. /package/dist/face/{open-sans.ttf → 17e98b9e5586529b13cc.ttf} +0 -0
  73. /package/dist/face/{proxima-nova.ttf → 326601dfabd91e3f016c.ttf} +0 -0
  74. /package/dist/face/{logo.svg → ee9c6af64aa224827cec.svg} +0 -0
package/src/schema.js CHANGED
@@ -1,11 +1,12 @@
1
- const _ = require('lodash');
2
- const mtSchema = require('metastocle/src/schema');
3
- const stSchema = require('storacle/src/schema');
4
- const utils = require('./utils');
1
+ import merge from "lodash-es/merge.js";
2
+ import mtSchema from "metastocle/src/schema.js";
3
+ import stSchema from "storacle/src/schema.js";
4
+ import utils from "./utils.js";
5
+
5
6
  const schema = Object.assign({}, mtSchema, stSchema);
6
7
 
7
8
  schema.getStatusResponse = function () {
8
- return _.merge(mtSchema.getStatusResponse(), stSchema.getStatusResponse(), {
9
+ return merge(mtSchema.getStatusResponse(), stSchema.getStatusResponse(), {
9
10
  props: {
10
11
  collectionLimit: 'number',
11
12
  }
@@ -17,10 +18,10 @@ schema.getSongPriority = function () {
17
18
  type: 'number',
18
19
  value: utils.isValidSongPriority.bind(utils)
19
20
  };
20
- }
21
+ };
21
22
 
22
23
  schema.getStatusPrettyResponse = function () {
23
- return _.merge(this.getStatusResponse(), mtSchema.getStatusPrettyResponse(), stSchema.getStatusPrettyResponse());
24
+ return merge(this.getStatusResponse(), mtSchema.getStatusPrettyResponse(), stSchema.getStatusPrettyResponse());
24
25
  };
25
26
 
26
27
  schema.getMusicCollectionGetting = function (options = {}) {
@@ -28,7 +29,6 @@ schema.getMusicCollectionGetting = function (options = {}) {
28
29
  type: 'object',
29
30
  value: null
30
31
  };
31
-
32
32
  const musicType = {
33
33
  type: 'object',
34
34
  strict: true,
@@ -38,56 +38,54 @@ schema.getMusicCollectionGetting = function (options = {}) {
38
38
  beautify: 'boolean'
39
39
  }
40
40
  };
41
-
42
41
  const titleType = [
43
42
  {
44
43
  type: 'object',
45
- strict: true,
46
- props: {
44
+ strict: true,
45
+ props: {
47
46
  $mus: musicType
48
47
  }
49
48
  },
50
49
  {
51
50
  type: 'object',
52
- strict: true,
51
+ strict: true,
53
52
  props: {
54
53
  $art: 'string'
55
54
  }
56
55
  },
57
56
  {
58
57
  type: 'object',
59
- strict: true,
60
- props: {
58
+ strict: true,
59
+ props: {
61
60
  $or: {
62
61
  type: 'array',
63
62
  items: [
64
- {
63
+ {
65
64
  type: 'object',
66
65
  strict: true,
67
66
  props: {
68
67
  $mus: musicType
69
68
  }
70
69
  },
71
- {
70
+ {
72
71
  type: 'object',
73
72
  strict: true,
74
73
  props: {
75
74
  $milk: {
76
75
  type: 'string',
77
76
  value: val => (!options.findingStringMinLength || val.length >= options.findingStringMinLength)
78
- }
77
+ }
79
78
  }
80
79
  }
81
80
  ]
82
- }
81
+ }
83
82
  }
84
83
  }
85
84
  ];
86
-
87
85
  return {
88
86
  type: 'object',
89
87
  strict: true,
90
- props: {
88
+ props: {
91
89
  offset: {
92
90
  type: 'number',
93
91
  value: 0
@@ -113,11 +111,11 @@ schema.getMusicCollectionGetting = function (options = {}) {
113
111
  type: 'object',
114
112
  strict: true,
115
113
  props: {
116
- compTitle: titleType
114
+ compTitle: titleType
117
115
  }
118
116
  }
119
117
  }
120
- }
118
+ };
121
119
  };
122
120
 
123
121
  schema.getSongAudioLink = function () {
@@ -137,13 +135,13 @@ schema.getSongCoverLink = function () {
137
135
  schema.getSongInfo = function () {
138
136
  return {
139
137
  type: 'object',
140
- props: {
138
+ props: {
141
139
  address: this.getAddress(),
142
140
  title: 'string',
143
141
  fileHash: 'string',
144
- tags: 'object',
142
+ tags: 'object',
145
143
  audioLink: this.getSongAudioLink(),
146
- coverLink: this.getSongCoverLink(),
144
+ coverLink: this.getSongCoverLink(),
147
145
  priority: this.getSongPriority()
148
146
  },
149
147
  strict: true
@@ -156,7 +154,7 @@ schema.getSongAdditionResponse = function () {
156
154
 
157
155
  schema.getSongInfoMasterResponse = function () {
158
156
  return this.getSongInfoButlerResponse();
159
- }
157
+ };
160
158
 
161
159
  schema.getSongInfoButlerResponse = function () {
162
160
  return {
@@ -169,7 +167,7 @@ schema.getSongInfoButlerResponse = function () {
169
167
  }
170
168
  },
171
169
  strict: true
172
- }
170
+ };
173
171
  };
174
172
 
175
173
  schema.getSongInfoSlaveResponse = function () {
@@ -178,7 +176,7 @@ schema.getSongInfoSlaveResponse = function () {
178
176
 
179
177
  schema.getSongRemovalMasterResponse = function () {
180
178
  return this.getSongRemovalButlerResponse();
181
- }
179
+ };
182
180
 
183
181
  schema.getSongRemovalButlerResponse = function () {
184
182
  return this.getFileRemovalMasterResponse();
@@ -195,4 +193,4 @@ schema.getMusicCollection = function () {
195
193
  return songInfo;
196
194
  };
197
195
 
198
- module.exports = schema;
196
+ export default schema;
@@ -1,11 +1,8 @@
1
- const schema = require('../../../../../schema');
1
+ import schema from "../../../../../schema.js";
2
2
 
3
- /**
4
- * Remove the song
5
- */
6
- module.exports.removeSong = node => {
3
+ export const removeSong = node => {
7
4
  return async (req, res, next) => {
8
- try {
5
+ try {
9
6
  const title = req.body.title;
10
7
  node.songTitleTest(title);
11
8
  const options = node.createRequestNetworkOptions(req.body, {
@@ -15,8 +12,8 @@ module.exports.removeSong = node => {
15
12
  const removed = results.reduce((p, c) => p + c.removed, 0);
16
13
  return res.send({ removed });
17
14
  }
18
- catch(err) {
15
+ catch (err) {
19
16
  next(err);
20
- }
21
- }
22
- };
17
+ }
18
+ };
19
+ };
@@ -1,15 +1,15 @@
1
- const controllers = require('./controllers');
1
+ import * as controllers from "./controllers.js";
2
2
 
3
- module.exports = [
3
+ export default [
4
4
  /**
5
5
  * Remove the song
6
- *
6
+ *
7
7
  * @api {post} /api/butler/remove-song
8
8
  * @apiParam {string} title - song title
9
9
  */
10
- {
10
+ {
11
11
  name: 'removeSong',
12
- method: 'post',
12
+ method: 'post',
13
13
  url: '/remove-song',
14
14
  fn: controllers.removeSong
15
15
  }
@@ -1,11 +1,8 @@
1
- const schema = require('../../../../../schema');
1
+ import schema from "../../../../../schema.js";
2
2
 
3
- /**
4
- * Remove the song
5
- */
6
- module.exports.removeSong = node => {
3
+ export const removeSong = node => {
7
4
  return async (req, res, next) => {
8
- try {
5
+ try {
9
6
  const title = req.body.title;
10
7
  node.songTitleTest(title);
11
8
  const options = node.createRequestNetworkOptions(req.body, {
@@ -15,8 +12,8 @@ module.exports.removeSong = node => {
15
12
  const removed = results.reduce((p, c) => p + c.removed, 0);
16
13
  return res.send({ removed });
17
14
  }
18
- catch(err) {
15
+ catch (err) {
19
16
  next(err);
20
- }
21
- }
22
- };
17
+ }
18
+ };
19
+ };
@@ -1,15 +1,15 @@
1
- const controllers = require('./controllers');
1
+ import * as controllers from "./controllers.js";
2
2
 
3
- module.exports = [
3
+ export default [
4
4
  /**
5
5
  * Remove the song
6
- *
6
+ *
7
7
  * @api {post} /api/master/remove-song
8
8
  * @apiParam {string} title - song title
9
9
  */
10
- {
10
+ {
11
11
  name: 'removeSong',
12
- method: 'post',
12
+ method: 'post',
13
13
  url: '/remove-song',
14
14
  fn: controllers.removeSong
15
15
  }
@@ -1,61 +1,53 @@
1
- const utils = require('../../../../../utils');
2
- const fs = require('fs');
3
- const fse = require('fs-extra');
4
- const path = require('path');
5
- const crypto = require('crypto');
6
- const _ = require('lodash');
1
+ import utils from "../../../../../utils.js";
2
+ import fse from "fs-extra";
3
+ import path from "path";
4
+ import crypto from "crypto";
5
+ import omit from "lodash-es/omit.js";
7
6
 
8
- /**
9
- * Add the song
10
- */
11
- module.exports.addSong = node => {
7
+ export const addSong = node => {
12
8
  return async (req, res, next) => {
13
9
  let file;
14
10
  let dupFile;
15
11
  let dupFileInfo;
16
12
  let filePath = '';
17
-
18
13
  const cleanUp = async () => {
19
14
  utils.isFileReadStream(file) && file.destroy();
20
-
21
- if(!filePath) {
15
+ if (!filePath) {
22
16
  return;
23
17
  }
24
18
 
25
19
  try {
26
20
  await fse.remove(filePath);
27
21
  }
28
- catch(err) {
29
- if(err.code != 'ENOENT') {
22
+ catch (err) {
23
+ if (err.code != 'ENOENT') {
30
24
  throw err;
31
25
  }
32
26
  }
33
27
  };
34
-
35
28
  const cleanUpDuplicate = async () => {
36
- if(!dupFile) {
29
+ if (!dupFile) {
37
30
  return;
38
31
  }
39
32
 
40
- dupFile.destroy();
33
+ dupFile.destroy();
41
34
 
42
35
  try {
43
36
  await fse.remove(dupFile.path);
44
37
  }
45
- catch(err) {
46
- if(err.code != 'ENOENT') {
38
+ catch (err) {
39
+ if (err.code != 'ENOENT') {
47
40
  throw err;
48
41
  }
49
42
  }
50
43
 
51
44
  dupFile = null;
52
45
  };
53
-
54
46
  const prepareApprovalInfo = () => {
55
47
  try {
56
48
  return JSON.parse(req.body.approvalInfo);
57
49
  }
58
- catch(err) {
50
+ catch (err) {
59
51
  return null;
60
52
  }
61
53
  };
@@ -70,7 +62,7 @@ module.exports.addSong = node => {
70
62
  const priority = parseInt(req.body.priority || 0);
71
63
  node.songPriorityTest({ priority, controlled, exported });
72
64
  let tags = await utils.getSongTags(file);
73
- node.songTitleTest(tags.fullTitle);
65
+ node.songTitleTest(tags.fullTitle);
74
66
  let fileInfo = await utils.getFileInfo(file);
75
67
  dupFileInfo = fileInfo;
76
68
  await node.fileAvailabilityTest(fileInfo);
@@ -78,9 +70,9 @@ module.exports.addSong = node => {
78
70
  let fileHashToRemove = '';
79
71
  let addFile = true;
80
72
  let document;
81
-
82
- HANDLE_MUSIC_DOCUMENT: if(existent) {
83
- if(typeof existent.fileHash != 'string' || !await node.hasFile(existent.fileHash)) {
73
+
74
+ HANDLE_MUSIC_DOCUMENT: if (existent) {
75
+ if (typeof existent.fileHash != 'string' || !await node.hasFile(existent.fileHash)) {
84
76
  await node.db.deleteDocument(existent);
85
77
  existent = null;
86
78
  break HANDLE_MUSIC_DOCUMENT;
@@ -91,11 +83,9 @@ module.exports.addSong = node => {
91
83
  const newFilePath = file.path;
92
84
  const currentPriority = existent.priority || 0;
93
85
 
94
- if(
95
- (controlled && !exported) ||
86
+ if ((controlled && !exported) ||
96
87
  priority > currentPriority ||
97
- (priority == currentPriority && !await node.checkSongRelevance(currentFilePath, newFilePath))
98
- ) {
88
+ (priority == currentPriority && !await node.checkSongRelevance(currentFilePath, newFilePath))) {
99
89
  filePath = newFilePath;
100
90
  tags = utils.mergeSongTags(await utils.getSongTags(currentFilePath), tags);
101
91
  existent.priority = priority;
@@ -109,23 +99,23 @@ module.exports.addSong = node => {
109
99
  filePath = await utils.setSongTags(filePath, tags);
110
100
  fileInfo = await utils.getFileInfo(filePath);
111
101
  await node.fileAvailabilityTest(fileInfo);
112
- existent.title = tags.fullTitle;
113
-
114
- if(existent.fileHash != fileInfo.hash) {
102
+ existent.title = tags.fullTitle;
103
+
104
+ if (existent.fileHash != fileInfo.hash) {
115
105
  fileHashToRemove = existent.fileHash;
116
106
  existent.fileHash = fileInfo.hash;
117
- }
107
+ }
118
108
  else {
119
109
  addFile = false;
120
110
  }
121
111
  }
122
-
112
+
123
113
  await node.withAddingFile(fileInfo.hash, async () => {
124
- if(addFile) {
114
+ if (addFile) {
125
115
  await node.addFileToStorage(filePath, fileInfo.hash, { copy: true });
126
116
  }
127
-
128
- if(!existent) {
117
+
118
+ if (!existent) {
129
119
  document = await node.db.addMusicDocument({
130
120
  title: tags.fullTitle,
131
121
  fileHash: fileInfo.hash,
@@ -135,42 +125,43 @@ module.exports.addSong = node => {
135
125
  else {
136
126
  document = await node.db.updateMusicDocument(existent);
137
127
  }
138
-
139
- if(fileHashToRemove) {
128
+
129
+ if (fileHashToRemove) {
140
130
  await node.removeFileFromStorage(fileHashToRemove);
141
131
  }
142
- });
132
+ });
133
+
143
134
  const audioLink = await node.createSongAudioLink(document);
144
135
  const coverLink = await node.createSongCoverLink(document);
145
-
146
- if(duplicates.length) {
136
+
137
+ if (duplicates.length) {
147
138
  const dupPath = path.join(node.tempPath, crypto.randomBytes(21).toString('hex'));
148
139
  await fse.copy(file.path, dupPath);
149
- dupFile = await fs.createReadStream(dupPath);
140
+ dupFile = await fse.createReadStream(dupPath);
150
141
  node.duplicateSong(duplicates, dupFile, dupFileInfo, { controlled, priority, approvalInfo })
151
- .then(cleanUpDuplicate)
152
- .catch(err => {
153
- node.logger.error(err.stack);
154
- return cleanUpDuplicate();
155
- })
156
- .catch(err => {
157
- node.logger.error(err.stack);
158
- });
142
+ .then(cleanUpDuplicate)
143
+ .catch(err => {
144
+ node.logger.error(err.stack);
145
+ return cleanUpDuplicate();
146
+ })
147
+ .catch(err => {
148
+ node.logger.error(err.stack);
149
+ });
159
150
  }
160
151
 
161
152
  await cleanUp();
162
- res.send({
153
+ res.send({
163
154
  fileHash: document.fileHash,
164
- audioLink,
165
- coverLink,
155
+ audioLink,
156
+ coverLink,
166
157
  title: tags.fullTitle,
167
- tags: _.omit(tags, 'APIC'),
158
+ tags: omit(tags, 'APIC'),
168
159
  priority: document.priority || 0
169
- });
160
+ });
170
161
  }
171
- catch(err) {
162
+ catch (err) {
172
163
  await cleanUp();
173
164
  next(err);
174
- }
175
- }
176
- };
165
+ }
166
+ };
167
+ };
@@ -1,23 +1,23 @@
1
- const controllers = require('./controllers');
2
- const midds = require('../../midds');
1
+ import * as controllers from "./controllers.js";
2
+ import midds from "../../midds.js";
3
3
 
4
- module.exports = [
4
+ export default [
5
5
  /**
6
6
  * Add the song
7
- *
7
+ *
8
8
  * @api {post} /api/node/add-song/
9
- * @apiParam {fs.ReadStream|string} file
9
+ * @apiParam {fse.ReadStream|string} file
10
10
  */
11
- {
11
+ {
12
12
  name: 'addSong',
13
- method: 'post',
13
+ method: 'post',
14
14
  url: '/add-song',
15
15
  fn: [
16
- midds.requestQueueSong,
17
- midds.filesFormData,
16
+ midds.requestQueueSong,
17
+ midds.filesFormData,
18
18
  midds.songAdditionControl,
19
19
  midds.prepareFileToStore,
20
20
  controllers.addSong
21
21
  ]
22
22
  }
23
- ];
23
+ ];
@@ -1 +1 @@
1
- module.exports = [];
1
+ export default [];
@@ -1,20 +1,17 @@
1
- /**
2
- * Remove the song
3
- */
4
- module.exports.removeSong = node => {
1
+ export const removeSong = node => {
5
2
  return async (req, res, next) => {
6
3
  try {
7
4
  let removed = false;
8
5
 
9
- if(req.document && req.document.fileHash && await node.hasFile(req.document.fileHash)) {
6
+ if (req.document && req.document.fileHash && await node.hasFile(req.document.fileHash)) {
10
7
  await node.removeFileFromStorage(req.document.fileHash);
11
8
  removed = true;
12
9
  }
13
-
10
+
14
11
  res.send({ removed: +removed });
15
12
  }
16
- catch(err) {
13
+ catch (err) {
17
14
  next(err);
18
- }
19
- }
20
- };
15
+ }
16
+ };
17
+ };
@@ -1,16 +1,16 @@
1
- const controllers = require('./controllers');
2
- const midds = require('../../midds');
1
+ import * as controllers from "./controllers.js";
2
+ import midds from "../../midds.js";
3
3
 
4
- module.exports = [
4
+ export default [
5
5
  /**
6
6
  * Remove the song
7
- *
7
+ *
8
8
  * @api {post} /api/slave/remove-song
9
9
  * @apiParam {string} title - song title
10
10
  */
11
- {
11
+ {
12
12
  name: 'removeSong',
13
- method: 'post',
13
+ method: 'post',
14
14
  url: '/remove-song',
15
15
  fn: [
16
16
  midds.requestQueueSong,