feat: Add flatrate billing model for editorial accounts

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 03:27:10 +02:00
1 parent 699580a6a0
commit 0b1ffdfdfc
39 files changed
+4900 -57

No files matched your search

+18 -1
View File
@@ -4,11 +4,12 @@ import { eq, sql } from "drizzle-orm";
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
import { db } from "@/db/client";
import { albumAutoRules } from "@/db/schema";
import { albumAutoRules, editorialAccounts } from "@/db/schema";
import type * as schema from "@/db/schema";
import { albumGrantService } from "./grants";
import { immichClient } from "@/modules/immich/client";
import type { ImmichClient } from "@/modules/immich/types";
import { emailService } from "@/modules/email/service";
export type AutoRule = {
id: string;
@@ -62,6 +63,18 @@ export function createAutoRuleService({
const grantedAlbumIds = new Set(await grantService.getGrantedAlbumIds(editorialId));
let newlyGranted = 0;
let editorialEmail: string | undefined;
try {
const [editorial] = await db
.select({ email: editorialAccounts.loginEmail })
.from(editorialAccounts)
.where(eq(editorialAccounts.id, editorialId))
.limit(1);
editorialEmail = editorial?.email;
} catch (e) {
// Ignore DB error
}
for (const album of albums) {
if (grantedAlbumIds.has(album.id)) {
continue;
@@ -75,6 +88,10 @@ export function createAutoRuleService({
await grantService.grantAlbum({ editorialId, immichAlbumId: album.id, adminUserId });
newlyGranted++;
grantedAlbumIds.add(album.id);
if (editorialEmail) {
await emailService.sendNewAlbumNotification(editorialEmail, album.albumName).catch(() => {});
}
} catch (error) {
// Ignore individual album grant failures
}