добавил домен резолвер
This commit is contained in:
parent
ae75816951
commit
77408cdb73
42
popup/src/api/DomainResolver.ts
Normal file
42
popup/src/api/DomainResolver.ts
Normal file
@ -0,0 +1,42 @@
|
||||
export class DomainResolver {
|
||||
resolve (): Promise<string> {
|
||||
const promise = new Promise((resolve) => {
|
||||
if (typeof chrome === 'undefined') {
|
||||
resolve(null)
|
||||
return
|
||||
}
|
||||
if (typeof chrome.tabs === 'undefined') {
|
||||
resolve(null)
|
||||
return
|
||||
}
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
for (const tab of tabs) {
|
||||
let url = tab.url || ''
|
||||
const parts = url.match(/http:\/\/.*?\.(.*?)\..*?/) || []
|
||||
const nickname = parts[1] || null
|
||||
const isPlacetgroup = url.indexOf('laen') > -1 ||
|
||||
url.indexOf('smsmoney') > -1 ||
|
||||
url.indexOf('smsraha') > -1 ||
|
||||
url.indexOf('placetgroup') > -1
|
||||
const project = isPlacetgroup ? 'placetgroup' : 'nordecum'
|
||||
const domain = isPlacetgroup ? 'com' : 'lt'
|
||||
if (nickname && url.indexOf('.sv') > -1) {
|
||||
url = project + '.' + nickname + '.sv'
|
||||
} else {
|
||||
url = project + '.' + nickname + '.' + domain
|
||||
}
|
||||
resolve(url)
|
||||
return
|
||||
}
|
||||
})
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
||||
// @ts-ignore
|
||||
return promise.then((url) => {
|
||||
console.log('url', url)
|
||||
return url
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new DomainResolver()
|
@ -2,6 +2,7 @@
|
||||
import { SchemaInterface } from './SchemaInterface'
|
||||
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'
|
||||
import stubResolver from '@/stubs/StubResolver'
|
||||
import domainResolver from '@/api/DomainResolver'
|
||||
|
||||
export abstract class Handler {
|
||||
abstract handle: any
|
||||
@ -42,7 +43,17 @@ export class HttpClient {
|
||||
this.baseUrl = baseUrl
|
||||
}
|
||||
|
||||
async syncBaseUrlWithStand () {
|
||||
await domainResolver
|
||||
.resolve()
|
||||
.then((url) => {
|
||||
this.baseUrl = url || this.baseUrl
|
||||
})
|
||||
}
|
||||
|
||||
send (schema: SchemaInterface, data: any | null = null): Promise<AxiosResponse> {
|
||||
this.syncBaseUrlWithStand()
|
||||
|
||||
let url = schema.url
|
||||
const preparedData = data
|
||||
for (const key in data) {
|
||||
|
Loading…
Reference in New Issue
Block a user