changes for plugin submission review
This commit is contained in:
parent
344c1ebf6c
commit
a5d62ddc24
13 changed files with 134 additions and 237 deletions
|
|
@ -2,6 +2,7 @@ import {APIModel} from '../APIModel';
|
|||
import {MediaTypeModel} from '../../models/MediaTypeModel';
|
||||
import MediaDbPlugin from '../../main';
|
||||
import {WikiModel} from '../../models/WikiModel';
|
||||
import {debugLog} from '../../utils/Utils';
|
||||
|
||||
export class WikipediaAPI extends APIModel {
|
||||
plugin: MediaDbPlugin;
|
||||
|
|
@ -17,22 +18,20 @@ export class WikipediaAPI extends APIModel {
|
|||
}
|
||||
|
||||
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
|
||||
console.log(`MDB | api "${this.apiName}" queried`);
|
||||
console.log(`MDB | api "${this.apiName}" queried by Title`);
|
||||
|
||||
const searchUrl = `https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(title)}&srlimit=20&utf8=&format=json&origin=*`;
|
||||
|
||||
const fetchData = await fetch(searchUrl);
|
||||
console.log(fetchData);
|
||||
debugLog(fetchData);
|
||||
|
||||
if (fetchData.status !== 200) {
|
||||
throw Error(`Received status code ${fetchData.status} from an API.`);
|
||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||
}
|
||||
|
||||
const data = await fetchData.json();
|
||||
|
||||
console.log(data);
|
||||
|
||||
debugLog(data);
|
||||
let ret: MediaTypeModel[] = [];
|
||||
|
||||
|
||||
for (const result of data.query.search) {
|
||||
ret.push(new WikiModel({
|
||||
type: 'wiki',
|
||||
|
|
@ -48,16 +47,17 @@ export class WikipediaAPI extends APIModel {
|
|||
}
|
||||
|
||||
async getById(item: MediaTypeModel): Promise<MediaTypeModel> {
|
||||
console.log(`MDB | api "${this.apiName}" queried by ID`);
|
||||
|
||||
const searchUrl = `https://en.wikipedia.org/w/api.php?action=query&prop=info&pageids=${item.id}&inprop=url&format=json&origin=*`;
|
||||
|
||||
const fetchData = await fetch(searchUrl);
|
||||
|
||||
if (fetchData.status !== 200) {
|
||||
throw Error(`Received status code ${fetchData.status} from an API.`);
|
||||
throw Error(`MDB | Received status code ${fetchData.status} from an API.`);
|
||||
}
|
||||
|
||||
const data = await fetchData.json();
|
||||
console.log(data);
|
||||
debugLog(data);
|
||||
const result = Object.entries(data?.query?.pages)[0][1];
|
||||
|
||||
const model = new WikiModel({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue