Skip to content

Commit 2ba2b5b

Browse files
authored
fetchOpenGraphData protobus migration (RooCodeInc#3549)
1 parent 0dad8e1 commit 2ba2b5b

File tree

10 files changed

+251
-56
lines changed

10 files changed

+251
-56
lines changed

.changeset/good-ducks-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
fetchOpenGraphData protobus migration

proto/web.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ import "common.proto";
88

99
service WebService {
1010
rpc checkIsImageUrl(StringRequest) returns (IsImageUrl);
11+
rpc fetchOpenGraphData(StringRequest) returns (OpenGraphData);
1112
}
1213

1314
message IsImageUrl {
1415
bool is_image = 1;
1516
string url = 2;
1617
}
18+
19+
message OpenGraphData {
20+
string title = 1;
21+
string description = 2;
22+
string image = 3;
23+
string url = 4;
24+
string site_name = 5;
25+
string type = 6;
26+
}

src/core/controller/index.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ export class Controller {
338338
vscode.env.openExternal(vscode.Uri.parse(message.url))
339339
}
340340
break
341-
case "fetchOpenGraphData":
342-
this.fetchOpenGraphData(message.text!)
343-
break
344341
case "openMention":
345342
openMention(message.text)
346343
break
@@ -1475,30 +1472,6 @@ export class Controller {
14751472

14761473
// secrets
14771474

1478-
// Open Graph Data
1479-
1480-
async fetchOpenGraphData(url: string) {
1481-
try {
1482-
// Use the fetchOpenGraphData function from link-preview.ts
1483-
const ogData = await fetchOpenGraphData(url)
1484-
1485-
// Send the data back to the webview
1486-
await this.postMessageToWebview({
1487-
type: "openGraphData",
1488-
openGraphData: ogData,
1489-
url: url,
1490-
})
1491-
} catch (error) {
1492-
console.error(`Error fetching Open Graph data for ${url}:`, error)
1493-
// Send an error response
1494-
await this.postMessageToWebview({
1495-
type: "openGraphData",
1496-
error: `Failed to fetch Open Graph data: ${error}`,
1497-
url: url,
1498-
})
1499-
}
1500-
}
1501-
15021475
// Git commit message generation
15031476

15041477
async generateGitCommitMessage() {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Controller } from ".."
2+
import { StringRequest } from "../../../shared/proto/common"
3+
import { OpenGraphData } from "../../../shared/proto/web"
4+
import { fetchOpenGraphData as fetchOGData } from "../../../integrations/misc/link-preview"
5+
import { convertDomainOpenGraphDataToProto } from "../../../shared/proto-conversions/web/open-graph-conversion"
6+
7+
/**
8+
* Fetches Open Graph metadata from a URL
9+
* @param controller The controller instance
10+
* @param request The request containing the URL to fetch metadata from
11+
* @returns Promise resolving to OpenGraphData
12+
*/
13+
export async function fetchOpenGraphData(controller: Controller, request: StringRequest): Promise<OpenGraphData> {
14+
try {
15+
const url = request.value || ""
16+
// Fetch open graph data using the existing utility
17+
const ogData = await fetchOGData(url)
18+
19+
// Convert domain model to proto model
20+
return convertDomainOpenGraphDataToProto(ogData)
21+
} catch (error) {
22+
console.error(`Error fetching Open Graph data: ${request.value}`, error)
23+
// Return empty OpenGraphData object
24+
return OpenGraphData.create({})
25+
}
26+
}

src/core/controller/web/methods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
// Import all method implementations
55
import { registerMethod } from "./index"
66
import { checkIsImageUrl } from "./checkIsImageUrl"
7+
import { fetchOpenGraphData } from "./fetchOpenGraphData"
78

89
// Register all web service methods
910
export function registerAllMethods(): void {
1011
// Register each method with the registry
1112
registerMethod("checkIsImageUrl", checkIsImageUrl)
13+
registerMethod("fetchOpenGraphData", fetchOpenGraphData)
1214
}

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export interface WebviewMessage {
3939
| "fetchLatestMcpServersFromHub"
4040
| "telemetrySetting"
4141
| "openSettings"
42-
| "fetchOpenGraphData"
4342
| "invoke"
4443
| "updateSettings"
4544
| "clearAllTaskHistory"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { OpenGraphData as DomainOpenGraphData } from "@integrations/misc/link-preview"
2+
import { OpenGraphData as ProtoOpenGraphData } from "@shared/proto/web"
3+
4+
/**
5+
* Converts domain OpenGraphData objects to proto OpenGraphData objects
6+
* @param ogData Domain OpenGraphData object
7+
* @returns Proto OpenGraphData object
8+
*/
9+
export function convertDomainOpenGraphDataToProto(ogData: DomainOpenGraphData): ProtoOpenGraphData {
10+
return ProtoOpenGraphData.create({
11+
title: ogData.title || "",
12+
description: ogData.description || "",
13+
image: ogData.image || "",
14+
url: ogData.url || "",
15+
siteName: ogData.siteName || "",
16+
type: ogData.type || "",
17+
})
18+
}

src/shared/proto/web.ts

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/standalone/server-setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { taskFeedback } from "../core/controller/task/taskFeedback"
6767

6868
// Web Service
6969
import { checkIsImageUrl } from "../core/controller/web/checkIsImageUrl"
70+
import { fetchOpenGraphData } from "../core/controller/web/fetchOpenGraphData"
7071

7172
export function addServices(
7273
server: grpc.Server,
@@ -157,5 +158,6 @@ export function addServices(
157158
// Web Service
158159
server.addService(proto.cline.WebService.service, {
159160
checkIsImageUrl: wrapper(checkIsImageUrl, controller),
161+
fetchOpenGraphData: wrapper(fetchOpenGraphData, controller),
160162
})
161163
}

0 commit comments

Comments
 (0)