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. 9
      web/src/Home/Home.js
  3. 5
      web/src/Lookup/Lookup.js
  4. 5
      web/src/Recent/Recent.js
  5. 9
      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

9
web/src/Home/Home.js

@ -26,7 +26,7 @@ export default class HomeComponent extends Component {
handlePasswordChange = (e, { value }) => this.password = value handlePasswordChange = (e, { value }) => this.password = value
handleCustomExpirationChange = expire => this.setState({ expiration: expire }) handleCustomExpirationChange = expire => this.setState({ expiration: expire })
handleCustomIDChange = (e, { value }) => { handleCustomIDChange = (e, { value }) => {
this.setState({customID: value}) this.setState({ customID: value })
util.lookupEntry(value, () => this.setState({ showCustomIDError: true }), () => this.setState({ showCustomIDError: false })) util.lookupEntry(value, () => this.setState({ showCustomIDError: true }), () => this.setState({ showCustomIDError: false }))
} }
onSettingsChange = (e, { value }) => { onSettingsChange = (e, { value }) => {
@ -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) {
@ -91,7 +90,7 @@ export default class HomeComponent extends Component {
</MediaQuery> </MediaQuery>
<Form.Group style={{ marginBottom: "1rem" }}> <Form.Group style={{ marginBottom: "1rem" }}>
{usedSettings.includes("custom") && <Form.Field error={showCustomIDError} width={16}> {usedSettings.includes("custom") && <Form.Field error={showCustomIDError} width={16}>
<Input label={this.state.displayURL + "/"} onChange={this.handleCustomIDChange} placeholder='my-shortened-url' value={this.state.customID}/> <Input label={this.state.displayURL + "/"} onChange={this.handleCustomIDChange} placeholder='my-shortened-url' value={this.state.customID} />
</Form.Field>} </Form.Field>}
</Form.Group> </Form.Group>
<Form.Group widths="equal"> <Form.Group widths="equal">

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 = () => {

9
web/src/util/util.js

@ -2,7 +2,7 @@ import toastr from 'toastr'
export default class UtilHelper { export default class UtilHelper {
static deleteEntry(url, cb) { static deleteEntry(url, cb) {
fetch(url, {credentials: "include"}) fetch(url, { credentials: "include" })
.then(res => res.ok ? res.json() : Promise.reject(res.json())) .then(res => res.ok ? res.json() : Promise.reject(res.json()))
.then(cb()) .then(cb())
.catch(e => this._reportError(e, "delete entry")) .catch(e => this._reportError(e, "delete entry"))
@ -42,7 +42,7 @@ export default class UtilHelper {
this._constructFetch("/api/v1/protected/visitors", { ID }, cbSucc) this._constructFetch("/api/v1/protected/visitors", { ID }, cbSucc)
} }
static createEntry(entry, cbSucc) { static createEntry(entry, cbSucc) {
this._constructFetch("/api/v1/protected/create",entry, cbSucc) this._constructFetch("/api/v1/protected/create", entry, cbSucc)
} }
static getRecentURLs(cbSucc) { static getRecentURLs(cbSucc) {
fetch('/api/v1/protected/recent', { fetch('/api/v1/protected/recent', {
@ -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