-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show upload progress for audio/video loop files
- Loading branch information
1 parent
f8b5b78
commit 7af8efd
Showing
11 changed files
with
192 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Box from '@mui/material/Box'; | ||
import CircularProgress from '@mui/material/CircularProgress'; | ||
import Typography from '@mui/material/Typography'; | ||
|
||
export default function Component({ color = 'inherit', value = -1 }) { | ||
if (value < 0) { | ||
return <CircularProgress color={color} />; | ||
} | ||
|
||
return ( | ||
<Box sx={{ position: 'relative', display: 'inline-flex' }}> | ||
<CircularProgress variant="determinate" value={value} color={color} /> | ||
<Box | ||
sx={{ | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
position: 'absolute', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}} | ||
> | ||
<Typography component="div" sx={{ color: 'text.secondary' }}> | ||
{`${Math.round(value)}%`} | ||
</Typography> | ||
</Box> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const fetch = async (url, options = {}) => { | ||
options = { | ||
method: 'GET', | ||
...options, | ||
}; | ||
|
||
options.method = options.method.toUpperCase(); | ||
|
||
const xhr = new XMLHttpRequest(); | ||
|
||
return new Promise((resolve, reject) => { | ||
xhr.responseType = 'text'; | ||
xhr.onload = () => { | ||
const response = { | ||
ok: false, | ||
headers: { | ||
get: function (key) { | ||
return this.data.get(key.toLowerCase()); | ||
}, | ||
data: xhr | ||
.getAllResponseHeaders() | ||
.split('\r\n') | ||
.reduce((result, current) => { | ||
let [name, value] = current.split(': '); | ||
result.set(name, value); | ||
return result; | ||
}, new Map()), | ||
}, | ||
status: xhr.status, | ||
statusText: xhr.statusText, | ||
data: xhr.response, | ||
json: function () { | ||
return JSON.parse(this.data); | ||
}, | ||
text: function () { | ||
return this.data; | ||
}, | ||
}; | ||
if (xhr.status < 200 || xhr.status >= 300) { | ||
resolve(response); | ||
} else { | ||
response.ok = true; | ||
resolve(response); | ||
} | ||
}; | ||
xhr.onerror = () => { | ||
reject({ | ||
message: 'network error', | ||
}); | ||
}; | ||
if ('onprogress' in options && typeof options.onprogress == 'function') { | ||
const tracker = (event) => { | ||
if (!event.lengthComputable) { | ||
options.onprogress(false, 0, event.loaded); | ||
return; | ||
} | ||
|
||
options.onprogress(true, event.loaded / event.total, event.total); | ||
}; | ||
|
||
if (options.method === 'GET') { | ||
xhr.onprogress = tracker; | ||
} else if (options.method === 'PUT' || options.method === 'POST') { | ||
xhr.upload.onprogress = tracker; | ||
} | ||
} | ||
xhr.open(options.method, url, true); | ||
if ('headers' in options) { | ||
for (const header in options.headers) { | ||
xhr.setRequestHeader(header, options.headers[header]); | ||
} | ||
} | ||
if ('body' in options) { | ||
xhr.send(options.body); | ||
} else { | ||
xhr.send(); | ||
} | ||
}); | ||
}; | ||
|
||
export { fetch }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.