Set subdomain to "__unset__" if it empty
This is to prevent invalid network requests with an empty subdomain.
This commit is contained in:
@@ -12,7 +12,7 @@ class Options extends Component {
|
|||||||
@observable isSuccess = false;
|
@observable isSuccess = false;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
getSettings().then(({ subdomain, apiKey }) => {
|
getSettings(false).then(({ subdomain, apiKey }) => {
|
||||||
this.subdomain = subdomain || ""
|
this.subdomain = subdomain || ""
|
||||||
this.apiKey = apiKey || ""
|
this.apiKey = apiKey || ""
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
|
import { head } from "lodash/fp"
|
||||||
export const isChrome = () => typeof browser === "undefined" && chrome
|
export const isChrome = () => typeof browser === "undefined" && chrome
|
||||||
export const isFirefox = () => typeof browser !== "undefined" && chrome
|
export const isFirefox = () => typeof browser !== "undefined" && chrome
|
||||||
import { head } from "lodash/fp"
|
|
||||||
|
|
||||||
export const getSettings = () => {
|
export const getSettings = (withDefaultSubdomain = true) => {
|
||||||
const keys = ["subdomain", "apiKey"]
|
const keys = ["subdomain", "apiKey"]
|
||||||
const { version } = chrome.runtime.getManifest()
|
const { version } = chrome.runtime.getManifest()
|
||||||
if (isChrome()) {
|
if (isChrome()) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
chrome.storage.sync.get(keys, data => {
|
chrome.storage.sync.get(keys, data => {
|
||||||
|
if (withDefaultSubdomain) {
|
||||||
|
data.subdomain = data.subdomain || "__unset__"
|
||||||
|
}
|
||||||
resolve({ ...data, version })
|
resolve({ ...data, version })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return browser.storage.sync.get(keys).then(data => ({ ...data, version }))
|
return browser.storage.sync.get(keys).then(data => {
|
||||||
|
if (withDefaultSubdomain) {
|
||||||
|
data.subdomain = data.subdomain || "__unset__"
|
||||||
|
}
|
||||||
|
return { ...data, version }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user