mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
Refactor seed script to use 'integrations' and 'integrationEvents' instead of 'webhookConnections' and 'webhookEventLog'. Update logging messages and variable names for clarity.
This commit is contained in:
+17
-15
@@ -36,8 +36,8 @@ import {
|
|||||||
userMovieWatches,
|
userMovieWatches,
|
||||||
userRatings,
|
userRatings,
|
||||||
userTitleStatus,
|
userTitleStatus,
|
||||||
webhookConnections,
|
integrations,
|
||||||
webhookEventLog,
|
integrationEvents,
|
||||||
} from "@/lib/db/schema";
|
} from "@/lib/db/schema";
|
||||||
import { createLogger } from "@/lib/logger";
|
import { createLogger } from "@/lib/logger";
|
||||||
import { importTitle } from "@/lib/services/metadata";
|
import { importTitle } from "@/lib/services/metadata";
|
||||||
@@ -499,17 +499,18 @@ async function seedForUser(userId: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Webhook connections
|
// 6. Integrations (webhook connections)
|
||||||
log.info("Creating webhook connections...");
|
log.info("Creating integrations...");
|
||||||
const plexWebhookId = Bun.randomUUIDv7();
|
const plexWebhookId = Bun.randomUUIDv7();
|
||||||
const jellyfinWebhookId = Bun.randomUUIDv7();
|
const jellyfinWebhookId = Bun.randomUUIDv7();
|
||||||
|
|
||||||
db.insert(webhookConnections)
|
db.insert(integrations)
|
||||||
.values([
|
.values([
|
||||||
{
|
{
|
||||||
id: plexWebhookId,
|
id: plexWebhookId,
|
||||||
userId,
|
userId,
|
||||||
provider: "plex",
|
provider: "plex",
|
||||||
|
type: "webhook",
|
||||||
token: `plex_${Bun.randomUUIDv7().replace(/-/g, "").slice(0, 32)}`,
|
token: `plex_${Bun.randomUUIDv7().replace(/-/g, "").slice(0, 32)}`,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
createdAt: daysAgo(90),
|
createdAt: daysAgo(90),
|
||||||
@@ -519,6 +520,7 @@ async function seedForUser(userId: string) {
|
|||||||
id: jellyfinWebhookId,
|
id: jellyfinWebhookId,
|
||||||
userId,
|
userId,
|
||||||
provider: "jellyfin",
|
provider: "jellyfin",
|
||||||
|
type: "webhook",
|
||||||
token: `jf_${Bun.randomUUIDv7().replace(/-/g, "").slice(0, 32)}`,
|
token: `jf_${Bun.randomUUIDv7().replace(/-/g, "").slice(0, 32)}`,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
createdAt: daysAgo(45),
|
createdAt: daysAgo(45),
|
||||||
@@ -528,10 +530,10 @@ async function seedForUser(userId: string) {
|
|||||||
.onConflictDoNothing()
|
.onConflictDoNothing()
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
// Sample webhook event log
|
// Sample integration event log
|
||||||
const webhookEvents = [
|
const integrationEventEntries = [
|
||||||
{
|
{
|
||||||
connectionId: plexWebhookId,
|
integrationId: plexWebhookId,
|
||||||
eventType: "media.scrobble",
|
eventType: "media.scrobble",
|
||||||
mediaType: "movie",
|
mediaType: "movie",
|
||||||
mediaTitle: "The Shawshank Redemption",
|
mediaTitle: "The Shawshank Redemption",
|
||||||
@@ -539,7 +541,7 @@ async function seedForUser(userId: string) {
|
|||||||
receivedAt: daysAgo(5),
|
receivedAt: daysAgo(5),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
connectionId: plexWebhookId,
|
integrationId: plexWebhookId,
|
||||||
eventType: "media.scrobble",
|
eventType: "media.scrobble",
|
||||||
mediaType: "movie",
|
mediaType: "movie",
|
||||||
mediaTitle: "Fight Club",
|
mediaTitle: "Fight Club",
|
||||||
@@ -547,7 +549,7 @@ async function seedForUser(userId: string) {
|
|||||||
receivedAt: daysAgo(10),
|
receivedAt: daysAgo(10),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
connectionId: plexWebhookId,
|
integrationId: plexWebhookId,
|
||||||
eventType: "media.play",
|
eventType: "media.play",
|
||||||
mediaType: "movie",
|
mediaType: "movie",
|
||||||
mediaTitle: "Unknown Movie",
|
mediaTitle: "Unknown Movie",
|
||||||
@@ -555,7 +557,7 @@ async function seedForUser(userId: string) {
|
|||||||
receivedAt: daysAgo(12),
|
receivedAt: daysAgo(12),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
connectionId: jellyfinWebhookId,
|
integrationId: jellyfinWebhookId,
|
||||||
eventType: "PlaybackStop",
|
eventType: "PlaybackStop",
|
||||||
mediaType: "episode",
|
mediaType: "episode",
|
||||||
mediaTitle: "House of the Dragon S01E05",
|
mediaTitle: "House of the Dragon S01E05",
|
||||||
@@ -563,7 +565,7 @@ async function seedForUser(userId: string) {
|
|||||||
receivedAt: daysAgo(30),
|
receivedAt: daysAgo(30),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
connectionId: jellyfinWebhookId,
|
integrationId: jellyfinWebhookId,
|
||||||
eventType: "PlaybackStop",
|
eventType: "PlaybackStop",
|
||||||
mediaType: "episode",
|
mediaType: "episode",
|
||||||
mediaTitle: "House of the Dragon S01E06",
|
mediaTitle: "House of the Dragon S01E06",
|
||||||
@@ -573,10 +575,10 @@ async function seedForUser(userId: string) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const event of webhookEvents) {
|
for (const event of integrationEventEntries) {
|
||||||
db.insert(webhookEventLog).values(event).run();
|
db.insert(integrationEvents).values(event).run();
|
||||||
}
|
}
|
||||||
log.info(` Created 2 webhook connections + ${webhookEvents.length} events`);
|
log.info(` Created 2 integrations + ${integrationEventEntries.length} events`);
|
||||||
|
|
||||||
// 7. Cron run history
|
// 7. Cron run history
|
||||||
log.info("Creating cron run history...");
|
log.info("Creating cron run history...");
|
||||||
|
|||||||
Reference in New Issue
Block a user