Skip to content

Commit

Permalink
docs: when can't import binary, info user to enable filter
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Feb 8, 2024
1 parent 7ee6a02 commit 2c9356e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/pages/Importer/useImportBinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function useImportBinary(newWorkspace: IWikiWorkspace | undefined) {
});
setImportSuccess(true);
} catch (error) {
setError(`Failed to import binary tiddlers: ${(error as Error).message} ${(error as Error).stack ?? ''}`);
setError(`Failed to import binary tiddlers, maybe you forget to enable custom filter in Tiddlywiki?: ${(error as Error).message} ${(error as Error).stack ?? ''}`);
} finally {
setImportingBinary(false);
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/ImportService/ExpoReadStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export class ExpoReadStream extends Readable {
const fileInfo = await fs.getInfoAsync(this.fileUri, { size: true });
if (fileInfo.exists) {
this.fileSize = fileInfo.size ?? 0;
} else {
this.fileSize = 0;
}
if (this.fileSize === 0) {
this.emit('error', new Error('File size is 0'));
}
} catch (error) {
this.emit('error', error);
Expand All @@ -43,7 +44,6 @@ export class ExpoReadStream extends Readable {
length: this.chunkSize,
} satisfies fs.ReadingOptions;
fs.readAsStringAsync(this.fileUri, readingOptions).then(chunk => {

if (chunk.length === 0) {
// End of the stream
this.emit('progress', 1);
Expand Down
7 changes: 4 additions & 3 deletions src/services/ImportService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ export class ImportService {
const JSON_READ_LENGTH = 512 * 1024;
// get content length use first pass
let dataCount = 0;
const binaryFileListPath = getWikiBinaryTiddlersListCachePath(workspace);
try {
const readStream = createReadStream(getWikiBinaryTiddlersListCachePath(workspace), { length: JSON_READ_LENGTH * 2 });
const readStream = createReadStream(binaryFileListPath, { length: JSON_READ_LENGTH * 2 });
readStream.on('progress', (progress: number) => {
setProgress.setReadListProgress(progress);
});
Expand Down Expand Up @@ -275,13 +276,13 @@ export class ImportService {
});
});
} catch (error) {
throw new Error(`loadBinaryTiddlersAsFilesFromServer() Failed to read tiddler text store, ${(error as Error).message}`);
throw new Error(`loadBinaryTiddlersAsFilesFromServer() Failed to read tiddler text store ${binaryFileListPath}, ${(error as Error).message}`);
}
// reset progress, start really processing data.
setProgress.setReadListProgress(0);
let batchedBinaryTiddlerFieldsStream: Chain;
try {
const readStream = createReadStream(getWikiBinaryTiddlersListCachePath(workspace), { length: JSON_READ_LENGTH });
const readStream = createReadStream(binaryFileListPath, { length: JSON_READ_LENGTH });
readStream.on('progress', (progress: number) => {
setProgress.setReadListProgress(progress);
});
Expand Down

0 comments on commit 2c9356e

Please sign in to comment.