-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.ts
31 lines (26 loc) · 986 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { type ClassValue, clsx } from 'clsx'
import { NextResponse } from 'next/server'
import { twMerge } from 'tailwind-merge'
import { Article } from '@prisma/client'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
interface SendJson {
code?: number
data?: unknown
msg?: string
}
export function sendJson(opts: SendJson) {
return NextResponse.json({ code: 0, msg: '', ...opts }, { status: 200 })
}
export const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
export async function getFileHash(file: File) {
const arrayBuffer = await file.arrayBuffer()
const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer)
const hashArray = Array.from(new Uint8Array(hashBuffer))
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')
}
// 获取跳转文章详情路径
export function getJumpArticleDetailsUrl(info: Article) {
return info.source === '00' ? `/article/${info.id}` : `https://juejin.cn/post/${info.id}`
}