Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/app.js
Show First 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | methods: { | ||||
timeout -= 60 | timeout -= 60 | ||||
} | } | ||||
// TODO: We probably should try a few times in case of an error | // TODO: We probably should try a few times in case of an error | ||||
// TODO: We probably should prevent axios from doing any requests | // TODO: We probably should prevent axios from doing any requests | ||||
// while the token is being refreshed | // while the token is being refreshed | ||||
this.refreshTimeout = setTimeout(() => { | this.refreshTimeout = setTimeout(() => { | ||||
axios.post('/api/auth/refresh', {'refresh_token': response.refresh_token}).then(response => { | axios.post('api/auth/refresh', { refresh_token: response.refresh_token }).then(response => { | ||||
this.loginUser(response.data, false, true) | this.loginUser(response.data, false, true) | ||||
}) | }) | ||||
}, timeout * 1000) | }, timeout * 1000) | ||||
}, | }, | ||||
// Set user state to "not logged in" | // Set user state to "not logged in" | ||||
logoutUser(redirect) { | logoutUser(redirect) { | ||||
store.commit('logoutUser') | store.commit('logoutUser') | ||||
localStorage.setItem('token', '') | localStorage.setItem('token', '') | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | methods: { | ||||
this.logoutUser() | this.logoutUser() | ||||
} else { | } else { | ||||
this.logoutUser(false) | this.logoutUser(false) | ||||
} | } | ||||
} else { | } else { | ||||
this.errorPage(status, message) | this.errorPage(status, message) | ||||
} | } | ||||
}, | }, | ||||
downloadFile(url) { | downloadFile(url, filename) { | ||||
// TODO: This might not be a best way for big files as the content | // TODO: This might not be a best way for big files as the content | ||||
// will be stored (temporarily) in browser memory | // will be stored (temporarily) in browser memory | ||||
// TODO: This method does not show the download progress in the browser | // TODO: This method does not show the download progress in the browser | ||||
// but it could be implemented in the UI, axios has 'progress' property | // but it could be implemented in the UI, axios has 'progress' property | ||||
axios.get(url, { responseType: 'blob' }) | axios.get(url, { responseType: 'blob' }) | ||||
.then(response => { | .then(response => { | ||||
const link = document.createElement('a') | const link = document.createElement('a') | ||||
if (!filename) { | |||||
const contentDisposition = response.headers['content-disposition'] | const contentDisposition = response.headers['content-disposition'] | ||||
let filename = 'unknown' | filename = 'unknown' | ||||
if (contentDisposition) { | if (contentDisposition) { | ||||
const match = contentDisposition.match(/filename="(.+)"/); | const match = contentDisposition.match(/filename="?(.+)"?/); | ||||
if (match.length === 2) { | if (match && match.length === 2) { | ||||
filename = match[1]; | filename = match[1]; | ||||
} | } | ||||
} | } | ||||
} | |||||
link.href = window.URL.createObjectURL(response.data) | link.href = window.URL.createObjectURL(response.data) | ||||
link.download = filename | link.download = filename | ||||
link.click() | link.click() | ||||
}) | }) | ||||
}, | }, | ||||
price(price, currency) { | price(price, currency) { | ||||
// TODO: Set locale argument according to the currently used locale | // TODO: Set locale argument according to the currently used locale | ||||
▲ Show 20 Lines • Show All 230 Lines • Show Last 20 Lines |