Skip to content

Commit

Permalink
check errors added
Browse files Browse the repository at this point in the history
  • Loading branch information
vvsviridov committed Apr 22, 2021
1 parent e28986f commit 83606cd
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
Binary file modified assets/icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon-384x384.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 25 additions & 6 deletions assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function pageInit() {
container.classList.add('active')
back.className = 'fas fa-cloud-download-alt'
root.style.setProperty('--progress', 100)
download.addEventListener('click', (e) => {
download.addEventListener('click', () => {
downloadFileFromStorage()
})
return
Expand All @@ -59,8 +59,8 @@ function uploadFile(file) {

async function downloadFileFromStorage() {
const fileRef = storageRef.child(fileId)
console.log(fileRef)
const metadata = await getMetadata(fileRef)
if (!metadata) return
const { contentType, customMetadata: { fileName } } = metadata
const url = await fileRef.getDownloadURL()
downloadFile(url, fileName, contentType)
Expand All @@ -71,7 +71,10 @@ function downloadFile(url, fileName, contentType) {
const xhr = new XMLHttpRequest()
xhr.responseType = 'blob'
xhr.onload = () => downloadComplete(xhr.response, fileName, contentType)
xhr.onloadend = () => checkDownloadStatus(xhr.status)
xhr.onprogress = (e) => setDownloadProgress(e)
xhr.onerror = () => showError()
xhr.on
xhr.open('GET', url)
xhr.send()
}
Expand Down Expand Up @@ -127,8 +130,18 @@ function downloadComplete(blob, fileName, contentType) {
}


function checkDownloadStatus(status) {
if (status !== 200) {
showError()
}
}

async function getMetadata(fileRef) {
return await fileRef.getMetadata()
try {
return await fileRef.getMetadata()
} catch (error) {
showError()
}
}


Expand All @@ -153,6 +166,14 @@ function openFileDialog() {
document.body.removeChild(input)
}


function showError() {
back.className = 'fas fa-exclamation-triangle'
download.classList.add('error')
root.style.setProperty('--progress', 0)
download.addEventListener('click', () => document.location.replace('/'))
}

upload.addEventListener('click', (e) => {
openFileDialog()
})
Expand All @@ -177,13 +198,11 @@ upload.addEventListener('dragover', (e) => {
window.addEventListener('load', async () => {
if ('serviceWorker' in navigator) {
try {
const reg = await navigator.serviceWorker.register('/serviceworker.js')
const reg = await navigator.serviceWorker.register('../serviceworker.js')
console.log('Service worker register success')
} catch (e) {
console.error('Service worker register fail')
}
}
pageInit()
})


13 changes: 13 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ body {

.header {
align-items: center;
justify-content: center;
display: flex;
flex-direction: row;
padding-bottom: 1.7rem;
Expand All @@ -37,6 +38,14 @@ body {
margin: 0;
}

.header a {
text-decoration: none;
}

.header a:hover {
transform: scale(1.05);
}

.divider {
border-bottom: 0.2rem var(--dark-color) solid;
height: 0.2rem;
Expand Down Expand Up @@ -114,3 +123,7 @@ body {
.download {
transform: rotateX(180deg);
}

.download.error {
border: lightcoral 1px solid;
}
Binary file modified favicon.ico
Binary file not shown.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<div class="container">
<div class="header">
<!-- <div class="divider"></div> -->
<h2>stream.io</h4>
<a href="/">
<h2>stream.io</h4>
</a>
</div>
<div class="btn">
<div class="file">
Expand Down
2 changes: 1 addition & 1 deletion serviceworker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const staticCacheName = 's-streamio-v2'
const staticCacheName = 's-streamio-v1'

const assetUrls = [
'index.html',
Expand Down

0 comments on commit 83606cd

Please sign in to comment.