|
1 | | -import * as functions from "firebase-functions" |
2 | | -import { RuntimeOptions, runWith } from "firebase-functions" |
| 1 | +import * as functions from "firebase-functions/v1" |
| 2 | +import { RuntimeOptions, runWith } from "firebase-functions/v1" |
| 3 | +import { onCall, CallableRequest } from "firebase-functions/v2/https" |
3 | 4 | import { DateTime } from "luxon" |
4 | 5 | import { JSDOM } from "jsdom" |
5 | 6 | import { AssemblyAI } from "assemblyai" |
@@ -476,6 +477,52 @@ export const scrapeSingleHearing = functions |
476 | 477 | } |
477 | 478 | }) |
478 | 479 |
|
| 480 | +export const scrapeSingleHearingv2 = onCall( |
| 481 | + { timeoutSeconds: 480, memory: "4GiB", secrets: ["ASSEMBLY_API_KEY"] }, |
| 482 | + async (request: CallableRequest) => { |
| 483 | + // Require admin authentication |
| 484 | + // Check how to integrate the new object with these helper functions |
| 485 | + checkAuth(request, false) |
| 486 | + checkAdmin(request) |
| 487 | + |
| 488 | + const { eventId } = request.data |
| 489 | + |
| 490 | + if (!eventId || typeof eventId !== "number") { |
| 491 | + throw new functions.https.HttpsError( |
| 492 | + "invalid-argument", |
| 493 | + "The function must be called with a valid eventId (number)." |
| 494 | + ) |
| 495 | + } |
| 496 | + |
| 497 | + try { |
| 498 | + // Create a temporary scraper instance to reuse the existing logic |
| 499 | + const scraper = new HearingScraper() |
| 500 | + const hearing = await scraper.getEvent( |
| 501 | + { EventId: eventId }, |
| 502 | + { ignoreCutoff: true } |
| 503 | + ) |
| 504 | + |
| 505 | + // Save the hearing to Firestore |
| 506 | + await db.doc(`/events/${hearing.id}`).set(hearing, { merge: true }) |
| 507 | + |
| 508 | + console.log(`Successfully scraped hearing ${eventId}`, hearing) |
| 509 | + |
| 510 | + return { |
| 511 | + status: "success", |
| 512 | + message: `Successfully scraped hearing ${eventId}`, |
| 513 | + hearingId: hearing.id |
| 514 | + } |
| 515 | + } catch (error: any) { |
| 516 | + console.error(`Failed to scrape hearing ${eventId}:`, error) |
| 517 | + throw new functions.https.HttpsError( |
| 518 | + "internal", |
| 519 | + `Failed to scrape hearing ${eventId}`, |
| 520 | + { details: error.message } |
| 521 | + ) |
| 522 | + } |
| 523 | + } |
| 524 | +) |
| 525 | + |
479 | 526 | export const scrapeSpecialEvents = new SpecialEventsScraper().function |
480 | 527 | export const scrapeSessions = new SessionScraper().function |
481 | 528 | export const scrapeHearings = new HearingScraper().function |
0 commit comments