fetchOpenGraphData protobus migration (#3549)
This commit is contained in:
1 parent
0dad8e178a
commit
2ba2b5b264
10 files changed
+251
-56
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { Controller } from ".."
|
||||
import { StringRequest } from "../../../shared/proto/common"
|
||||
import { OpenGraphData } from "../../../shared/proto/web"
|
||||
import { fetchOpenGraphData as fetchOGData } from "../../../integrations/misc/link-preview"
|
||||
import { convertDomainOpenGraphDataToProto } from "../../../shared/proto-conversions/web/open-graph-conversion"
|
||||
|
||||
/**
|
||||
* Fetches Open Graph metadata from a URL
|
||||
* @param controller The controller instance
|
||||
* @param request The request containing the URL to fetch metadata from
|
||||
* @returns Promise resolving to OpenGraphData
|
||||
*/
|
||||
export async function fetchOpenGraphData(controller: Controller, request: StringRequest): Promise<OpenGraphData> {
|
||||
try {
|
||||
const url = request.value || ""
|
||||
// Fetch open graph data using the existing utility
|
||||
const ogData = await fetchOGData(url)
|
||||
|
||||
// Convert domain model to proto model
|
||||
return convertDomainOpenGraphDataToProto(ogData)
|
||||
} catch (error) {
|
||||
console.error(`Error fetching Open Graph data: ${request.value}`, error)
|
||||
// Return empty OpenGraphData object
|
||||
return OpenGraphData.create({})
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@
|
||||
// Import all method implementations
|
||||
import { registerMethod } from "./index"
|
||||
import { checkIsImageUrl } from "./checkIsImageUrl"
|
||||
import { fetchOpenGraphData } from "./fetchOpenGraphData"
|
||||
|
||||
// Register all web service methods
|
||||
export function registerAllMethods(): void {
|
||||
// Register each method with the registry
|
||||
registerMethod("checkIsImageUrl", checkIsImageUrl)
|
||||
registerMethod("fetchOpenGraphData", fetchOpenGraphData)
|
||||
}
|
||||
Reference in new issue
Block a user