soiz1 commited on
Commit
59595cc
Β·
verified Β·
1 Parent(s): 0a8b9cf

Update src/containers/sb3-downloader.jsx

Browse files
Files changed (1) hide show
  1. src/containers/sb3-downloader.jsx +47 -7
src/containers/sb3-downloader.jsx CHANGED
@@ -97,13 +97,17 @@ class SB3Downloader extends React.Component {
97
  return;
98
  }
99
  try {
100
- const handle = await FileSystemAPI.showSaveFilePicker(this.props.projectFilename);
101
- await this.saveToHandle(handle);
102
- this.props.onSetFileHandle(handle);
103
- const title = getProjectTitleFromFilename(handle.name);
104
- if (title) {
105
- this.props.onSetProjectTitle(title);
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;