Skip to content

Commit

Permalink
fix source version detection in legacy/modern imports
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Nov 2, 2021
1 parent 80dd76c commit 6133ce1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/controllers/import.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const has = require('has');
const {
SourceNotFoundError,
SourceNoImportError,
Expand All @@ -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 });
}

Expand Down
4 changes: 0 additions & 4 deletions src/controllers/sources.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const has = require('has');
const { BadRequest } = require('http-errors');
const {
SourceNotFoundError,
Expand All @@ -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 });
}
Expand Down
25 changes: 11 additions & 14 deletions src/source/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,17 @@ class LegacySourceWrapper {

/**
* Unsupported for legacy sources.
* @param {User} user
* @param {string} userID
* @returns {Promise<Page<unknown, {}>>}
* @returns {Promise<never>}
*/
// 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<Page<PlaylistItemDesc, {}>>}
* @returns {Promise<never>}
*/
// eslint-disable-next-line no-unused-vars
async getPlaylistItems(user, playlistID) {
async getPlaylistItems() {
throw new SourceNoImportError({ name: this.type });
}

Expand All @@ -131,12 +125,13 @@ class LegacySourceWrapper {
* doing.
*
* @param {User} user
* @param {unknown[]} args
* @param {{}} values
* @returns {Promise<unknown>}
*/
'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 });
}
Expand Down Expand Up @@ -256,8 +251,10 @@ class ModernSourceWrapper {

/**
* Unsupported for modern media sources.
*
* @returns {Promise<never>}
*/
'import'() {
async 'import'() {
throw new SourceNoImportError({ name: this.type });
}
}
Expand Down
1 change: 1 addition & 0 deletions src/source/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export interface SourceWrapper {
search(user: User, query: string, page?: JsonValue): Promise<Page<PlaylistItemDesc, JsonValue>>;
getUserPlaylists(user: User, userID: string): Promise<Page<unknown, JsonValue>>;
getPlaylistItems(user: User, playlistID: string): Promise<Page<PlaylistItemDesc, JsonValue>>;
import(user: User, params: {}): Promise<unknown>;
}

0 comments on commit 6133ce1

Please sign in to comment.