-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
51 lines (48 loc) · 1.37 KB
/
Copy pathapi.ts
File metadata and controls
51 lines (48 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { httpsCallable } from "firebase/functions";
import { FIREBASE_FUNCTIONS } from "../../firebaseConfig";
/**
* Example of calling a Firebase Cloud Function (API)
*
* Replace 'getFactualCheck' with the name of your actual function.
*/
export const getFactCheck = async (content: string) => {
try {
const factCheckFunction = httpsCallable(
FIREBASE_FUNCTIONS,
"getFactualCheck",
);
const result = await factCheckFunction({ content });
return result.data;
} catch (error) {
console.error("Error calling fact-check API, using mock data:", error);
// Return mock data for local simulation/testing
return {
status: "verified",
confidence: 0.95,
source: "Verified News Source (Simulated)",
message:
"This content aligns with verified factual reports about " +
content.substring(0, 20) +
"...",
};
}
};
/**
* If you are using a standard REST API endpoint outside of Firebase Functions,
* you can use standard fetch:
*/
export const callExternalApi = async (url: string, body: any) => {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
return await response.json();
} catch (error) {
console.error("API call failed:", error);
throw error;
}
};