MCPcopy
hub / github.com/iChochy/NCE / loadBookConfig

Method loadBookConfig

js/ReadingSystem.js:165–196  ·  view source on GitHub ↗

* 加载课本配置(book.json) * @returns {Promise }

()

Source from the content-addressed store, hash-verified

163 * @returns {Promise<void>}
164 */
165 async loadBookConfig() {
166 if (!this.state.bookPath) {
167 this.renderEmptyState(this.config.ERROR_MESSAGES.NO_DATA);
168 return;
169 }
170
171 try {
172 const response = await fetch(`${this.state.bookPath}/book.json`);
173 const data = await response.json();
174
175 this.state.units = data.units.map((unit, index) => ({
176 ...unit,
177 id: index + 1,
178 title: unit.title,
179 audio: `${this.state.bookPath}/${unit.filename}.mp3`,
180 lrc: `${this.state.bookPath}/${unit.filename}.lrc`,
181 }));
182
183 if (this.dom.bookCover && data.bookCover) {
184 this.dom.bookCover.src = `${this.state.bookPath}/${data.bookCover}`;
185 }
186
187 // 清除缓存
188 this.lrcCache.clear();
189 this.audioPreload.clear();
190 } catch (error) {
191 console.error(this.config.ERROR_MESSAGES.LOAD_CONFIG, error);
192 this.renderEmptyState(
193 `${this.config.ERROR_MESSAGES.LOAD_CONFIG}: ${this.state.bookPath}/book.json`
194 );
195 }
196 }
197
198 /**
199 * 更新所有课本选择器

Callers 1

applyBookChangeMethod · 0.95

Calls 2

renderEmptyStateMethod · 0.95
clearMethod · 0.45

Tested by

no test coverage detected