Skip to content

Commit

Permalink
Merge branch 'besscroft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
minimua authored Dec 9, 2024
2 parents f87da6e + 49d651d commit 6cdac5f
Show file tree
Hide file tree
Showing 9 changed files with 2,168 additions and 2,114 deletions.
7 changes: 6 additions & 1 deletion app/admin/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export default function About() {
url: 'https://github.com/soxft',
avatar: 'https://avatars.githubusercontent.com/u/42080379?v=4'
},
{
name: 'Cheng Gu',
url: 'https://github.com/gucheen',
avatar: 'https://avatars.githubusercontent.com/u/1382472?v=4'
},
]
return (
<div className="flex flex-col space-y-2 h-full flex-1 w-full mx-auto items-center p-2">
Expand All @@ -58,7 +63,7 @@ export default function About() {
/>
</svg>

<p className="whitespace-nowrap text-sm">v2.0.5</p>
<p className="whitespace-nowrap text-sm">v2.0.6</p>
</span>
<span>PicImpact 是一个摄影师专用的摄影作品展示网站,基于 Next.js + Hono.js 开发。</span>
<div className="flex flex-col w-full">
Expand Down
83 changes: 76 additions & 7 deletions app/admin/settings/preferences/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { fetcher } from '~/lib/utils/fetcher'
import { toast } from 'sonner'
import { ReloadIcon } from '@radix-ui/react-icons'
import { Button } from '~/components/ui/button'
import { Switch } from '~/components/ui/switch'

export default function Preferences() {
const [title, setTitle] = useState('')
Expand All @@ -14,10 +15,23 @@ export default function Preferences() {
const [feedId, setFeedId] = useState('')
const [userId, setUserId] = useState('')
const [loading, setLoading] = useState(false)
const [previewImageMaxWidth, setPreviewImageMaxWidth] = useState('0')
const [enablePreviewImageMaxWidthLimit, setPreviewImageMaxWidthLimitEnabled] = useState(false)
const [previewQualityInput, setPreviewQualityInput] = useState('0.2')

const { data, isValidating, isLoading } = useSWR('/api/v1/settings/get-custom-info', fetcher)
const { data, isValidating, isLoading } = useSWR<{ config_key: string, config_value: string }[]>('/api/v1/settings/get-custom-info', fetcher)

async function updateInfo() {
const maxWidth = parseInt(previewImageMaxWidth)
if (isNaN(maxWidth) || maxWidth < 0) {
toast.error('预览图最大宽度限制不能小于 0')
return
}
const previewQuality = parseFloat(previewQualityInput)
if (isNaN(previewQuality) || previewQuality <= 0 || previewQuality > 1) {
toast.error('预览图压缩质量只支持0-1,大于0')
return
}
try {
setLoading(true)
await fetch('/api/v1/settings/update-custom-info', {
Expand All @@ -31,6 +45,9 @@ export default function Preferences() {
customAuthor: customAuthor,
feedId: feedId,
userId: userId,
enablePreviewImageMaxWidthLimit,
previewImageMaxWidth: maxWidth,
previewQuality,
}),
}).then(res => res.json())
toast.success('修改成功!')
Expand All @@ -42,11 +59,14 @@ export default function Preferences() {
}

useEffect(() => {
setTitle(data?.find((item: any) => item.config_key === 'custom_title')?.config_value || '')
setCustomFaviconUrl(data?.find((item: any) => item.config_key === 'custom_favicon_url')?.config_value || '')
setCustomAuthor(data?.find((item: any) => item.config_key === 'custom_author')?.config_value || '')
setFeedId(data?.find((item: any) => item.config_key === 'rss_feed_id')?.config_value || '')
setUserId(data?.find((item: any) => item.config_key === 'rss_user_id')?.config_value || '')
setTitle(data?.find((item) => item.config_key === 'custom_title')?.config_value || '')
setCustomFaviconUrl(data?.find((item) => item.config_key === 'custom_favicon_url')?.config_value || '')
setCustomAuthor(data?.find((item) => item.config_key === 'custom_author')?.config_value || '')
setFeedId(data?.find((item) => item.config_key === 'rss_feed_id')?.config_value || '')
setUserId(data?.find((item) => item.config_key === 'rss_user_id')?.config_value || '')
setPreviewImageMaxWidth(data?.find((item) => item.config_key === 'preview_max_width_limit')?.config_value?.toString() || '0')
setPreviewImageMaxWidthLimitEnabled(data?.find((item) => item.config_key === 'preview_max_width_limit_switch')?.config_value === '1')
setPreviewQualityInput(data?.find((item) => item.config_key === 'preview_quality')?.config_value || '0.2')
}, [data])

return (
Expand Down Expand Up @@ -131,6 +151,55 @@ export default function Preferences() {
className="mt-1 w-full border-none p-0 focus:border-transparent focus:outline-none focus:ring-0 sm:text-sm"
/>
</label>
<label
htmlFor="previewQuality"
className="w-full sm:w-64 block overflow-hidden rounded-md border border-gray-200 px-3 py-2 shadow-sm focus-within:border-blue-600 focus-within:ring-1 focus-within:ring-blue-600"
>
<span className="text-xs font-medium text-gray-700"> 预览图压缩质量(0-1,大于0) </span>

<input
type="text"
id="userId"
disabled={isValidating || isLoading}
value={previewQualityInput}
placeholder="请输入预览图压缩质量"
onChange={(e) => setPreviewQualityInput(e.target.value)}
className="mt-1 w-full border-none p-0 focus:border-transparent focus:outline-none focus:ring-0 sm:text-sm"
/>
</label>
<div className="flex gap-4">
<label
htmlFor="enableMaxWidthLimit"
className="w-full sm:w-64 block overflow-hidden rounded-md border border-gray-200 px-3 py-2 shadow-sm focus-within:border-blue-600 focus-within:ring-1 focus-within:ring-blue-600"
>
<span className="text-xs font-medium text-gray-700"> 预览图最大尺寸限制开关 </span>
<div>
<Switch
id="enableMaxWidthLimit"
disabled={isValidating || isLoading}
checked={enablePreviewImageMaxWidthLimit}
onCheckedChange={checked => {
setPreviewImageMaxWidthLimitEnabled(checked)
}}
/>
</div>
</label>
<label
htmlFor="maxWidth"
className="w-full sm:w-64 block overflow-hidden rounded-md border border-gray-200 px-3 py-2 shadow-sm focus-within:border-blue-600 focus-within:ring-1 focus-within:ring-blue-600"
>
<span className="text-xs font-medium text-gray-700"> 预览图最大宽度(正整数) </span>
<input
type="text"
id="maxWidth"
disabled={isValidating || isLoading}
value={previewImageMaxWidth}
placeholder="请输入预览图最大宽度限制,正整数"
onChange={(e) => setPreviewImageMaxWidth(e.target.value)}
className="mt-1 w-full border-none p-0 focus:border-transparent focus:outline-none focus:ring-0 sm:text-sm"
/>
</label>
</div>
<div className="flex w-full sm:w-64 items-center justify-center space-x-1">
<Button
variant="outline"
Expand All @@ -144,4 +213,4 @@ export default function Preferences() {
</div>
</div>
)
}
}
11 changes: 9 additions & 2 deletions components/admin/upload/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export default function FileUpload() {
)

const { data, isLoading } = useSWR('/api/v1/albums/get', fetcher)
const { data: configs } = useSWR<{ config_key: string, config_value: string }[]>('/api/v1/settings/get-custom-info', fetcher)

const previewImageMaxWidthLimitSwitchOn = configs?.find(config => config.config_key === 'preview_max_width_limit_switch')?.config_value === '1'
const previewImageMaxWidthLimit = parseInt(configs?.find(config => config.config_key === 'preview_max_width_limit')?.config_value || '0')
const previewCompressQuality = parseFloat(configs?.find(config => config.config_key === 'preview_quality')?.config_value || '0.2')

async function loadExif(file: any, outputBuffer: any, flag: boolean) {
try {
Expand Down Expand Up @@ -409,9 +414,10 @@ export default function FileUpload() {

async function uploadPreviewImage(option: any, type: string, url: string, flag: boolean, outputBuffer: any) {
new Compressor(flag ? outputBuffer : option.file, {
quality: 0.2,
quality: previewCompressQuality,
checkOrientation: false,
mimeType: 'image/webp',
maxWidth: previewImageMaxWidthLimitSwitchOn && previewImageMaxWidthLimit > 0 ? previewImageMaxWidthLimit : undefined,
async success(compressedFile) {
if (compressedFile instanceof File) {
const res = await uploadFile(compressedFile, type)
Expand Down Expand Up @@ -492,9 +498,10 @@ export default function FileUpload() {
outputBuffer.name = fileName + '.jpg'
// @ts-ignore
new Compressor(outputBuffer, {
quality: 0.2,
quality: previewCompressQuality,
checkOrientation: false,
mimeType: 'image/jpeg',
maxWidth: previewImageMaxWidthLimitSwitchOn && previewImageMaxWidthLimit > 0 ? previewImageMaxWidthLimit : undefined,
async success(compressedFile) {
if (compressedFile instanceof File) {
await uploadFile(compressedFile, album).then(async (res) => {
Expand Down
20 changes: 16 additions & 4 deletions hono/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ app.get('/get-custom-info', async (c) => {
'custom_favicon_url',
'custom_author',
'rss_feed_id',
'rss_user_id'
'rss_user_id',
'preview_max_width_limit',
'preview_max_width_limit_switch',
'preview_quality',
]);
return c.json(data)
})
Expand Down Expand Up @@ -88,9 +91,18 @@ app.put('/update-s3-info', async (c) => {
})

app.put('/update-custom-info', async (c) => {
const query = await c.req.json()
const query = await c.req.json() satisfies {
title: string
customFaviconUrl: string
customAuthor: string
feedId: string
userId: string
enablePreviewImageMaxWidthLimit: boolean
previewImageMaxWidth: number
previewQuality: number
}
try {
await updateCustomInfo(query.title, query.customFaviconUrl, query.customAuthor, query.feedId, query.userId);
await updateCustomInfo(query);
return c.json({
code: 200,
message: '更新成功!'
Expand Down Expand Up @@ -139,4 +151,4 @@ app.put('/update-password', async (c) => {
}
})

export default app
export default app
5 changes: 4 additions & 1 deletion instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export async function register() {
{ config_key: 'custom_author', config_value: '', detail: '网站归属者名称' },
{ config_key: 'rss_feed_id', config_value: '', detail: 'Follow feedId' },
{ config_key: 'rss_user_id', config_value: '', detail: 'Follow userId' },
{ config_key: 'preview_max_width_limit', config_value: '0', detail: '预览图最大宽度限制' },
{ config_key: 'preview_max_width_limit_switch', config_value: '0', detail: '预览图最大宽度限制开关' },
{ config_key: 'preview_quality', config_value: '0.2', detail: '预览图压缩质量' },
],
skipDuplicates: true,
})
Expand All @@ -60,4 +63,4 @@ export async function register() {
} catch (e) {
console.error('初始化失败,请您先尝试排查问题,如无法解决请携带日志去提交反馈:https://github.com/besscroft/PicImpact/issues', e)
}
}
}
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
62 changes: 31 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picimpact",
"version": "2.0.5",
"version": "2.0.6",
"private": true,
"author": "Bess Croft <[email protected]>",
"packageManager": "[email protected]",
Expand All @@ -20,11 +20,11 @@
},
"dependencies": {
"@ant-design/nextjs-registry": "^1.0.1",
"@auth/prisma-adapter": "^2.7.2",
"@aws-sdk/client-s3": "^3.679.0",
"@hono/node-server": "^1.13.3",
"@auth/prisma-adapter": "^2.7.4",
"@aws-sdk/client-s3": "^3.705.0",
"@hono/node-server": "^1.13.7",
"@hookform/resolvers": "^3.9.1",
"@prisma/client": "^5.21.1",
"@prisma/client": "^5.22.0",
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-checkbox": "^1.1.2",
Expand All @@ -41,56 +41,56 @@
"@radix-ui/react-switch": "^1.1.1",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.3",
"antd": "^5.21.6",
"class-variance-authority": "^0.7.0",
"antd": "^5.22.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "1.0.0",
"cmdk": "1.0.4",
"compressorjs": "^1.2.1",
"crypto-js": "^4.2.0",
"cuid": "^3.0.0",
"dayjs": "^1.11.13",
"emblor": "^1.4.6",
"emblor": "^1.4.7",
"exifreader": "^4.25.0",
"framer-motion": "^11.11.17",
"framer-motion": "^11.13.1",
"heic2any": "^0.0.4",
"hono": "^4.6.11",
"input-otp": "^1.2.4",
"hono": "^4.6.13",
"input-otp": "^1.4.1",
"livephotoskit": "^1.5.6",
"lucide-react": "^0.454.0",
"next": "^15.0.4-canary.5",
"lucide-react": "^0.468.0",
"next": "^15.0.4",
"next-auth": "^5.0.0-beta.25",
"next-nprogress-bar": "^2.3.14",
"next-nprogress-bar": "^2.3.15",
"next-qrcode": "^2.5.1",
"next-themes": "^0.3.0",
"otpauth": "^9.3.4",
"react": "19.0.0-rc-5c56b873-20241107",
"react-dom": "19.0.0-rc-5c56b873-20241107",
"react-hook-form": "^7.53.1",
"next-themes": "^0.4.4",
"otpauth": "^9.3.5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.0",
"react-photo-album": "^3.0.2",
"rss": "^1.2.2",
"server-only": "^0.0.1",
"sharp": "^0.33.5",
"sonner": "^1.5.0",
"sonner": "^1.7.1",
"swr": "^2.2.5",
"tailwind-merge": "^2.5.4",
"tailwind-merge": "^2.5.5",
"tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss-animate": "^1.0.7",
"vaul": "^1.1.0",
"vaul": "^1.1.1",
"zod": "^3.23.8",
"zustand": "^4.5.5"
},
"devDependencies": {
"@types/crypto-js": "^4.2.2",
"@types/node": "^20.17.1",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/node": "^20.17.9",
"@types/react": "^19.0.1",
"@types/react-dom": "^19.0.1",
"@types/rss": "^0.0.32",
"autoprefixer": "^10.4.20",
"eslint": "^8.57.1",
"eslint-config-next": "^15.0.3",
"postcss": "^8.4.47",
"prisma": "^5.21.1",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
"eslint-config-next": "^15.0.4",
"postcss": "^8.4.49",
"prisma": "^5.22.0",
"tailwindcss": "^3.4.16",
"typescript": "^5.7.2"
}
}
Loading

0 comments on commit 6cdac5f

Please sign in to comment.