initial commit

This commit is contained in:
yiling
2026-05-19 16:05:09 +08:00
commit 9cad96210c
370 changed files with 131609 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
import { createAuthClient } from 'better-auth/react'
export const authClient = createAuthClient({
// eslint-disable-next-line @typescript-eslint/naming-convention
baseURL: window.location.origin,
})
export const { signIn, signUp, useSession, signOut } = authClient
+5
View File
@@ -0,0 +1,5 @@
export function arrayMove<T>(array: T[], from: number, to: number): T[] {
const newArray = array.slice()
newArray.splice(to, 0, newArray.splice(from, 1)[0])
return newArray
}
+45
View File
@@ -0,0 +1,45 @@
import type { ImageTranscode, VideoTranscode } from '@/dtos/asset'
type Transcode = ImageTranscode | VideoTranscode
export function getBestTranscode(
transcodes: Transcode[] | undefined,
screenWidth: number,
): Transcode | null {
if (!transcodes || transcodes.length === 0) {
return null
}
// Filter out raw versions unless they are the only option
const nonRaw = transcodes.filter((t) => !t.isRaw)
const candidates = nonRaw.length > 0 ? nonRaw : transcodes
// Sort by width descending to easily find largest available
// If widths are equal, prefer the one that is NOT raw (transcoded optimized version)
const sorted = [...candidates].sort((a, b) => {
const wA = a.width ?? 0
const wB = b.width ?? 0
if (wA !== wB) {
return wB - wA // Descending width
}
// If widths equal, prefer non-raw (optimized)
return (a.isRaw ? 1 : 0) - (b.isRaw ? 1 : 0)
})
// Find smallest width that is >= screenWidth
const suitable = sorted.filter((t) => (t.width ?? 0) >= screenWidth)
if (suitable.length > 0) {
// Sort suitable by width ASCENDING to find "smallest fit".
suitable.sort((a, b) => {
const wA = a.width ?? 0
const wB = b.width ?? 0
if (wA !== wB) return wA - wB // Ascending
return (a.isRaw ? 1 : 0) - (b.isRaw ? 1 : 0) // Non-raw first
})
return suitable[0]
}
// If no candidate >= screenWidth, simply return the largest available (first in original sorted)
return sorted[0]
}
+41
View File
@@ -0,0 +1,41 @@
import { differenceInDays, format, isToday, isYesterday, parseISO } from 'date-fns'
export const formatTimeAgo = (dateString: string) => {
const date = parseISO(dateString)
const now = new Date()
if (isNaN(date.getTime())) {
return dateString
}
const time = format(date, 'HH:mm')
if (isToday(date)) {
return `Today ${time}`
}
if (isYesterday(date)) {
return `Yesterday ${time}`
}
const daysAgo = differenceInDays(now, date)
return `${daysAgo >= 0 ? daysAgo : 0} days ago`
}
export const formatDateAgo = (dateString: string) => {
const date = parseISO(dateString)
const now = new Date()
if (isNaN(date.getTime())) {
return dateString
}
if (isToday(date)) {
return 'Today'
}
if (isYesterday(date)) {
return 'Yesterday'
}
const daysAgo = differenceInDays(now, date)
return `${daysAgo >= 0 ? daysAgo : 0} days ago`
}
+6
View File
@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}