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:
parent
0438daa6e3
commit
cac556a816
3 changed files with 11 additions and 11 deletions
|
|
@ -97,7 +97,7 @@ export async function fetchAllDatabaseCloudinaryReferences(): Promise<Set<string
|
||||||
if (publicId) publicIds.add(publicId)
|
if (publicId) publicIds.add(publicId)
|
||||||
}
|
}
|
||||||
if (project.gallery && typeof project.gallery === 'object') {
|
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) {
|
for (const item of gallery) {
|
||||||
if (item.url?.includes('cloudinary.com')) {
|
if (item.url?.includes('cloudinary.com')) {
|
||||||
const publicId = extractPublicId(item.url)
|
const publicId = extractPublicId(item.url)
|
||||||
|
|
@ -121,7 +121,7 @@ export async function fetchAllDatabaseCloudinaryReferences(): Promise<Set<string
|
||||||
if (publicId) publicIds.add(publicId)
|
if (publicId) publicIds.add(publicId)
|
||||||
}
|
}
|
||||||
if (post.attachments && typeof post.attachments === 'object') {
|
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) {
|
for (const attachment of attachments) {
|
||||||
if (attachment.url?.includes('cloudinary.com')) {
|
if (attachment.url?.includes('cloudinary.com')) {
|
||||||
const publicId = extractPublicId(attachment.url)
|
const publicId = extractPublicId(attachment.url)
|
||||||
|
|
@ -296,7 +296,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
|
||||||
|
|
||||||
for (const project of projectsToClean) {
|
for (const project of projectsToClean) {
|
||||||
let updated = false
|
let updated = false
|
||||||
const updates: any = {}
|
const updates: Record<string, unknown> = {}
|
||||||
|
|
||||||
if (project.featuredImage?.includes('cloudinary.com')) {
|
if (project.featuredImage?.includes('cloudinary.com')) {
|
||||||
const publicId = extractPublicId(project.featuredImage)
|
const publicId = extractPublicId(project.featuredImage)
|
||||||
|
|
@ -316,7 +316,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
|
||||||
|
|
||||||
// Handle gallery items
|
// Handle gallery items
|
||||||
if (project.gallery && typeof project.gallery === 'object') {
|
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) => {
|
const cleanedGallery = gallery.filter((item) => {
|
||||||
if (item.url?.includes('cloudinary.com')) {
|
if (item.url?.includes('cloudinary.com')) {
|
||||||
const publicId = extractPublicId(item.url)
|
const publicId = extractPublicId(item.url)
|
||||||
|
|
@ -349,7 +349,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
|
||||||
|
|
||||||
for (const post of postsToClean) {
|
for (const post of postsToClean) {
|
||||||
let updated = false
|
let updated = false
|
||||||
const updates: any = {}
|
const updates: Record<string, unknown> = {}
|
||||||
|
|
||||||
if (post.featuredImage?.includes('cloudinary.com')) {
|
if (post.featuredImage?.includes('cloudinary.com')) {
|
||||||
const publicId = extractPublicId(post.featuredImage)
|
const publicId = extractPublicId(post.featuredImage)
|
||||||
|
|
@ -361,7 +361,7 @@ export async function cleanupBrokenReferences(publicIds: string[]): Promise<{
|
||||||
|
|
||||||
// Handle attachments
|
// Handle attachments
|
||||||
if (post.attachments && typeof post.attachments === 'object') {
|
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) => {
|
const cleanedAttachments = attachments.filter((attachment) => {
|
||||||
if (attachment.url?.includes('cloudinary.com')) {
|
if (attachment.url?.includes('cloudinary.com')) {
|
||||||
const publicId = extractPublicId(attachment.url)
|
const publicId = extractPublicId(attachment.url)
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ export interface UploadResult {
|
||||||
format?: string
|
format?: string
|
||||||
size?: number
|
size?: number
|
||||||
dominantColor?: string
|
dominantColor?: string
|
||||||
colors?: any
|
colors?: Array<{ hex: string; rgb: [number, number, number]; population: number }>
|
||||||
aspectRatio?: number
|
aspectRatio?: number
|
||||||
duration?: number
|
duration?: number
|
||||||
videoCodec?: string
|
videoCodec?: string
|
||||||
|
|
@ -82,7 +82,7 @@ export interface UploadResult {
|
||||||
export async function uploadFile(
|
export async function uploadFile(
|
||||||
file: File,
|
file: File,
|
||||||
type: 'media' | 'photos' | 'projects' = 'media',
|
type: 'media' | 'photos' | 'projects' = 'media',
|
||||||
customOptions?: any
|
customOptions?: Record<string, unknown>
|
||||||
): Promise<UploadResult> {
|
): Promise<UploadResult> {
|
||||||
try {
|
try {
|
||||||
// Toggle this to use Cloudinary in development (requires API keys)
|
// Toggle this to use Cloudinary in development (requires API keys)
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ function getFieldDisplayName(fieldName: string): string {
|
||||||
/**
|
/**
|
||||||
* Extract media IDs from various data structures
|
* 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]
|
const value = data[fieldName]
|
||||||
if (!value) return []
|
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)
|
* 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 []
|
if (!content || typeof content !== 'object') return []
|
||||||
|
|
||||||
const mediaIds: number[] = []
|
const mediaIds: number[] = []
|
||||||
|
|
||||||
function traverse(node: any) {
|
function traverse(node: unknown) {
|
||||||
if (!node) return
|
if (!node) return
|
||||||
|
|
||||||
// Handle image nodes
|
// Handle image nodes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue