Browse Source

refactored getDisplayURL

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 7 years ago
parent
commit
2360ce36ac
  1. 1
      internal/handlers/handlers.go
  2. 5
      web/src/Home/Home.js
  3. 5
      web/src/Lookup/Lookup.js
  4. 5
      web/src/Recent/Recent.js
  5. 5
      web/src/util/util.js

1
internal/handlers/handlers.go

@ -163,7 +163,6 @@ func (h *Handler) setHandlers() error {
h.engine.GET("/api/v1/info", h.handleInfo) h.engine.GET("/api/v1/info", h.handleInfo)
h.engine.GET("/d/:id/:hash", h.handleDelete) h.engine.GET("/d/:id/:hash", h.handleDelete)
h.engine.GET("/ok", h.handleHealthcheck) h.engine.GET("/ok", h.handleHealthcheck)
h.engine.GET("/displayurl", h.handleDisplayURL)
// Handling the shorted URLs, if no one exists, it checks // Handling the shorted URLs, if no one exists, it checks
// in the filesystem and sets headers for caching // in the filesystem and sets headers for caching

5
web/src/Home/Home.js

@ -36,9 +36,8 @@ export default class HomeComponent extends Component {
componentDidMount() { componentDidMount() {
this.urlInput.focus() this.urlInput.focus()
fetch("/displayurl") util.getDisplayURL()
.then(response => response.json()) .then(displayURL => this.setState({ displayURL }));
.then(data => this.setState({displayURL: data}));
} }
handleURLSubmit = () => { handleURLSubmit = () => {
if (!this.state.showCustomIDError) { if (!this.state.showCustomIDError) {

5
web/src/Lookup/Lookup.js

@ -10,9 +10,8 @@ export default class LookupComponent extends Component {
displayURL: window.location.origin displayURL: window.location.origin
} }
componentDidMount() { componentDidMount() {
fetch("/displayurl") util.getDisplayURL()
.then(response => response.json()) .then(displayURL => this.setState({ displayURL }));
.then(data => this.setState({displayURL: data}));
} }
handleURLChange = (e, { value }) => this.url = value handleURLChange = (e, { value }) => this.url = value
handleURLSubmit = () => { handleURLSubmit = () => {

5
web/src/Recent/Recent.js

@ -14,9 +14,8 @@ export default class RecentComponent extends Component {
componentDidMount() { componentDidMount() {
this.loadRecentURLs() this.loadRecentURLs()
fetch("/displayurl") util.getDisplayURL()
.then(response => response.json()) .then(displayURL => this.setState({ displayURL }));
.then(data => this.setState({displayURL: data}));
} }
loadRecentURLs = () => { loadRecentURLs = () => {

5
web/src/util/util.js

@ -56,4 +56,9 @@ export default class UtilHelper {
.then(res => cbSucc ? cbSucc(res) : null) .then(res => cbSucc ? cbSucc(res) : null)
.catch(e => this._reportError(e, "recent")) .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"))
}
} }

Loading…
Cancel
Save