diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index c1c27ce..cf601c2 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -163,7 +163,6 @@ func (h *Handler) setHandlers() error { h.engine.GET("/api/v1/info", h.handleInfo) h.engine.GET("/d/:id/:hash", h.handleDelete) h.engine.GET("/ok", h.handleHealthcheck) - h.engine.GET("/displayurl", h.handleDisplayURL) // Handling the shorted URLs, if no one exists, it checks // in the filesystem and sets headers for caching diff --git a/web/src/Home/Home.js b/web/src/Home/Home.js index 51db5e4..2548655 100644 --- a/web/src/Home/Home.js +++ b/web/src/Home/Home.js @@ -11,22 +11,22 @@ import './Home.css' export default class HomeComponent extends Component { constructor(props) { - super(props); - this.urlParams = new URLSearchParams(window.location.search); - this.state = { - links: [], - usedSettings: this.urlParams.get('customUrl') ? ['custom'] : [], - customID: this.urlParams.get('customUrl') ? this.urlParams.get('customUrl') : '', - showCustomIDError: false, - expiration: null, - displayURL: window.location.origin - } + super(props); + this.urlParams = new URLSearchParams(window.location.search); + this.state = { + links: [], + usedSettings: this.urlParams.get('customUrl') ? ['custom'] : [], + customID: this.urlParams.get('customUrl') ? this.urlParams.get('customUrl') : '', + showCustomIDError: false, + expiration: null, + displayURL: window.location.origin + } } handleURLChange = (e, { value }) => this.url = value handlePasswordChange = (e, { value }) => this.password = value handleCustomExpirationChange = expire => this.setState({ expiration: expire }) handleCustomIDChange = (e, { value }) => { - this.setState({customID: value}) + this.setState({ customID: value }) util.lookupEntry(value, () => this.setState({ showCustomIDError: true }), () => this.setState({ showCustomIDError: false })) } onSettingsChange = (e, { value }) => { @@ -36,9 +36,8 @@ export default class HomeComponent extends Component { componentDidMount() { this.urlInput.focus() - fetch("/displayurl") - .then(response => response.json()) - .then(data => this.setState({displayURL: data})); + util.getDisplayURL() + .then(displayURL => this.setState({ displayURL })); } handleURLSubmit = () => { if (!this.state.showCustomIDError) { @@ -71,7 +70,7 @@ export default class HomeComponent extends Component { {this.urlParams.get("customUrl") ? (
I don't have a link named "{this.urlParams.get("customUrl")}" in my database, would you like to create one?
- ) : + ) :
Simplify your links
}
@@ -91,7 +90,7 @@ export default class HomeComponent extends Component { {usedSettings.includes("custom") && - + } diff --git a/web/src/Lookup/Lookup.js b/web/src/Lookup/Lookup.js index 218aeb3..8859666 100644 --- a/web/src/Lookup/Lookup.js +++ b/web/src/Lookup/Lookup.js @@ -10,9 +10,8 @@ export default class LookupComponent extends Component { displayURL: window.location.origin } componentDidMount() { - fetch("/displayurl") - .then(response => response.json()) - .then(data => this.setState({displayURL: data})); + util.getDisplayURL() + .then(displayURL => this.setState({ displayURL })); } handleURLChange = (e, { value }) => this.url = value handleURLSubmit = () => { diff --git a/web/src/Recent/Recent.js b/web/src/Recent/Recent.js index 396c767..8692978 100644 --- a/web/src/Recent/Recent.js +++ b/web/src/Recent/Recent.js @@ -14,9 +14,8 @@ export default class RecentComponent extends Component { componentDidMount() { this.loadRecentURLs() - fetch("/displayurl") - .then(response => response.json()) - .then(data => this.setState({displayURL: data})); + util.getDisplayURL() + .then(displayURL => this.setState({ displayURL })); } loadRecentURLs = () => { diff --git a/web/src/util/util.js b/web/src/util/util.js index 71b9dc8..0d4cc14 100644 --- a/web/src/util/util.js +++ b/web/src/util/util.js @@ -2,7 +2,7 @@ import toastr from 'toastr' export default class UtilHelper { static deleteEntry(url, cb) { - fetch(url, {credentials: "include"}) + fetch(url, { credentials: "include" }) .then(res => res.ok ? res.json() : Promise.reject(res.json())) .then(cb()) .catch(e => this._reportError(e, "delete entry")) @@ -42,7 +42,7 @@ export default class UtilHelper { this._constructFetch("/api/v1/protected/visitors", { ID }, cbSucc) } static createEntry(entry, cbSucc) { - this._constructFetch("/api/v1/protected/create",entry, cbSucc) + this._constructFetch("/api/v1/protected/create", entry, cbSucc) } static getRecentURLs(cbSucc) { fetch('/api/v1/protected/recent', { @@ -56,4 +56,9 @@ export default class UtilHelper { .then(res => cbSucc ? cbSucc(res) : null) .catch(e => this._reportError(e, "recent")) } + static getDisplayURL() { + return fetch("/api/v1/displayURL") + .then(res => res.ok ? res.json() : Promise.reject(res.json())) + .catch(e => this._reportError(e, "getDisplayURL")) + } }