Spaces:
Running
Running
Update src/containers/sb3-downloader.jsx
Browse files
src/containers/sb3-downloader.jsx
CHANGED
@@ -97,13 +97,17 @@ class SB3Downloader extends React.Component {
|
|
97 |
return;
|
98 |
}
|
99 |
try {
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
} catch (e) {
|
108 |
this.handleSaveError(e);
|
109 |
}
|
@@ -121,6 +125,42 @@ class SB3Downloader extends React.Component {
|
|
121 |
}
|
122 |
return this.saveAsNew();
|
123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
async saveToHandle (handle) {
|
125 |
if (!this.props.canSaveProject) {
|
126 |
return;
|
|
|
97 |
return;
|
98 |
}
|
99 |
try {
|
100 |
+
// ε€ι¨γ§γδ½Ώη¨γ§γγγγγ«γγγγγ£γ«δΏε
|
101 |
+
this.handle = {
|
102 |
+
name: this.props.projectFilename
|
103 |
+
};
|
104 |
+
this.title = getProjectTitleFromFilename(this.handle.name);
|
105 |
+
if (this.title) {
|
106 |
+
this.props.onSetProjectTitle(this.title);
|
107 |
+
}
|
108 |
+
|
109 |
+
await this.saveToBlobAndDownload();
|
110 |
+
|
111 |
} catch (e) {
|
112 |
this.handleSaveError(e);
|
113 |
}
|
|
|
125 |
}
|
126 |
return this.saveAsNew();
|
127 |
}
|
128 |
+
async saveToBlobAndDownload () {
|
129 |
+
if (!this.props.canSaveProject) return;
|
130 |
+
|
131 |
+
this.startedSaving();
|
132 |
+
|
133 |
+
// Blob γηζ
|
134 |
+
const chunks = [];
|
135 |
+
const jszipStream = this.props.saveProjectSb3Stream();
|
136 |
+
|
137 |
+
await new Promise((resolve, reject) => {
|
138 |
+
jszipStream.on('data', chunk => chunks.push(chunk));
|
139 |
+
jszipStream.on('end', resolve);
|
140 |
+
jszipStream.on('error', reject);
|
141 |
+
});
|
142 |
+
|
143 |
+
const blob = new Blob(chunks, { type: 'text/plain' }); // β γγγ text/plain γ«ε€ζ΄
|
144 |
+
|
145 |
+
// ζ‘εΌ΅εγ .txt γ§γγγγ¨γδΏθ¨Ό
|
146 |
+
let filename = this.handle.name;
|
147 |
+
if (!filename.endsWith('.txt')) {
|
148 |
+
filename = filename.replace(/\.[^/.]+$/, '') + '.txt';
|
149 |
+
}
|
150 |
+
|
151 |
+
// γγ¦γ³γγΌγγͺγ³γ―γδ½ζ
|
152 |
+
const a = document.createElement('a');
|
153 |
+
const url = URL.createObjectURL(blob);
|
154 |
+
a.href = url;
|
155 |
+
a.download = filename;
|
156 |
+
document.body.appendChild(a);
|
157 |
+
a.click();
|
158 |
+
document.body.removeChild(a);
|
159 |
+
URL.revokeObjectURL(url);
|
160 |
+
|
161 |
+
this.finishedSaving();
|
162 |
+
}
|
163 |
+
|
164 |
async saveToHandle (handle) {
|
165 |
if (!this.props.canSaveProject) {
|
166 |
return;
|