From 6133ce1bc3b603cc9b076466247dec6a8f4e9614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Tue, 2 Nov 2021 13:04:25 +0100 Subject: [PATCH] fix source version detection in legacy/modern imports --- src/controllers/import.js | 3 +-- src/controllers/sources.js | 4 ---- src/source/Source.js | 25 +++++++++++-------------- src/source/types.d.ts | 1 + 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/controllers/import.js b/src/controllers/import.js index 790b54d8..e7f59081 100644 --- a/src/controllers/import.js +++ b/src/controllers/import.js @@ -1,6 +1,5 @@ 'use strict'; -const has = require('has'); const { SourceNotFoundError, SourceNoImportError, @@ -18,7 +17,7 @@ const getImportableSource = (req) => { if (!source) { throw new SourceNotFoundError({ name: sourceName }); } - if (!has(source, 'import')) { + if (source.apiVersion >= 3) { throw new SourceNoImportError({ name: sourceName }); } diff --git a/src/controllers/sources.js b/src/controllers/sources.js index e8b6d435..b52b3175 100644 --- a/src/controllers/sources.js +++ b/src/controllers/sources.js @@ -1,6 +1,5 @@ 'use strict'; -const has = require('has'); const { BadRequest } = require('http-errors'); const { SourceNotFoundError, @@ -20,9 +19,6 @@ function getImportableSource(req) { if (!source) { throw new SourceNotFoundError({ name: sourceName }); } - if (has(source, 'import')) { - throw new SourceNoImportError({ name: sourceName }); - } if (source.apiVersion < 3) { throw new SourceNoImportError({ name: sourceName }); } diff --git a/src/source/Source.js b/src/source/Source.js index 3fe3ea3a..f6e342fd 100644 --- a/src/source/Source.js +++ b/src/source/Source.js @@ -105,23 +105,17 @@ class LegacySourceWrapper { /** * Unsupported for legacy sources. - * @param {User} user - * @param {string} userID - * @returns {Promise>} + * @returns {Promise} */ - // eslint-disable-next-line no-unused-vars - async getUserPlaylists(user, userID) { + async getUserPlaylists() { throw new SourceNoImportError({ name: this.type }); } /** * Unsupported for legacy sources. - * @param {User} user - * @param {string} playlistID - * @returns {Promise>} + * @returns {Promise} */ - // eslint-disable-next-line no-unused-vars - async getPlaylistItems(user, playlistID) { + async getPlaylistItems() { throw new SourceNoImportError({ name: this.type }); } @@ -131,12 +125,13 @@ class LegacySourceWrapper { * doing. * * @param {User} user - * @param {unknown[]} args + * @param {{}} values + * @returns {Promise} */ - 'import'(user, ...args) { + 'import'(user, values) { const importContext = new ImportContext(this.uw, this, user); if (this.plugin.api === 2 && this.plugin.import != null) { - return this.plugin.import(importContext, ...args); + return this.plugin.import(importContext, values); } throw new SourceNoImportError({ name: this.type }); } @@ -256,8 +251,10 @@ class ModernSourceWrapper { /** * Unsupported for modern media sources. + * + * @returns {Promise} */ - 'import'() { + async 'import'() { throw new SourceNoImportError({ name: this.type }); } } diff --git a/src/source/types.d.ts b/src/source/types.d.ts index c9350b96..1039effb 100644 --- a/src/source/types.d.ts +++ b/src/source/types.d.ts @@ -42,4 +42,5 @@ export interface SourceWrapper { search(user: User, query: string, page?: JsonValue): Promise>; getUserPlaylists(user: User, userID: string): Promise>; getPlaylistItems(user: User, playlistID: string): Promise>; + import(user: User, params: {}): Promise; }