Skip to content

Commit

Permalink
Merge branch 'default' into hcaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Aug 9, 2020
2 parents b6bb729 + dbc96de commit db8edbc
Show file tree
Hide file tree
Showing 50 changed files with 1,099 additions and 324 deletions.
13 changes: 0 additions & 13 deletions .babelrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/example
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,21 @@ module.exports = {
'no-param-reassign': ['error', { props: false }],
// I disagree that this is bad
'max-classes-per-file': 'off',
// Allow `for..of`
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
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.',
},
{
selector: 'LabeledStatement',
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
},
};
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
19 changes: 19 additions & 0 deletions .github/workflows/update-ns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish Updated Config Schemas

on:
push:
branches: [default]
# Maybe should do it on release instead?
# release:
# types: [published]

jobs:
dispatch:
name: Dispatch
runs-on: ubuntu-latest
steps:
- uses: peter-evans/repository-dispatch@v1
with:
repository: u-wave/federation
token: ${{secrets.SCHEMA_ACCESS_TOKEN}}
event-type: update-config-schemas
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ node_modules
/dist
.eslintcache
package-lock.json
.env
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const ms = require('ms');
module.exports = {
timeout: ms('30 seconds'),
recursive: 'test/',
require: 'make-promises-safe',
};
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.

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

## Unreleased

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.

Features:
* **Breaking:** Merge `u-wave-http-api`. (#333)
* Automatically activate a user's first playlist. (#219)
* Implement votes using HTTP requests. (#361)
* Older client versions can still use WebSocket votes.
* Find playlists containing a particular media. (#374)

Internal:
* Add `uw.models` property for easier mongoose model access. (#283)
* **Breaking:** Small changes to DB option handling. (#264)
* **Breaking:** Raise supported Node.js version to 10+. (#342)
* Make `getPlaylistItems` faster with a single query. (#351, #370)
* Remove use of `p-props`. (#371)

## 0.4.1 / 17 Jul 2018

Bugfixes:
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ Core library for üWave, the collaborative listening platform.
[Getting Started](#getting-started) - [API](#api) - [Building](#contributing) -
[License](#license)

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

üWave consists of three parts: the core library, the HTTP API, and the web
Expand Down
101 changes: 101 additions & 0 deletions bin/u-wave-core
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env node

require('make-promises-safe');
const explain = require('explain-error');
const envSchema = require('env-schema');
const ytSource = require('u-wave-source-youtube');
const scSource = require('u-wave-source-soundcloud');
const uwave = require('..');
const pkg = require('../package.json');
const argv = require('minimist')(process.argv.slice(2));

if (argv.h || argv.help) {
console.log('u-wave-core');
console.log('Version', pkg.version);
console.log();
console.log('Environment Variables:');
console.log(' SECRET');
console.log(' A secret key used for encrypting passwords. Must be a 64-character hexadecimal string (= 256 bits).');
console.log(' PORT');
console.log(' Port to listen on. Defaults to 6042.');
console.log(' REDIS_URL');
console.log(' URL of the Redis instance to connect to. Defaults to redis://localhost:6379/.');
console.log(' MONGODB_URL');
console.log(' URL of the MongoDB database to use. Defaults to mongodb://localhost:27017/uwave.');
console.log();
process.exit(0);
}

const config = envSchema({
schema: {
type: 'object',
required: ['SECRET'],
properties: {
PORT: {
type: 'number',
default: 6042,
},
REDIS_URL: {
type: 'string',
format: 'uri',
default: 'redis://localhost:6379',
},
MONGODB_URL: {
type: 'string',
format: 'uri',
default: 'mongodb://localhost:27017/uwave',
},
SECRET: {
type: 'string',
regex: '^[0-9a-fA-F]+$',
min: 64,
max: 64,
},
YOUTUBE_API_KEY: {
type: 'string',
},
SOUNDCLOUD_API_KEY: {
type: 'string',
},
},
},
});

const port = Number(argv.port || config.PORT);

const secret = Buffer.from(config.SECRET, 'hex');

const uw = uwave({
port,
redis: config.REDIS_URL,
mongo: config.MONGODB_URL,
secret,
});

uw.express.set('json spaces', 2);

uw.on('mongoError', (err) => {
throw explain(err, 'Could not connect to MongoDB. Is it installed and running?');
});

uw.on('redisError', (err) => {
throw explain(err, 'Could not connect to the Redis server. Is it installed and running?');
});

if (config.YOUTUBE_API_KEY) {
uw.source(ytSource, {
key: config.YOUTUBE_API_KEY,
});
}
if (config.SOUNDCLOUD_API_KEY) {
uw.source(scSource, {
key: config.SOUNDCLOUD_API_KEY,
});
}

uw.listen(port).then(() => {
console.log(`Now listening on ${port}`);
}, (error) => {
console.error(error.stack);
process.exit(1);
});
11 changes: 0 additions & 11 deletions dev/dev-server-config.json

This file was deleted.

74 changes: 36 additions & 38 deletions dev/u-wave-dev-server
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#!/usr/bin/env node

require('make-promises-safe');
const { Buffer } = require('buffer');
const http = require('http');
const argv = require('minimist')(process.argv.slice(2));
const concat = require('concat-stream');
const explain = require('explain-error');
const announce = require('u-wave-announce');
const ytSource = require('u-wave-source-youtube');
const scSource = require('u-wave-source-soundcloud');
const hcaptchaTestKeys = require('hcaptcha-test-keys');
const express = require('express');
const mailDebug = require('debug')('uwave:mail');
const debug = require('debug')('uwave:dev-server');
const config = require('./dev-server-config.json');
const dotenv = require('dotenv');

dotenv.config();

const testTransport = {
name: 'test',
version: '0.0.0',
send(mail, callback) {
mail.message.createReadStream().pipe(concat((message) => {
mailDebug(mail.message.getEnvelope().to, message.toString('utf8'));
debug(mail.message.getEnvelope().to, message.toString('utf8'));
callback(null, {
envelope: mail.message.getEnvelope(),
messageId: mail.message.messageId(),
Expand All @@ -31,28 +30,24 @@ const testTransport = {
/**
* üWave API development server.
*/
function start() {
const port = argv.port || 6042;
async function start() {
const port = argv.port || process.env.PORT || 6042;

const uwave = require('..');

const app = express();
const server = http.createServer(app);

const apiUrl = '/api';
const secret = Buffer.from('none', 'utf8');

const uw = uwave({
...config,
port,
redis: process.env.REDIS_URL,
mongo: process.env.MONGODB_URL,
server,
secret,
auth: config.auth,
mailTransport: testTransport,
timeout: 10,
});

uw.express.set('json spaces', 2);

uw.on('mongoError', (err) => {
throw explain(err, 'Could not connect to MongoDB. Is it installed and running?');
});
Expand All @@ -61,30 +56,33 @@ function start() {
throw explain(err, 'Could not connect to the Redis server. Is it installed and running?');
});

uw.use(announce({
// Generate a random one in a real app!
seed: Buffer.from('8286a5e55c62d93a042b8c56c8face52c05354c288807d941751f0e9060c2ded', 'hex'),
name: 'localhost',
subtitle: 'Local dev server',
url: `http://localhost:${port}`,
hub: process.env.HUB_URL || 'http://localhost:6451',
}));

uw.source(ytSource, config.sources.youtube);
uw.source(scSource, config.sources.soundcloud);

app.set('json spaces', 2);
app.use(apiUrl, uw.httpApi);
app.use((error, req, res, next) => {
debug(error);
next(error);
});
if (process.env.HUB_URL) {
uw.use(announce({
// Generate a random one in a real app!
seed: Buffer.from('8286a5e55c62d93a042b8c56c8face52c05354c288807d941751f0e9060c2ded', 'hex'),
name: 'localhost',
subtitle: 'Local dev server',
url: `http://localhost:${port}`,
hub: process.env.HUB_URL,
}));
}

server.listen(port, () => {
console.log(`Now listening on ${port}`);
});
if (process.env.YOUTUBE_API_KEY) {
uw.source(ytSource, {
key: process.env.YOUTUBE_API_KEY,
});
}
if (process.env.SOUNDCLOUD_API_KEY) {
uw.source(scSource, {
key: process.env.SOUNDCLOUD_API_KEY,
});
}

return app;
await uw.listen(port);
console.log(`Now listening on ${port}`);
}

start();
start().catch((error) => {
console.error(error.stack);
process.exit(1);
});
12 changes: 0 additions & 12 deletions example/config.json

This file was deleted.

Loading

0 comments on commit db8edbc

Please sign in to comment.