Skip to content

Commit 6133ce1

Browse files
committed
fix source version detection in legacy/modern imports
1 parent 80dd76c commit 6133ce1

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

src/controllers/import.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const has = require('has');
43
const {
54
SourceNotFoundError,
65
SourceNoImportError,
@@ -18,7 +17,7 @@ const getImportableSource = (req) => {
1817
if (!source) {
1918
throw new SourceNotFoundError({ name: sourceName });
2019
}
21-
if (!has(source, 'import')) {
20+
if (source.apiVersion >= 3) {
2221
throw new SourceNoImportError({ name: sourceName });
2322
}
2423

src/controllers/sources.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const has = require('has');
43
const { BadRequest } = require('http-errors');
54
const {
65
SourceNotFoundError,
@@ -20,9 +19,6 @@ function getImportableSource(req) {
2019
if (!source) {
2120
throw new SourceNotFoundError({ name: sourceName });
2221
}
23-
if (has(source, 'import')) {
24-
throw new SourceNoImportError({ name: sourceName });
25-
}
2622
if (source.apiVersion < 3) {
2723
throw new SourceNoImportError({ name: sourceName });
2824
}

src/source/Source.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,17 @@ class LegacySourceWrapper {
105105

106106
/**
107107
* Unsupported for legacy sources.
108-
* @param {User} user
109-
* @param {string} userID
110-
* @returns {Promise<Page<unknown, {}>>}
108+
* @returns {Promise<never>}
111109
*/
112-
// eslint-disable-next-line no-unused-vars
113-
async getUserPlaylists(user, userID) {
110+
async getUserPlaylists() {
114111
throw new SourceNoImportError({ name: this.type });
115112
}
116113

117114
/**
118115
* Unsupported for legacy sources.
119-
* @param {User} user
120-
* @param {string} playlistID
121-
* @returns {Promise<Page<PlaylistItemDesc, {}>>}
116+
* @returns {Promise<never>}
122117
*/
123-
// eslint-disable-next-line no-unused-vars
124-
async getPlaylistItems(user, playlistID) {
118+
async getPlaylistItems() {
125119
throw new SourceNoImportError({ name: this.type });
126120
}
127121

@@ -131,12 +125,13 @@ class LegacySourceWrapper {
131125
* doing.
132126
*
133127
* @param {User} user
134-
* @param {unknown[]} args
128+
* @param {{}} values
129+
* @returns {Promise<unknown>}
135130
*/
136-
'import'(user, ...args) {
131+
'import'(user, values) {
137132
const importContext = new ImportContext(this.uw, this, user);
138133
if (this.plugin.api === 2 && this.plugin.import != null) {
139-
return this.plugin.import(importContext, ...args);
134+
return this.plugin.import(importContext, values);
140135
}
141136
throw new SourceNoImportError({ name: this.type });
142137
}
@@ -256,8 +251,10 @@ class ModernSourceWrapper {
256251

257252
/**
258253
* Unsupported for modern media sources.
254+
*
255+
* @returns {Promise<never>}
259256
*/
260-
'import'() {
257+
async 'import'() {
261258
throw new SourceNoImportError({ name: this.type });
262259
}
263260
}

src/source/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ export interface SourceWrapper {
4242
search(user: User, query: string, page?: JsonValue): Promise<Page<PlaylistItemDesc, JsonValue>>;
4343
getUserPlaylists(user: User, userID: string): Promise<Page<unknown, JsonValue>>;
4444
getPlaylistItems(user: User, playlistID: string): Promise<Page<PlaylistItemDesc, JsonValue>>;
45+
import(user: User, params: {}): Promise<unknown>;
4546
}

0 commit comments

Comments
 (0)