museria 0.2.49 → 0.3.1
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.
- package/.eslintrc +10 -2
- package/.github/workflows/build.yml +3 -3
- package/.github/workflows/publish.yml +3 -3
- package/README.md +55 -59
- package/bin/actions.js +28 -28
- package/bin/index.js +4 -4
- package/bin/runner.js +1 -1
- package/bin/utils.js +6 -2
- package/dist/client/museria.client.js +7 -7
- package/dist/face/45a265d0f07b31cde85f.ttf +0 -0
- package/dist/face/6205fd00fb1b573e9f0f.ttf +0 -0
- package/dist/face/8d3cabfc66809162fb4d.woff2 +0 -0
- package/dist/face/fb8184add5a3101ad0a3.woff2 +0 -0
- package/dist/face/museria.face.js +33 -13
- package/dist/face/style.css +13 -11
- package/package.json +41 -40
- package/src/browser/client/index.js +2 -1
- package/src/browser/face/client.js +2 -1
- package/src/browser/face/controllers/app/app.html +77 -69
- package/src/browser/face/controllers/app/app.js +14 -7
- package/src/browser/face/controllers/app/app.scss +2 -22
- package/src/browser/face/index.js +3 -3
- package/src/browser/face/styles/main.scss +91 -11
- package/src/browser/face/styles/vars.scss +0 -1
- package/src/client.js +73 -74
- package/src/collection/transports/music/index.js +20 -18
- package/src/db/transports/database/index.js +7 -5
- package/src/db/transports/loki/index.js +30 -25
- package/src/errors.js +2 -1
- package/src/index.js +8 -6
- package/src/node.js +312 -323
- package/src/schema.js +27 -29
- package/src/server/transports/express/api/butler/controllers.js +7 -10
- package/src/server/transports/express/api/butler/routes.js +5 -5
- package/src/server/transports/express/api/master/controllers.js +7 -10
- package/src/server/transports/express/api/master/routes.js +5 -5
- package/src/server/transports/express/api/node/controllers.js +52 -61
- package/src/server/transports/express/api/node/routes.js +10 -10
- package/src/server/transports/express/api/routes.js +1 -1
- package/src/server/transports/express/api/slave/controllers.js +7 -10
- package/src/server/transports/express/api/slave/routes.js +6 -6
- package/src/server/transports/express/client/controllers.js +40 -61
- package/src/server/transports/express/client/routes.js +33 -39
- package/src/server/transports/express/controllers.js +10 -21
- package/src/server/transports/express/index.js +23 -20
- package/src/server/transports/express/midds.js +67 -67
- package/src/server/transports/express/routes.js +12 -12
- package/src/utils.js +175 -184
- package/test/client.js +311 -305
- package/test/db/database.js +32 -28
- package/test/db/loki.js +78 -74
- package/test/group.js +161 -156
- package/test/index.js +20 -10
- package/test/node.js +461 -460
- package/test/routes.js +404 -399
- package/test/server/express.js +35 -31
- package/test/services.js +25 -18
- package/test/tools.js +8 -6
- package/test/utils.js +236 -234
- package/webpack.client.js +9 -7
- package/webpack.face.js +8 -6
- package/dist/face/fa-brands-400.eot +0 -0
- package/dist/face/fa-brands-400.svg +0 -3717
- package/dist/face/fa-brands-400.ttf +0 -0
- package/dist/face/fa-brands-400.woff +0 -0
- package/dist/face/fa-brands-400.woff2 +0 -0
- package/dist/face/fa-solid-900.eot +0 -0
- package/dist/face/fa-solid-900.svg +0 -5034
- package/dist/face/fa-solid-900.ttf +0 -0
- package/dist/face/fa-solid-900.woff +0 -0
- package/dist/face/fa-solid-900.woff2 +0 -0
- /package/dist/face/{open-sans.ttf → 17e98b9e5586529b13cc.ttf} +0 -0
- /package/dist/face/{proxima-nova.ttf → 326601dfabd91e3f016c.ttf} +0 -0
- /package/dist/face/{logo.svg → ee9c6af64aa224827cec.svg} +0 -0
package/test/client.js
CHANGED
@@ -1,362 +1,368 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
describe('Client', () => {
|
10
|
-
let client;
|
11
|
-
let node;
|
12
|
-
|
13
|
-
before(async function() {
|
14
|
-
node = new Node(await tools.createNodeOptions());
|
15
|
-
await node.init();
|
16
|
-
});
|
1
|
+
import { assert } from "chai";
|
2
|
+
import fse from "fs-extra";
|
3
|
+
import path from "path";
|
4
|
+
import node from "../src/node.js";
|
5
|
+
import client from "../src/client.js";
|
6
|
+
import utils from "../src/utils.js";
|
7
|
+
import tools from "./tools.js";
|
17
8
|
|
18
|
-
|
19
|
-
|
20
|
-
});
|
9
|
+
const Node = node();
|
10
|
+
const Client = client();
|
21
11
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
});
|
27
|
-
});
|
12
|
+
export default function () {
|
13
|
+
describe('Client', () => {
|
14
|
+
let client;
|
15
|
+
let node;
|
28
16
|
|
29
|
-
|
30
|
-
|
31
|
-
await
|
17
|
+
before(async function () {
|
18
|
+
node = new Node(await tools.createNodeOptions());
|
19
|
+
await node.init();
|
32
20
|
});
|
33
|
-
});
|
34
21
|
|
35
|
-
|
36
|
-
|
37
|
-
const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle: 'wrong' });
|
38
|
-
try {
|
39
|
-
await client.addSong(file);
|
40
|
-
throw new Error('Fail');
|
41
|
-
}
|
42
|
-
catch(err) {
|
43
|
-
assert.isOk(err.message.match('Wrong song title'));
|
44
|
-
}
|
22
|
+
after(async function () {
|
23
|
+
await node.deinit();
|
45
24
|
});
|
46
25
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
TIT3: 'x'
|
53
|
-
});
|
54
|
-
const result = await client.addSong(file);
|
55
|
-
const doc = await node.db.getMusicByPk(result.title);
|
56
|
-
assert.equal(utils.beautifySongTitle(title), result.title, 'check the title');
|
57
|
-
assert.equal(result.tags.TIT3, 'x', 'check the tags');
|
58
|
-
assert.isNotNull(doc, 'check the database');
|
59
|
-
assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
|
60
|
-
assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
|
61
|
-
assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
|
26
|
+
describe('instance creation', function () {
|
27
|
+
it('should create an instance', async function () {
|
28
|
+
const options = await tools.createClientOptions({ address: node.address });
|
29
|
+
assert.doesNotThrow(() => client = new Client(options));
|
30
|
+
});
|
62
31
|
});
|
63
|
-
});
|
64
32
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
throw new Error('Fail');
|
70
|
-
}
|
71
|
-
catch(err) {
|
72
|
-
assert.isOk(err.message.match('Wrong song title'));
|
73
|
-
}
|
33
|
+
describe('.init()', function () {
|
34
|
+
it('should not throw an exception', async function () {
|
35
|
+
await client.init();
|
36
|
+
});
|
74
37
|
});
|
75
38
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
39
|
+
describe('.addSong()', function () {
|
40
|
+
it('should not add the song with a wrong title', async function () {
|
41
|
+
const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle: 'wrong' });
|
42
|
+
|
43
|
+
try {
|
44
|
+
await client.addSong(file);
|
45
|
+
throw new Error('Fail');
|
46
|
+
}
|
47
|
+
catch (err) {
|
48
|
+
assert.isOk(err.message.match('Wrong song title'));
|
49
|
+
}
|
50
|
+
});
|
80
51
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
52
|
+
it('should add the song', async () => {
|
53
|
+
const title = 'artist - title';
|
54
|
+
const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), {
|
55
|
+
fullTitle: title,
|
56
|
+
APIC: path.join(tools.tmpPath, 'cover.jpg'),
|
57
|
+
TIT3: 'x'
|
58
|
+
});
|
59
|
+
const result = await client.addSong(file);
|
60
|
+
const doc = await node.db.getMusicByPk(result.title);
|
61
|
+
assert.equal(utils.beautifySongTitle(title), result.title, 'check the title');
|
62
|
+
assert.equal(result.tags.TIT3, 'x', 'check the tags');
|
63
|
+
assert.isNotNull(doc, 'check the database');
|
64
|
+
assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
|
65
|
+
assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
|
66
|
+
assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
|
67
|
+
});
|
90
68
|
});
|
91
|
-
});
|
92
69
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
70
|
+
describe('.getSongInfo()', function () {
|
71
|
+
it('should throw an error because of a wrong title', async function () {
|
72
|
+
try {
|
73
|
+
await client.getSongInfo('wrong');
|
74
|
+
throw new Error('Fail');
|
75
|
+
}
|
76
|
+
catch (err) {
|
77
|
+
assert.isOk(err.message.match('Wrong song title'));
|
78
|
+
}
|
79
|
+
});
|
98
80
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
assert.lengthOf(songs, 1, 'check the length');
|
104
|
-
assert.isOk(result.title.toLowerCase().match(str.toLowerCase()), 'check the title');
|
105
|
-
assert.equal(result.tags.TIT3, 'x', 'check the tags');
|
106
|
-
assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
|
107
|
-
assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
|
108
|
-
});
|
109
|
-
});
|
81
|
+
it('should return an empty array', async function () {
|
82
|
+
const info = await client.getSongInfo('unexistent - song');
|
83
|
+
assert.lengthOf(info, 0);
|
84
|
+
});
|
110
85
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
86
|
+
it('should return the info', async function () {
|
87
|
+
const title = 'artist - title';
|
88
|
+
const info = await client.getSongInfo(title);
|
89
|
+
const result = info[0];
|
90
|
+
assert.lengthOf(info, 1, 'check the length');
|
91
|
+
assert.equal(utils.beautifySongTitle(title), result.title, 'check the title');
|
92
|
+
assert.equal(result.tags.TIT3, 'x', 'check the tags');
|
93
|
+
assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
|
94
|
+
assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
|
95
|
+
});
|
115
96
|
});
|
116
97
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
assert.isOk(result.title.toLowerCase().match(str), 'check the title');
|
123
|
-
assert.equal(result.tags.TIT3, 'x', 'check the tags');
|
124
|
-
assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
|
125
|
-
assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
|
126
|
-
});
|
127
|
-
});
|
98
|
+
describe('.findSongs()', function () {
|
99
|
+
it('should return an empty array', async function () {
|
100
|
+
const songs = await client.findSongs('unexistent');
|
101
|
+
assert.lengthOf(songs, 0);
|
102
|
+
});
|
128
103
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
assert.
|
137
|
-
|
104
|
+
it('should return the songs', async function () {
|
105
|
+
const str = 'arTist';
|
106
|
+
const songs = await client.findSongs(str);
|
107
|
+
const result = songs[0];
|
108
|
+
assert.lengthOf(songs, 1, 'check the length');
|
109
|
+
assert.isOk(result.title.toLowerCase().match(str.toLowerCase()), 'check the title');
|
110
|
+
assert.equal(result.tags.TIT3, 'x', 'check the tags');
|
111
|
+
assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
|
112
|
+
assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
|
113
|
+
});
|
138
114
|
});
|
139
115
|
|
140
|
-
|
141
|
-
|
142
|
-
|
116
|
+
describe('.findArtistSongs()', function () {
|
117
|
+
it('should return an empty array', async function () {
|
118
|
+
const songs = await client.findArtistSongs('art');
|
119
|
+
assert.lengthOf(songs, 0);
|
120
|
+
});
|
143
121
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
122
|
+
it('should return the songs', async function () {
|
123
|
+
const str = 'artist';
|
124
|
+
const songs = await client.findArtistSongs(str);
|
125
|
+
const result = songs[0];
|
126
|
+
assert.lengthOf(songs, 1, 'check the length');
|
127
|
+
assert.isOk(result.title.toLowerCase().match(str), 'check the title');
|
128
|
+
assert.equal(result.tags.TIT3, 'x', 'check the tags');
|
129
|
+
assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
|
130
|
+
assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
|
131
|
+
});
|
151
132
|
});
|
152
|
-
});
|
153
133
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
134
|
+
describe('.getSong()', function () {
|
135
|
+
it('should throw an error because of a wrong title', async function () {
|
136
|
+
try {
|
137
|
+
await client.getSong('wrong');
|
138
|
+
throw new Error('Fail');
|
139
|
+
}
|
140
|
+
catch (err) {
|
141
|
+
assert.isOk(err.message.match('Wrong song title'));
|
142
|
+
}
|
143
|
+
});
|
164
144
|
|
165
|
-
|
166
|
-
|
167
|
-
|
145
|
+
it('should return null', async function () {
|
146
|
+
assert.isNull(await client.getSong('unexistent - song'));
|
147
|
+
});
|
168
148
|
|
169
|
-
|
170
|
-
|
171
|
-
|
149
|
+
it('should return the right info', async function () {
|
150
|
+
const title = 'artist - title';
|
151
|
+
const info = await client.getSong(title);
|
152
|
+
assert.equal(utils.beautifySongTitle(title), info.title, 'check the title');
|
153
|
+
assert.equal(info.tags.TIT3, 'x', 'check the tags');
|
154
|
+
assert.isTrue(utils.isValidSongAudioLink(info.audioLink), 'check the audio link');
|
155
|
+
assert.isTrue(utils.isValidSongCoverLink(info.coverLink), 'check the cover link');
|
156
|
+
});
|
172
157
|
});
|
173
|
-
});
|
174
158
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
159
|
+
describe('.getSongAudioLink()', function () {
|
160
|
+
it('should throw an error because of a wrong title', async function () {
|
161
|
+
try {
|
162
|
+
await client.getSongAudioLink('wrong');
|
163
|
+
throw new Error('Fail');
|
164
|
+
}
|
165
|
+
catch (err) {
|
166
|
+
assert.isOk(err.message.match('Wrong song title'));
|
167
|
+
}
|
168
|
+
});
|
185
169
|
|
186
|
-
|
187
|
-
|
188
|
-
|
170
|
+
it('should return an empty string', async function () {
|
171
|
+
assert.isEmpty(await client.getSongAudioLink('unexistent - song'));
|
172
|
+
});
|
189
173
|
|
190
|
-
|
191
|
-
|
192
|
-
|
174
|
+
it('should return the link', async function () {
|
175
|
+
const link = await client.getSongAudioLink('artist - title');
|
176
|
+
assert.isTrue(utils.isValidSongAudioLink(link));
|
177
|
+
});
|
193
178
|
});
|
194
|
-
});
|
195
179
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
180
|
+
describe('.getSongCoverLink()', function () {
|
181
|
+
it('should throw an error because of a wrong title', async function () {
|
182
|
+
try {
|
183
|
+
await client.getSongCoverLink('wrong');
|
184
|
+
throw new Error('Fail');
|
185
|
+
}
|
186
|
+
catch (err) {
|
187
|
+
assert.isOk(err.message.match('Wrong song title'));
|
188
|
+
}
|
189
|
+
});
|
206
190
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
throw new Error('Fail');
|
211
|
-
}
|
212
|
-
catch(err) {
|
213
|
-
assert.isOk(err.message.match('Link for song'));
|
214
|
-
}
|
215
|
-
});
|
191
|
+
it('should return an empty string', async function () {
|
192
|
+
assert.isEmpty(await client.getSongCoverLink('unexistent - song'));
|
193
|
+
});
|
216
194
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
const buffer = await client.getSongAudioToBuffer(title);
|
222
|
-
assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
|
195
|
+
it('should return the link', async function () {
|
196
|
+
const link = await client.getSongCoverLink('artist - title');
|
197
|
+
assert.isTrue(utils.isValidSongCoverLink(link));
|
198
|
+
});
|
223
199
|
});
|
224
|
-
});
|
225
200
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
201
|
+
describe('.getSongAudioToBuffer()', function () {
|
202
|
+
it('should throw an error because of a wrong title', async function () {
|
203
|
+
try {
|
204
|
+
await client.getSongAudioToBuffer('wrong');
|
205
|
+
throw new Error('Fail');
|
206
|
+
}
|
207
|
+
catch (err) {
|
208
|
+
assert.isOk(err.message.match('Wrong song title'));
|
209
|
+
}
|
210
|
+
});
|
236
211
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
212
|
+
it('should throw an error because of wrong link', async function () {
|
213
|
+
try {
|
214
|
+
await client.getSongAudioToBuffer('unexistent - song');
|
215
|
+
throw new Error('Fail');
|
216
|
+
}
|
217
|
+
catch (err) {
|
218
|
+
assert.isOk(err.message.match('Link for song'));
|
219
|
+
}
|
220
|
+
});
|
246
221
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
222
|
+
it('should be the same buffer', async function () {
|
223
|
+
const title = 'artist - title';
|
224
|
+
const doc = await node.db.getMusicByPk(title);
|
225
|
+
const originalBuffer = await fse.readFile(node.getFilePath(doc.fileHash));
|
226
|
+
const buffer = await client.getSongAudioToBuffer(title);
|
227
|
+
assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
|
228
|
+
});
|
253
229
|
});
|
254
|
-
});
|
255
230
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
231
|
+
describe('.getSongCoverToBuffer()', function () {
|
232
|
+
it('should throw an error because of a wrong title', async function () {
|
233
|
+
try {
|
234
|
+
await client.getSongCoverToBuffer('wrong');
|
235
|
+
throw new Error('Fail');
|
236
|
+
}
|
237
|
+
catch (err) {
|
238
|
+
assert.isOk(err.message.match('Wrong song title'));
|
239
|
+
}
|
240
|
+
});
|
266
241
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
242
|
+
it('should throw an error because of wrong link', async function () {
|
243
|
+
try {
|
244
|
+
await client.getSongCoverToBuffer('unexistent - song');
|
245
|
+
throw new Error('Fail');
|
246
|
+
}
|
247
|
+
catch (err) {
|
248
|
+
assert.isOk(err.message.match('Link for song'));
|
249
|
+
}
|
250
|
+
});
|
276
251
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
|
252
|
+
it('should be the same buffer', async function () {
|
253
|
+
const title = 'artist - title';
|
254
|
+
const doc = await node.db.getMusicByPk(title);
|
255
|
+
const originalBuffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
|
256
|
+
const buffer = await client.getSongCoverToBuffer(title);
|
257
|
+
assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
|
258
|
+
});
|
285
259
|
});
|
286
|
-
});
|
287
260
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
261
|
+
describe('.getSongAudioToPath()', function () {
|
262
|
+
it('should throw an error because of a wrong title', async function () {
|
263
|
+
try {
|
264
|
+
await client.getSongAudioToPath('wrong');
|
265
|
+
throw new Error('Fail');
|
266
|
+
}
|
267
|
+
catch (err) {
|
268
|
+
assert.isOk(err.message.match('Wrong song title'));
|
269
|
+
}
|
270
|
+
});
|
298
271
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
272
|
+
it('should throw an error because of wrong link', async function () {
|
273
|
+
try {
|
274
|
+
await client.getSongAudioToPath('unexistent - song');
|
275
|
+
throw new Error('Fail');
|
276
|
+
}
|
277
|
+
catch (err) {
|
278
|
+
assert.isOk(err.message.match('Link for song'));
|
279
|
+
}
|
280
|
+
});
|
308
281
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
282
|
+
it('should save the file', async function () {
|
283
|
+
const filePath = path.join(tools.tmpPath, 'audio-saved.mp3');
|
284
|
+
const title = 'artist - title';
|
285
|
+
const doc = await node.db.getMusicByPk(title);
|
286
|
+
const originalBuffer = await fse.readFile(node.getFilePath(doc.fileHash));
|
287
|
+
await client.getSongAudioToPath(title, filePath);
|
288
|
+
const buffer = await fse.readFile(filePath);
|
289
|
+
assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
|
290
|
+
});
|
317
291
|
});
|
318
|
-
});
|
319
292
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
293
|
+
describe('.getSongCoverToPath()', function () {
|
294
|
+
it('should throw an error because of a wrong title', async function () {
|
295
|
+
try {
|
296
|
+
await client.getSongCoverToPath('wrong');
|
297
|
+
throw new Error('Fail');
|
298
|
+
}
|
299
|
+
catch (err) {
|
300
|
+
assert.isOk(err.message.match('Wrong song title'));
|
301
|
+
}
|
302
|
+
});
|
330
303
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
304
|
+
it('should throw an error because of wrong link', async function () {
|
305
|
+
try {
|
306
|
+
await client.getSongCoverToPath('unexistent - song');
|
307
|
+
throw new Error('Fail');
|
308
|
+
}
|
309
|
+
catch (err) {
|
310
|
+
assert.isOk(err.message.match('Link for song'));
|
311
|
+
}
|
312
|
+
});
|
313
|
+
|
314
|
+
it('should save the file', async function () {
|
315
|
+
const filePath = path.join(tools.tmpPath, '/cover-saved.jpg');
|
316
|
+
const title = 'artist - title';
|
317
|
+
const doc = await node.db.getMusicByPk(title);
|
318
|
+
const originalBuffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
|
319
|
+
await client.getSongCoverToPath(title, filePath);
|
320
|
+
const buffer = await fse.readFile(filePath);
|
321
|
+
assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
|
322
|
+
});
|
338
323
|
});
|
339
|
-
});
|
340
324
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
325
|
+
describe('.removeSong()', function () {
|
326
|
+
it('should throw an error because of a wrong title', async function () {
|
327
|
+
try {
|
328
|
+
await client.getSongAudioLink('wrong');
|
329
|
+
throw new Error('Fail');
|
330
|
+
}
|
331
|
+
catch (err) {
|
332
|
+
assert.isOk(err.message.match('Wrong song title'));
|
333
|
+
}
|
334
|
+
});
|
335
|
+
|
336
|
+
it('should return the link', async function () {
|
337
|
+
const title = 'artist - title';
|
338
|
+
const doc = await node.db.getMusicByPk(title);
|
339
|
+
const res = await client.removeSong(title);
|
340
|
+
assert.equal(res.removed, 1, 'check the result');
|
341
|
+
assert.isNull(await node.db.getMusicByPk(title), 'check the database');
|
342
|
+
assert.isFalse(await node.hasFile(doc.fileHash), 'check the file');
|
343
|
+
});
|
346
344
|
});
|
347
|
-
});
|
348
345
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
346
|
+
describe('.createRequestedSongAudioLink()', () => {
|
347
|
+
it('should return the right link', async () => {
|
348
|
+
const title = 'artist-title';
|
349
|
+
const link = client.createRequestedSongAudioLink(title);
|
350
|
+
assert.equal(link, `${client.getRequestProtocol()}://${client.workerAddress}/client/request-song?type=audio&title=${title}`);
|
351
|
+
});
|
354
352
|
});
|
355
|
-
});
|
356
353
|
|
357
|
-
|
358
|
-
|
359
|
-
|
354
|
+
describe('.createRequestedSongCoverLink()', () => {
|
355
|
+
it('should return the right link', async () => {
|
356
|
+
const title = 'artist-title';
|
357
|
+
const link = client.createRequestedSongCoverLink(title);
|
358
|
+
assert.equal(link, `${client.getRequestProtocol()}://${client.workerAddress}/client/request-song?type=cover&title=${title}`);
|
359
|
+
});
|
360
|
+
});
|
361
|
+
|
362
|
+
describe('.deinit()', function () {
|
363
|
+
it('should not throw an exception', async function () {
|
364
|
+
await client.deinit();
|
365
|
+
});
|
360
366
|
});
|
361
367
|
});
|
362
|
-
}
|
368
|
+
}
|