Skip to content

Commit

Permalink
fix: read file
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Sep 11, 2023
1 parent 97634fb commit 2990a17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,7 @@ class TidGiMobileFileSystemSyncAdaptor {
const title = tiddler.fields.title;
this.logger.log(`saveTiddler ${title}`);
this.addRecentUpdatedTiddlersFromClient('modifications', title);
const etag = await this.wikiStorageService.saveTiddler(
title,
tiddler.getFieldStrings(),
$tw.wiki.isBinaryTiddler(title) ? 'base64' : undefined,
);
const etag = await this.wikiStorageService.saveTiddler(title, tiddler.getFieldStrings());
if (etag === undefined) {
callback(new Error('Response from server is missing required `etag` header'));
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/services/WikiStorageService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export class WikiStorageService {
/**
* Return the e-tag
*/
async saveTiddler(title: string, fields: ITiddlerFieldsParam, encoding?: 'utf8' | 'base64'): Promise<string> {
async saveTiddler(title: string, fields: ITiddlerFieldsParam): Promise<string> {
try {
let operation: TiddlersLogOperation = TiddlersLogOperation.INSERT;
const saveFullTiddler = getFullSaveTiddlers(title).includes(title);
const { text, title: _, ...fieldsToSave } = fields as ITiddlerFieldsParam & { text?: string; title: string };
const { text, title: _, ...fieldsToSave } = fields as (ITiddlerFieldsParam & { text?: string; title: string });

// Get the database connection for the workspace
const dataSource = await sqliteServiceService.getDatabase(this.#workspace);
Expand Down Expand Up @@ -86,7 +86,8 @@ export class WikiStorageService {
if (text !== undefined && backgroundSyncService.checkIsLargeText(text, fieldsToSave.type as string)) {
// save to fs instead of sqlite. See `WikiStorageService.#loadFromServer` for how we load it later.
// `BackgroundSyncService.#updateTiddlersFromServer` will use saveToFSFromServer, but here we already have the text, so we can save it directly
await fs.writeAsStringAsync(getWikiTiddlerPathByTitle(this.#workspace, title), text, { encoding });
// don't set encoding here, otherwise read as utf8 will failed.
await fs.writeAsStringAsync(getWikiTiddlerPathByTitle(this.#workspace, title), text);
tiddler.text = null;
} else {
tiddler.text = text;
Expand Down

0 comments on commit 2990a17

Please sign in to comment.