2020-05-18 22:44:45 +00:00
|
|
|
|
|
|
|
import { saveAs } from './utils'
|
|
|
|
import scoreinfo from './scoreinfo'
|
|
|
|
|
|
|
|
let msczBufferP: Promise<ArrayBuffer> | undefined
|
|
|
|
|
|
|
|
export const fetchMscz = async (): Promise<ArrayBuffer> => {
|
|
|
|
if (!msczBufferP) {
|
|
|
|
const url = scoreinfo.msczUrl
|
|
|
|
msczBufferP = (async (): Promise<ArrayBuffer> => {
|
2020-11-12 07:54:49 +00:00
|
|
|
const r = await fetch(url)
|
2020-05-18 22:44:45 +00:00
|
|
|
const data = await r.arrayBuffer()
|
|
|
|
return data
|
|
|
|
})()
|
|
|
|
}
|
|
|
|
|
|
|
|
return msczBufferP
|
|
|
|
}
|
|
|
|
|
|
|
|
export const downloadMscz = async (): Promise<void> => {
|
|
|
|
const data = new Blob([await fetchMscz()])
|
|
|
|
const filename = scoreinfo.fileName
|
|
|
|
saveAs(data, `${filename}.mscz`)
|
|
|
|
}
|