radio-station/app/lib/importer.server.ts
Luke Bunselmeyer 4e0dc08e29 - Clean up
- Removed notes
  - Updated readme
- DB
  - Updated initial db schema
  - Updated db seed
  - Created source, station, and tag models
- Libs
   - Create content source importer
- UI
  - Added content source UI & routes
  - Updated page layout
  - Created <Breadcrumbs> component
2023-05-07 11:03:30 -04:00

25 lines
666 B
TypeScript

import type { ContentSource } from "@prisma/client";
import { fetch } from "@remix-run/node";
import { importStations } from "~/models/station.server";
export async function importSource(source: ContentSource) {
switch (source.type) {
case "json":
return importRemoteJson(source);
default:
throw new Error("Unsupported source");
}
}
export async function importRemoteJson(source: ContentSource) {
const response = await fetch(source.connectionUrl);
if (!response.ok) {
throw new Error("Failed to fetch source");
}
const { data } = await response.json();
return importStations(data);
}