MCPcopy
hub / github.com/ranuts/document / readMediaFiles

Method readMediaFiles

lib/document-converter.ts:189–226  ·  view source on GitHub ↗

* Read media files

()

Source from the content-addressed store, hash-verified

187 * Read media files
188 */
189 private async readMediaFiles(): Promise<Record<string, string>> {
190 if (!this.x2tModule) return {};
191
192 const media: Record<string, string> = {};
193
194 try {
195 const files = this.x2tModule.FS.readdir('/working/media/');
196
197 // Use Promise.all to handle async createObjectURL
198 const mediaPromises = files
199 .filter((file) => file !== '.' && file !== '..')
200 .map(async (file) => {
201 try {
202 const fileData = this.x2tModule!.FS.readFile(`/working/media/${file}`, {
203 encoding: 'binary',
204 }) as BlobPart;
205
206 const blob = new Blob([fileData]);
207 const mediaUrl = await createObjectURL(blob);
208 return { key: `media/${file}`, url: mediaUrl };
209 } catch (error) {
210 console.warn(`Failed to read media file ${file}:`, error);
211 return null;
212 }
213 });
214
215 const results = await Promise.all(mediaPromises);
216 results.forEach((result) => {
217 if (result) {
218 media[result.key] = result.url;
219 }
220 });
221 } catch (error) {
222 console.warn('Failed to read media directory:', error);
223 }
224
225 return media;
226 }
227
228 /**
229 * Load xlsx library from local file

Callers 2

convertDocumentMethod · 0.95
convertCsvDirectlyMethod · 0.95

Calls 2

readdirMethod · 0.80
readFileMethod · 0.80

Tested by

no test coverage detected