Skip to content

Commit db8edbc

Browse files
committed
Merge branch 'default' into hcaptcha
2 parents b6bb729 + dbc96de commit db8edbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1099
-324
lines changed

Diff for: .babelrc.js

-13
This file was deleted.

Diff for: .eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/example

Diff for: .eslintrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,21 @@ module.exports = {
88
'no-param-reassign': ['error', { props: false }],
99
// I disagree that this is bad
1010
'max-classes-per-file': 'off',
11+
// Allow `for..of`
12+
'no-restricted-syntax': [
13+
'error',
14+
{
15+
selector: 'ForInStatement',
16+
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
17+
},
18+
{
19+
selector: 'LabeledStatement',
20+
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
21+
},
22+
{
23+
selector: 'WithStatement',
24+
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
25+
},
26+
],
1127
},
1228
};

Diff for: .github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
open-pull-requests-limit: 10

Diff for: .github/workflows/update-ns.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Publish Updated Config Schemas
2+
3+
on:
4+
push:
5+
branches: [default]
6+
# Maybe should do it on release instead?
7+
# release:
8+
# types: [published]
9+
10+
jobs:
11+
dispatch:
12+
name: Dispatch
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: peter-evans/repository-dispatch@v1
16+
with:
17+
repository: u-wave/federation
18+
token: ${{secrets.SCHEMA_ACCESS_TOKEN}}
19+
event-type: update-config-schemas

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ node_modules
3131
/dist
3232
.eslintcache
3333
package-lock.json
34+
.env

Diff for: .mocharc.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ const ms = require('ms');
33
module.exports = {
44
timeout: ms('30 seconds'),
55
recursive: 'test/',
6+
require: 'make-promises-safe',
67
};

Diff for: CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
44

55
This project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## Unreleased
8+
9+
The `u-wave-http-api` package has been merged into `u-wave-core`. This package now contains both the library and the HTTP and WebSocket API for üWave servers.
10+
11+
Features:
12+
* **Breaking:** Merge `u-wave-http-api`. (#333)
13+
* Automatically activate a user's first playlist. (#219)
14+
* Implement votes using HTTP requests. (#361)
15+
* Older client versions can still use WebSocket votes.
16+
* Find playlists containing a particular media. (#374)
17+
18+
Internal:
19+
* Add `uw.models` property for easier mongoose model access. (#283)
20+
* **Breaking:** Small changes to DB option handling. (#264)
21+
* **Breaking:** Raise supported Node.js version to 10+. (#342)
22+
* Make `getPlaylistItems` faster with a single query. (#351, #370)
23+
* Remove use of `p-props`. (#371)
24+
725
## 0.4.1 / 17 Jul 2018
826

927
Bugfixes:

Diff for: README.md

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ Core library for üWave, the collaborative listening platform.
55
[Getting Started](#getting-started) - [API](#api) - [Building](#contributing) -
66
[License](#license)
77

8-
> Note: üWave is still under development. Particularly the `u-wave-core` and
9-
> `u-wave-api-v1` modules will change a lot before the "official" 1.0.0 release.
10-
> Make sure to always upgrade both of them at the same time.
11-
128
## Getting Started
139

1410
üWave consists of three parts: the core library, the HTTP API, and the web

Diff for: bin/u-wave-core

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env node
2+
3+
require('make-promises-safe');
4+
const explain = require('explain-error');
5+
const envSchema = require('env-schema');
6+
const ytSource = require('u-wave-source-youtube');
7+
const scSource = require('u-wave-source-soundcloud');
8+
const uwave = require('..');
9+
const pkg = require('../package.json');
10+
const argv = require('minimist')(process.argv.slice(2));
11+
12+
if (argv.h || argv.help) {
13+
console.log('u-wave-core');
14+
console.log('Version', pkg.version);
15+
console.log();
16+
console.log('Environment Variables:');
17+
console.log(' SECRET');
18+
console.log(' A secret key used for encrypting passwords. Must be a 64-character hexadecimal string (= 256 bits).');
19+
console.log(' PORT');
20+
console.log(' Port to listen on. Defaults to 6042.');
21+
console.log(' REDIS_URL');
22+
console.log(' URL of the Redis instance to connect to. Defaults to redis://localhost:6379/.');
23+
console.log(' MONGODB_URL');
24+
console.log(' URL of the MongoDB database to use. Defaults to mongodb://localhost:27017/uwave.');
25+
console.log();
26+
process.exit(0);
27+
}
28+
29+
const config = envSchema({
30+
schema: {
31+
type: 'object',
32+
required: ['SECRET'],
33+
properties: {
34+
PORT: {
35+
type: 'number',
36+
default: 6042,
37+
},
38+
REDIS_URL: {
39+
type: 'string',
40+
format: 'uri',
41+
default: 'redis://localhost:6379',
42+
},
43+
MONGODB_URL: {
44+
type: 'string',
45+
format: 'uri',
46+
default: 'mongodb://localhost:27017/uwave',
47+
},
48+
SECRET: {
49+
type: 'string',
50+
regex: '^[0-9a-fA-F]+$',
51+
min: 64,
52+
max: 64,
53+
},
54+
YOUTUBE_API_KEY: {
55+
type: 'string',
56+
},
57+
SOUNDCLOUD_API_KEY: {
58+
type: 'string',
59+
},
60+
},
61+
},
62+
});
63+
64+
const port = Number(argv.port || config.PORT);
65+
66+
const secret = Buffer.from(config.SECRET, 'hex');
67+
68+
const uw = uwave({
69+
port,
70+
redis: config.REDIS_URL,
71+
mongo: config.MONGODB_URL,
72+
secret,
73+
});
74+
75+
uw.express.set('json spaces', 2);
76+
77+
uw.on('mongoError', (err) => {
78+
throw explain(err, 'Could not connect to MongoDB. Is it installed and running?');
79+
});
80+
81+
uw.on('redisError', (err) => {
82+
throw explain(err, 'Could not connect to the Redis server. Is it installed and running?');
83+
});
84+
85+
if (config.YOUTUBE_API_KEY) {
86+
uw.source(ytSource, {
87+
key: config.YOUTUBE_API_KEY,
88+
});
89+
}
90+
if (config.SOUNDCLOUD_API_KEY) {
91+
uw.source(scSource, {
92+
key: config.SOUNDCLOUD_API_KEY,
93+
});
94+
}
95+
96+
uw.listen(port).then(() => {
97+
console.log(`Now listening on ${port}`);
98+
}, (error) => {
99+
console.error(error.stack);
100+
process.exit(1);
101+
});

Diff for: dev/dev-server-config.json

-11
This file was deleted.

Diff for: dev/u-wave-dev-server

+36-38
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
#!/usr/bin/env node
22

3+
require('make-promises-safe');
34
const { Buffer } = require('buffer');
4-
const http = require('http');
55
const argv = require('minimist')(process.argv.slice(2));
66
const concat = require('concat-stream');
77
const explain = require('explain-error');
88
const announce = require('u-wave-announce');
99
const ytSource = require('u-wave-source-youtube');
1010
const scSource = require('u-wave-source-soundcloud');
11-
const hcaptchaTestKeys = require('hcaptcha-test-keys');
12-
const express = require('express');
13-
const mailDebug = require('debug')('uwave:mail');
1411
const debug = require('debug')('uwave:dev-server');
15-
const config = require('./dev-server-config.json');
12+
const dotenv = require('dotenv');
13+
14+
dotenv.config();
1615

1716
const testTransport = {
1817
name: 'test',
1918
version: '0.0.0',
2019
send(mail, callback) {
2120
mail.message.createReadStream().pipe(concat((message) => {
22-
mailDebug(mail.message.getEnvelope().to, message.toString('utf8'));
21+
debug(mail.message.getEnvelope().to, message.toString('utf8'));
2322
callback(null, {
2423
envelope: mail.message.getEnvelope(),
2524
messageId: mail.message.messageId(),
@@ -31,28 +30,24 @@ const testTransport = {
3130
/**
3231
* üWave API development server.
3332
*/
34-
function start() {
35-
const port = argv.port || 6042;
33+
async function start() {
34+
const port = argv.port || process.env.PORT || 6042;
3635

3736
const uwave = require('..');
3837

39-
const app = express();
40-
const server = http.createServer(app);
41-
42-
const apiUrl = '/api';
4338
const secret = Buffer.from('none', 'utf8');
4439

4540
const uw = uwave({
46-
...config,
41+
port,
4742
redis: process.env.REDIS_URL,
4843
mongo: process.env.MONGODB_URL,
49-
server,
5044
secret,
51-
auth: config.auth,
5245
mailTransport: testTransport,
5346
timeout: 10,
5447
});
5548

49+
uw.express.set('json spaces', 2);
50+
5651
uw.on('mongoError', (err) => {
5752
throw explain(err, 'Could not connect to MongoDB. Is it installed and running?');
5853
});
@@ -61,30 +56,33 @@ function start() {
6156
throw explain(err, 'Could not connect to the Redis server. Is it installed and running?');
6257
});
6358

64-
uw.use(announce({
65-
// Generate a random one in a real app!
66-
seed: Buffer.from('8286a5e55c62d93a042b8c56c8face52c05354c288807d941751f0e9060c2ded', 'hex'),
67-
name: 'localhost',
68-
subtitle: 'Local dev server',
69-
url: `http://localhost:${port}`,
70-
hub: process.env.HUB_URL || 'http://localhost:6451',
71-
}));
72-
73-
uw.source(ytSource, config.sources.youtube);
74-
uw.source(scSource, config.sources.soundcloud);
75-
76-
app.set('json spaces', 2);
77-
app.use(apiUrl, uw.httpApi);
78-
app.use((error, req, res, next) => {
79-
debug(error);
80-
next(error);
81-
});
59+
if (process.env.HUB_URL) {
60+
uw.use(announce({
61+
// Generate a random one in a real app!
62+
seed: Buffer.from('8286a5e55c62d93a042b8c56c8face52c05354c288807d941751f0e9060c2ded', 'hex'),
63+
name: 'localhost',
64+
subtitle: 'Local dev server',
65+
url: `http://localhost:${port}`,
66+
hub: process.env.HUB_URL,
67+
}));
68+
}
8269

83-
server.listen(port, () => {
84-
console.log(`Now listening on ${port}`);
85-
});
70+
if (process.env.YOUTUBE_API_KEY) {
71+
uw.source(ytSource, {
72+
key: process.env.YOUTUBE_API_KEY,
73+
});
74+
}
75+
if (process.env.SOUNDCLOUD_API_KEY) {
76+
uw.source(scSource, {
77+
key: process.env.SOUNDCLOUD_API_KEY,
78+
});
79+
}
8680

87-
return app;
81+
await uw.listen(port);
82+
console.log(`Now listening on ${port}`);
8883
}
8984

90-
start();
85+
start().catch((error) => {
86+
console.error(error.stack);
87+
process.exit(1);
88+
});

Diff for: example/config.json

-12
This file was deleted.

0 commit comments

Comments
 (0)