Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Sep 1, 2021
1 parent 58353ec commit 5b415ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Source {
}

get apiVersion() {
return this.plugin.api || this.plugin.constructor.api || 1;
return this.plugin.api || 1;
}

/**
Expand All @@ -115,11 +115,11 @@ class Source {
*
* @param {User} user
* @param {string} id
* @returns {Promise<PlaylistItemDesc?>}
* @returns {Promise<PlaylistItemDesc | undefined>}
*/
getOne(user, id) {
return this.get(user, [id])
.then((items) => items[0]);
async getOne(user, id) {
const [item] = await this.get(user, [id]);
return item;
}

/**
Expand Down Expand Up @@ -164,6 +164,10 @@ class Source {

/**
* Get playlists for a specific user from this media source.
*
* @param {User} user
* @param {string} userID
* @returns {Promise<unknown>}
*/
async getUserPlaylists(user, userID) {
if (this.apiVersion < 3 || !this.plugin.getUserPlaylists) {
Expand All @@ -177,6 +181,10 @@ class Source {

/**
* Get playlists for a specific user from this media source.
*
* @param {User} user
* @param {string} playlistID
* @returns {Promise<unknown>}
*/
async getPlaylistItems(user, playlistID) {
if (this.apiVersion < 3 || !this.plugin.getPlaylistItems) {
Expand All @@ -203,6 +211,9 @@ class Source {
throw new SourceNoImportError({ name: this.type });
}

/**
* @param {import('./Uwave')} uw
*/
static async plugin(uw, { source: SourcePlugin, baseOptions = {} }) {
debug('registering plugin', SourcePlugin);
if (SourcePlugin.api == null || SourcePlugin.api < 3) {
Expand Down
2 changes: 0 additions & 2 deletions src/Uwave.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ class UwaveServer extends EventEmitter {
*
* @param {string} sourceType
* @param {Source} source
* @private
*/
insertSourceInternal(sourceType, source) {
this.#sources.set(sourceType, source);
Expand All @@ -285,7 +284,6 @@ class UwaveServer extends EventEmitter {
* Only source plugins using Media Source API 3 or higher can be removed.
*
* @param {string} sourceType
* @private
*/
removeSourceInternal(sourceType) {
const source = this.#sources.get(sourceType);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/sources.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const router = require('router');
const { Router } = require('express');
const route = require('../route');
const protect = require('../middleware/protect');
const schema = require('../middleware/schema');
const controller = require('../controllers/sources');
const validations = require('../validations');

function sourceRoutes() {
return router()
return Router()
.use(protect())
// GET /sources/:source/search - Search for media in a single source.
.get(
Expand Down

0 comments on commit 5b415ef

Please sign in to comment.