Skip to content

Commit

Permalink
Minor fixes related to naming
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimKovalenkoSNF committed Aug 14, 2023
1 parent 2cd3e58 commit 3c1020f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/Downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ class Downloader {
public async setBaseUrls() {
//* Objects order in array matters!
this.baseUrl = basicURLDirector.buildDownloaderBaseUrl([
{ condition: this.mw.hasDesktopRestApi, value: this.mw.desktopRestApiUrl.href },
{ condition: this.mw.hasVeApi, value: this.mw.veApiUrl.href },
{ condition: this.mw.hasWikimediaDesktopRestApi, value: this.mw.desktopRestApiUrl.href },
{ condition: this.mw.hasVisualEditorApi, value: this.mw.visualEditorApiUrl.href },
])

//* Objects order in array matters!
this.baseUrlForMainPage = basicURLDirector.buildDownloaderBaseUrl([
{ condition: this.mw.hasDesktopRestApi, value: this.mw.desktopRestApiUrl.href },
{ condition: this.mw.hasVeApi, value: this.mw.veApiUrl.href },
{ condition: this.mw.hasWikimediaDesktopRestApi, value: this.mw.desktopRestApiUrl.href },
{ condition: this.mw.hasVisualEditorApi, value: this.mw.visualEditorApiUrl.href },
])

logger.log('Base Url: ', this.baseUrl)
Expand Down
18 changes: 9 additions & 9 deletions src/MediaWiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class MediaWiki {
private readonly apiPath: string
private readonly domain: string
private apiUrlDirector: ApiURLDirector
private desktopUrlDirector: DesktopURLDirector
private wikimediaDesktopUrlDirector: DesktopURLDirector
private visualEditorURLDirector: VisualEditorURLDirector

public veApiUrl: URL
public visualEditorApiUrl: URL
public restApiUrl: URL
public apiUrl: URL
public modulePath: string
public webUrl: URL
public desktopRestApiUrl: URL

public hasDesktopRestApi = false
public hasVeApi = false
public hasWikimediaDesktopRestApi = false
public hasVisualEditorApi = false

constructor(config: MWConfig) {
this.domain = config.domain || ''
Expand All @@ -60,15 +60,15 @@ class MediaWiki {
this.webUrl = baseUrlDirector.buildURL(this.wikiPath)
this.apiUrl = baseUrlDirector.buildURL(this.apiPath)
this.apiUrlDirector = new ApiURLDirector(this.apiUrl.href)
this.veApiUrl = this.apiUrlDirector.buildVisualEditorURL()
this.visualEditorApiUrl = this.apiUrlDirector.buildVisualEditorURL()

this.restApiUrl = baseUrlDirector.buildRestApiURL(this.restApiPath)
this.desktopRestApiUrl = baseUrlDirector.buildDesktopRestApiURL(this.restApiPath)

this.modulePath = baseUrlDirector.buildModuleURL(this.modulePathConfig)

this.desktopUrlDirector = new DesktopURLDirector(this.desktopRestApiUrl.href)
this.visualEditorURLDirector = new VisualEditorURLDirector(this.veApiUrl.href)
this.wikimediaDesktopUrlDirector = new DesktopURLDirector(this.desktopRestApiUrl.href)
this.visualEditorURLDirector = new VisualEditorURLDirector(this.visualEditorApiUrl.href)
}

public async login(downloader: Downloader) {
Expand Down Expand Up @@ -312,8 +312,8 @@ class MediaWiki {

// Set capability properties, usied while mw.login
public async setCapabilities(articleId = 'MediaWiki:Sidebar', loginCookie?: string): Promise<void> {
this.hasDesktopRestApi = await checkApiAvailabilty(this.desktopUrlDirector.buildArticleURL(articleId), loginCookie)
this.hasVeApi = await checkApiAvailabilty(this.visualEditorURLDirector.buildArticleURL(articleId), loginCookie)
this.hasWikimediaDesktopRestApi = await checkApiAvailabilty(this.wikimediaDesktopUrlDirector.buildArticleURL(articleId), loginCookie)
this.hasVisualEditorApi = await checkApiAvailabilty(this.visualEditorURLDirector.buildArticleURL(articleId), loginCookie)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/util/builders/url/basic.director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import urlBuilder from './url.builder.js'

type DownloaderBaseUrlConditions = Array<{ condition: boolean; value: string }>

/**
* Build base URL for specific wiki if format like 'https://en.wikipedia.org' or 'https://de.wikivoyage.org
*/
class BasicURLDirector {
buildMediawikiBaseURL(domain: string) {
return urlBuilder.setDomain(domain).build(true, '/')
Expand Down
2 changes: 1 addition & 1 deletion src/util/saveArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function isMainPage(dump: Dump, articleId: string): boolean {
}

async function chooseRenderer(articleId, dump, mw: MediaWiki, wikimediaDesktopRenderer, visualEditorRenderer) {
if (mw.hasVeApi && !mw.hasDesktopRestApi) {
if (mw.hasVisualEditorApi && !mw.hasWikimediaDesktopRestApi) {
return visualEditorRenderer
}
return wikimediaDesktopRenderer
Expand Down
4 changes: 2 additions & 2 deletions test/unit/builders/url/desktop.director.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import DesktopURLDirector from '../../../../src/util/builders/url/desktop.director.js'

describe('DesktopURLDirector', () => {
const desktopUrlDirector = new DesktopURLDirector('https://en.m.wikipedia.org/api/rest_v1/page/html/')
const wikimediaDesktopUrlDirector = new DesktopURLDirector('https://en.m.wikipedia.org/api/rest_v1/page/html/')

describe('buildArticleURL', () => {
it('should return the URL to retrieve a desktop article', () => {
const url = desktopUrlDirector.buildArticleURL('article-1234')
const url = wikimediaDesktopUrlDirector.buildArticleURL('article-1234')

expect(url).toBe('https://en.m.wikipedia.org/api/rest_v1/page/html/article-1234')
})
Expand Down

0 comments on commit 3c1020f

Please sign in to comment.