fix: replace any types in Cloudinary and media utilities (11 errors)

Phase 1 Batch 7: Cloudinary & Media type safety improvements

Fixed 11 any-type errors across 3 files:

1. src/lib/server/cloudinary.ts (2 errors)
   - Fixed UploadResult.colors: Array<{hex, rgb, population}> (line 72)
   - Fixed uploadFile customOptions: Record<string, unknown> (line 85)

2. src/lib/server/cloudinary-audit.ts (6 errors)
   - Fixed gallery arrays: Record<string, unknown>[] (lines 100, 319)
   - Fixed attachments arrays: Record<string, unknown>[] (lines 124, 364)
   - Fixed updates objects: Record<string, unknown> (lines 299, 352)

3. src/lib/server/media-usage.ts (3 errors)
   - Fixed extractMediaIds data parameter: unknown (line 188)
   - Fixed extractMediaFromRichText content parameter: unknown (line 227)
   - Fixed traverse node parameter: unknown (line 232)

Progress: 11 any-type errors remaining (down from 22)
This commit is contained in:
Justin Edmund 2025-11-24 02:41:39 -08:00
parent 0438daa6e3
commit cac556a816
3 changed files with 11 additions and 11 deletions

View file

@ -97,7 +97,7 @@ export async function fetchAllDatabaseCloudinaryReferences(): Promise<Set<string
if (publicId) publicIds.add(publicId)
}
if (project.gallery && typeof project.gallery === 'object') {
const gallery = project.gallery as any[]
const gallery = project.gallery as Record<string, unknown>[]
for (const item of gallery) {
if (item.url?.includes('cloudinary.com')) {
const publicId = extractPublicId(item.url)
@ -121,7 +121,7 @@ export async function fetchAllDatabaseCloudinaryReferences(): Promise<Set<string
if (publicId) publicIds.add(publicId)
}
if (post.attachments && typeof post.attachments === 'object') {
const attachments = post.attachments as any[]
const attachments = post.attachments as Record<string, unknown>[]
for (const attachment of attachments) {
if (attachment.url?.includes('cloudinary.com')) {
const publicId = extractPublicId(attachment.url)
@ -296,7 +296,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
for (const project of projectsToClean) {
let updated = false
const updates: any = {}
const updates: Record<string, unknown> = {}
if (project.featuredImage?.includes('cloudinary.com')) {
const publicId = extractPublicId(project.featuredImage)
@ -316,7 +316,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
// Handle gallery items
if (project.gallery && typeof project.gallery === 'object') {
const gallery = project.gallery as any[]
const gallery = project.gallery as Record<string, unknown>[]
const cleanedGallery = gallery.filter((item) => {
if (item.url?.includes('cloudinary.com')) {
const publicId = extractPublicId(item.url)
@ -349,7 +349,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
for (const post of postsToClean) {
let updated = false
const updates: any = {}
const updates: Record<string, unknown> = {}
if (post.featuredImage?.includes('cloudinary.com')) {
const publicId = extractPublicId(post.featuredImage)
@ -361,7 +361,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
// Handle attachments
if (post.attachments && typeof post.attachments === 'object') {
const attachments = post.attachments as any[]
const attachments = post.attachments as Record<string, unknown>[]
const cleanedAttachments = attachments.filter((attachment) => {
if (attachment.url?.includes('cloudinary.com')) {
const publicId = extractPublicId(attachment.url)

View file

@ -69,7 +69,7 @@ export interface UploadResult {
format?: string
size?: number
dominantColor?: string
colors?: any
colors?: Array<{ hex: string; rgb: [number, number, number]; population: number }>
aspectRatio?: number
duration?: number
videoCodec?: string
@ -82,7 +82,7 @@ export interface UploadResult {
export async function uploadFile(
file: File,
type: 'media' | 'photos' | 'projects' = 'media',
customOptions?: any
customOptions?: Record<string, unknown>
): Promise<UploadResult> {
try {
// Toggle this to use Cloudinary in development (requires API keys)

View file

@ -185,7 +185,7 @@ function getFieldDisplayName(fieldName: string): string {
/**
* Extract media IDs from various data structures
*/
export function extractMediaIds(data: any, fieldName: string): number[] {
export function extractMediaIds(data: unknown, fieldName: string): number[] {
const value = data[fieldName]
if (!value) return []
@ -224,12 +224,12 @@ export function extractMediaIds(data: any, fieldName: string): number[] {
/**
* Extract media IDs from rich text content (TipTap/Edra JSON)
*/
function extractMediaFromRichText(content: any): number[] {
function extractMediaFromRichText(content: unknown): number[] {
if (!content || typeof content !== 'object') return []
const mediaIds: number[] = []
function traverse(node: any) {
function traverse(node: unknown) {
if (!node) return
// Handle image nodes