Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/admin/settings/preferences/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Preferences() {
const [adminImagesPerPage, setAdminImagesPerPage] = useState('8')
const t = useTranslations()

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

async function updateInfo() {
const maxWidth = parseInt(previewImageMaxWidth)
Expand All @@ -57,7 +57,7 @@ export default function Preferences() {
}
try {
setLoading(true)
await fetch('/api/v1/settings/update-custom-info', {
await fetch('/api/v1/settings/custom-info', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion components/admin/list/list-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function ListProps(props : Readonly<ImageServerHandleProps>) {
(state) => state,
)
const { data: albums, isLoading: albumsLoading } = useSWR('/api/v1/albums/get', fetcher)
const { data: adminConfig } = useSWR('/api/v1/settings/get-admin-config', fetcher)
const { data: adminConfig } = useSWR('/api/v1/settings/admin-config', fetcher)
const t = useTranslations()

const dataProps: ImageListDataProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function OpenListEditSheet() {
async function submit() {
setLoading(true)
try {
await fetch('/api/v1/settings/update-open-list-info', {
await fetch('/api/v1/settings/open-list-info', {
headers: {
'Content-Type': 'application/json',
},
Expand Down
2 changes: 1 addition & 1 deletion components/admin/settings/storages/r2-edit-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function R2EditSheet() {
async function submit() {
setLoading(true)
try {
await fetch('/api/v1/settings/update-r2-info', {
await fetch('/api/v1/settings/r2-info', {
headers: {
'Content-Type': 'application/json',
},
Expand Down
2 changes: 1 addition & 1 deletion components/admin/settings/storages/s3-edit-sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function S3EditSheet() {
async function submit() {
setLoading(true)
try {
await fetch('/api/v1/settings/update-s3-info', {
await fetch('/api/v1/settings/s3-info', {
headers: {
'Content-Type': 'application/json',
},
Expand Down
20 changes: 10 additions & 10 deletions hono/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { updateOpenListConfig, updateCustomInfo, updateR2Config, updateS3Config

const app = new Hono()

app.get('/get-custom-info', async (c) => {
app.get('/custom-info', async (c) => {
try {
const data = await fetchConfigsByKeys([
'custom_title',
Expand All @@ -27,7 +27,7 @@ app.get('/get-custom-info', async (c) => {
'custom_index_origin_enable',
'admin_images_per_page'
])
return c.json(data)
return c.json({ code: 200, message: 'Success', data })
} catch (error) {
throw new HTTPException(500, { message: 'Failed to fetch custom info', cause: error })
}
Expand All @@ -44,7 +44,7 @@ app.get('/r2-info', async (c) => {
'r2_public_domain',
'r2_direct_download'
])
return c.json(data)
return c.json({ code: 200, message: 'Success', data })
} catch (error) {
throw new HTTPException(500, { message: 'Failed to fetch R2 info', cause: error })
}
Expand All @@ -64,24 +64,24 @@ app.get('/s3-info', async (c) => {
's3_cdn_url',
's3_direct_download'
])
return c.json(data)
return c.json({ code: 200, message: 'Success', data })
} catch (error) {
throw new HTTPException(500, { message: 'Failed to fetch S3 info', cause: error })
}
})

app.get('/get-admin-config', async (c) => {
app.get('/admin-config', async (c) => {
try {
const data = await fetchConfigsByKeys([
'admin_images_per_page'
])
return c.json(data)
return c.json({ code: 200, message: 'Success', data })
} catch (error) {
throw new HTTPException(500, { message: 'Failed to fetch admin config', cause: error })
}
})

app.put('/update-open-list-info', async (c) => {
app.put('/open-list-info', async (c) => {
try {
const query = await c.req.json()

Expand All @@ -95,7 +95,7 @@ app.put('/update-open-list-info', async (c) => {
}
})

app.put('/update-r2-info', async (c) => {
app.put('/r2-info', async (c) => {
try {
const query = await c.req.json()

Expand All @@ -114,7 +114,7 @@ app.put('/update-r2-info', async (c) => {
}
})

app.put('/update-s3-info', async (c) => {
app.put('/s3-info', async (c) => {
try {
const query = await c.req.json()

Expand All @@ -136,7 +136,7 @@ app.put('/update-s3-info', async (c) => {
}
})

app.put('/update-custom-info', async (c) => {
app.put('/custom-info', async (c) => {
const query = await c.req.json() satisfies {
title: string
customFaviconUrl: string
Expand Down
4 changes: 2 additions & 2 deletions hono/storage/open-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ app.get('/info', async (c) => {
'open_list_url',
'open_list_token'
])
return c.json(data)
return c.json({ code: 200, message: 'Success', data })
} catch (e) {
throw new HTTPException(500, { message: 'Failed to fetch open list info', cause: e })
}
Expand All @@ -38,7 +38,7 @@ app.get('/storages', async (c) => {
'Authorization': openListToken.toString(),
},
}).then(res => res.json())
return c.json(data)
return c.json({ code: 200, message: 'Success', data })
} catch (e) {
if (e instanceof HTTPException) throw e
throw new HTTPException(500, { message: 'Failed to fetch storages', cause: e })
Expand Down
8 changes: 4 additions & 4 deletions hooks/use-upload-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function useUploadConfig(): UploadConfig {
const t = useTranslations()

const { data: albums, isLoading: isAlbumsLoading } = useSWR('/api/v1/albums/get', fetcher)
const { data: configs } = useSWR<{ config_key: string, config_value: string }[]>('/api/v1/settings/get-custom-info', fetcher)
const { data: configs } = useSWR<{ config_key: string, config_value: string }[]>('/api/v1/settings/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')
Expand All @@ -70,11 +70,11 @@ export function useUploadConfig(): UploadConfig {
}
try {
toast.info(t('Tips.gettingOpenListDirs'))
const res = await fetch('/api/v1/storage/open-list/storages', {
const envelope = await fetch('/api/v1/storage/open-list/storages', {
method: 'GET',
}).then(res => res.json())
if (res?.code === 200) {
setOpenListStorage(res.data?.content)
if (envelope?.code === 200) {
setOpenListStorage(envelope.data?.data?.content)
setStorageSelect(true)
} else {
toast.error(t('Tips.getFailed'))
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export const fetcher = (url: string) => fetch(url).then((res) => res.json())
export const fetcher = async (url: string) => {
const res = await fetch(url).then((r) => r.json())
if (res && typeof res === 'object' && 'code' in res && 'data' in res) {
return res.data
}
return res
}
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/dev/types/routes.d.ts";
import "./.next/types/routes.d.ts";

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Loading