Skip to content

Commit ec1a11f

Browse files
committed
Feedback addressed from Obsidian PR review bot
1 parent 902d3aa commit ec1a11f

6 files changed

Lines changed: 127 additions & 105 deletions

File tree

src/main.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class RiverPlugin extends Plugin {
1111
syncInterval: number | null = null;
1212

1313
async onload() {
14-
console.log("Loading River Sync plugin");
14+
console.debug("Loading River Sync plugin");
1515

1616
// Load settings
1717
await this.loadSettings();
@@ -31,17 +31,17 @@ export default class RiverPlugin extends Plugin {
3131

3232
// Add command for manual sync
3333
this.addCommand({
34-
id: "sync-river-notes",
35-
name: "Sync notes from River",
34+
id: "sync-notes",
35+
name: "Sync notes",
3636
callback: async () => {
3737
await this.syncNotes();
3838
},
3939
});
4040

4141
// Add command to test connection
4242
this.addCommand({
43-
id: "test-river-connection",
44-
name: "Test River connection",
43+
id: "test-connection",
44+
name: "Test connection",
4545
callback: async () => {
4646
await this.testConnection();
4747
},
@@ -54,7 +54,7 @@ export default class RiverPlugin extends Plugin {
5454
if (this.settings.syncOnStartup) {
5555
// Delay startup sync by 2 seconds to let Obsidian fully load
5656
setTimeout(() => {
57-
this.syncNotes();
57+
void this.syncNotes();
5858
}, 2000);
5959
}
6060

@@ -64,8 +64,8 @@ export default class RiverPlugin extends Plugin {
6464
}
6565
}
6666

67-
async onunload() {
68-
console.log("Unloading River Sync plugin");
67+
onunload() {
68+
console.debug("Unloading River Sync plugin");
6969
this.stopPeriodicSync();
7070
}
7171

@@ -136,18 +136,18 @@ export default class RiverPlugin extends Plugin {
136136

137137
startPeriodicSync() {
138138
const intervalMs = this.settings.syncInterval * 60 * 1000;
139-
console.log(
139+
console.debug(
140140
`River: Starting periodic sync every ${this.settings.syncInterval} minutes`,
141141
);
142142

143143
this.syncInterval = window.setInterval(() => {
144-
this.syncNotes();
144+
void this.syncNotes();
145145
}, intervalMs);
146146
}
147147

148148
stopPeriodicSync() {
149149
if (this.syncInterval !== null) {
150-
console.log("River: Stopping periodic sync");
150+
console.debug("River: Stopping periodic sync");
151151
window.clearInterval(this.syncInterval);
152152
this.syncInterval = null;
153153
}

src/noteCreator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ export class NoteCreator {
2525
// Check if file already exists
2626
const existingFile = this.app.vault.getAbstractFileByPath(filepath);
2727
if (existingFile instanceof TFile) {
28-
console.log(`River: File already exists, updating: ${filepath}`);
28+
console.debug(`River: File already exists, updating: ${filepath}`);
2929
await this.app.vault.modify(existingFile, content);
3030
return existingFile;
3131
}
3232

3333
// Create new file
34-
console.log(`River: Creating note: ${filepath}`);
34+
console.debug(`River: Creating note: ${filepath}`);
3535
const file = await this.app.vault.create(filepath, content);
3636
return file;
3737
}
@@ -162,7 +162,7 @@ export class NoteCreator {
162162

163163
const exists = this.app.vault.getAbstractFileByPath(folder);
164164
if (!exists) {
165-
console.log(`River: Creating folder: ${folder}`);
165+
console.debug(`River: Creating folder: ${folder}`);
166166
await this.app.vault.createFolder(folder);
167167
}
168168
}

src/riverClient.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { requestUrl } from "obsidian";
12
import type {
23
PendingEmail,
34
SyncResponse,
45
MarkSyncedResponse,
56
ObsidianMetadata,
7+
SmsApiResponse,
68
} from "./types";
79

810
export class RiverClient {
@@ -28,23 +30,23 @@ export class RiverClient {
2830
}
2931

3032
const url = `${this.apiUrl}/api/staging/${this.userId}/pending`;
31-
console.log(`River: Fetching pending emails from ${url}`);
33+
console.debug(`River: Fetching pending emails from ${url}`);
3234

33-
const response = await fetch(url);
35+
const response = await requestUrl(url);
3436

35-
if (!response.ok) {
37+
if (response.status >= 400) {
3638
throw new Error(
37-
`Failed to fetch pending emails: ${response.status} ${response.statusText}`,
39+
`Failed to fetch pending emails: ${response.status}`,
3840
);
3941
}
4042

41-
const data: SyncResponse = await response.json();
43+
const data: SyncResponse = response.json;
4244

4345
if (!data.success) {
4446
throw new Error("API returned success=false");
4547
}
4648

47-
console.log(`River: Found ${data.count} pending emails`);
49+
console.debug(`River: Found ${data.count} pending emails`);
4850

4951
// Mark all emails with source
5052
const emails = data.emails.map((email) => ({
@@ -57,7 +59,7 @@ export class RiverClient {
5759

5860
// Merge and return
5961
const allMessages = [...emails, ...smsMessages];
60-
console.log(
62+
console.debug(
6163
`River: Total pending messages: ${allMessages.length} (${emails.length} emails, ${smsMessages.length} SMS)`,
6264
);
6365
return allMessages;
@@ -73,28 +75,28 @@ export class RiverClient {
7375

7476
try {
7577
const url = `${this.smsApiUrl}/api/sms/staging/pending?userId=${this.userId}`;
76-
console.log(`River: Fetching pending SMS from ${url}`);
78+
console.debug(`River: Fetching pending SMS from ${url}`);
7779

78-
const response = await fetch(url);
80+
const response = await requestUrl(url);
7981

80-
if (!response.ok) {
82+
if (response.status >= 400) {
8183
console.warn(
8284
`River: Failed to fetch SMS (${response.status}), continuing with emails only`,
8385
);
8486
return [];
8587
}
8688

87-
const data = await response.json();
89+
const data = response.json;
8890

8991
if (!data.messages || !Array.isArray(data.messages)) {
9092
console.warn("River: Invalid SMS response format");
9193
return [];
9294
}
9395

94-
console.log(`River: Found ${data.messages.length} pending SMS`);
96+
console.debug(`River: Found ${data.messages.length} pending SMS`);
9597

9698
// Transform SMS messages to PendingEmail format
97-
return data.messages.map((sms: any) => {
99+
return data.messages.map((sms: SmsApiResponse) => {
98100
const receivedDate = new Date(sms.received_at);
99101

100102
return {
@@ -132,19 +134,20 @@ export class RiverClient {
132134
if (source === "sms") {
133135
// Mark SMS as synced
134136
const url = `${this.smsApiUrl}/api/sms/staging/${messageId}/synced`;
135-
console.log(`River: Marking SMS ${messageId} as synced`);
137+
console.debug(`River: Marking SMS ${messageId} as synced`);
136138

137-
const response = await fetch(url, {
139+
const response = await requestUrl({
140+
url,
138141
method: "POST",
139142
headers: {
140143
"Content-Type": "application/json",
141144
},
142145
body: JSON.stringify({ obsidianMetadata: metadata }),
143146
});
144147

145-
if (!response.ok) {
148+
if (response.status >= 400) {
146149
throw new Error(
147-
`Failed to mark SMS as synced: ${response.status} ${response.statusText}`,
150+
`Failed to mark SMS as synced: ${response.status}`,
148151
);
149152
}
150153

@@ -153,23 +156,24 @@ export class RiverClient {
153156

154157
// Mark email as synced
155158
const url = `${this.apiUrl}/api/staging/${messageId}/mark-synced`;
156-
console.log(`River: Marking email ${messageId} as synced`);
159+
console.debug(`River: Marking email ${messageId} as synced`);
157160

158-
const response = await fetch(url, {
161+
const response = await requestUrl({
162+
url,
159163
method: "POST",
160164
headers: {
161165
"Content-Type": "application/json",
162166
},
163167
body: JSON.stringify({ obsidianMetadata: metadata }),
164168
});
165169

166-
if (!response.ok) {
170+
if (response.status >= 400) {
167171
throw new Error(
168-
`Failed to mark email as synced: ${response.status} ${response.statusText}`,
172+
`Failed to mark email as synced: ${response.status}`,
169173
);
170174
}
171175

172-
const data: MarkSyncedResponse = await response.json();
176+
const data: MarkSyncedResponse = response.json;
173177

174178
if (!data.success) {
175179
throw new Error("Failed to mark email as synced");
@@ -182,8 +186,8 @@ export class RiverClient {
182186
async testConnection(): Promise<boolean> {
183187
try {
184188
const url = `${this.apiUrl}/health`;
185-
const response = await fetch(url);
186-
return response.ok;
189+
const response = await requestUrl(url);
190+
return response.status < 400;
187191
} catch (error) {
188192
console.error("River: Connection test failed:", error);
189193
return false;

0 commit comments

Comments
 (0)