|
887 | 887 |
|
888 | 888 | console.log(`file ${i}: ${file.name}`);
|
889 | 889 |
|
890 |
| - const _loadModel = u => { |
| 890 | + const reader = new FileReader(); |
| 891 | + reader.onload = async e => { |
| 892 | + let data = new Uint8Array(reader.result, 0, reader.result.byteLength); |
| 893 | + const d = '/lol'; |
| 894 | + const p = `${d}/${file.name}`; |
| 895 | + console.log('writing', p, data.byteLength); |
| 896 | + await localforage.write(p, data); |
| 897 | + data = null; |
| 898 | + data = await localforage.read(p); |
| 899 | + console.log('got file', data.map(data => data.length)); |
| 900 | + const u = URL.createObjectURL(new Blob(data, { |
| 901 | + type: 'application/octet-stream', |
| 902 | + })); |
891 | 903 | _addNewApp(u, faviconImg, 'model', -1);
|
892 | 904 | };
|
893 |
| - const _loadLocal = () => { |
894 |
| - console.log('loading', file.name); |
895 |
| - const reader = new FileReader(); |
896 |
| - reader.onload = async e => { |
897 |
| - let data = new Uint8Array(reader.result, 0, reader.result.byteLength); |
898 |
| - const d = '/lol'; |
899 |
| - const p = `${d}/${file.name}`; |
900 |
| - console.log('writing', p, data.byteLength); |
901 |
| - await localforage.write(p, data); |
902 |
| - data = null; |
903 |
| - data = await localforage.read(p); |
904 |
| - console.log('got file', data.map(data => data.length)); |
905 |
| - const u = URL.createObjectURL(new Blob(data, { |
906 |
| - type: 'application/octet-stream', |
907 |
| - })); |
908 |
| - _loadModel(u); |
909 |
| - }; |
910 |
| - reader.readAsArrayBuffer(file); |
911 |
| - }; |
912 |
| - const _loadRemote = () => { |
913 |
| - const u = `https://webaverse.s3.amazonaws.com/lol/${file.name}`; |
914 |
| - fetch(u, { |
915 |
| - method: 'PUT', |
916 |
| - body: file, |
917 |
| - mode: 'cors', |
918 |
| - }) |
919 |
| - .then(res => res.arrayBuffer()) |
920 |
| - .then(() => { |
921 |
| - _loadModel(u); |
922 |
| - }) |
923 |
| - .catch(err => { |
924 |
| - console.warn(err.stack); |
925 |
| - }); |
926 |
| - }; |
927 |
| - if (!_isInMultiverse()) { |
928 |
| - _loadLocal(); |
929 |
| - } else { |
930 |
| - _loadRemote(); |
931 |
| - } |
| 905 | + reader.readAsArrayBuffer(file); |
932 | 906 | }
|
933 | 907 | }
|
934 | 908 | }
|
|
0 commit comments