perf: image and auth

This commit is contained in:
archer
2023-04-28 14:01:27 +08:00
parent 75073a64fb
commit ca8e940c9b
8 changed files with 24 additions and 22 deletions

View File

@@ -21,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
data: collections
.map((item: any) => ({
_id: item.modelId?._id,
avatar: item.modelId?.avatar || '',
avatar: item.modelId?.avatar || '/icon/logo.png',
name: item.modelId?.name || '',
userId: item.modelId?.userId || '',
share: item.modelId?.share || {},
@@ -31,8 +31,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
});
} catch (err) {
jsonRes(res, {
code: 500,
error: err
data: []
});
}
}

View File

@@ -8,9 +8,6 @@ import type { ShareModelItem } from '@/types/model';
/* 获取模型列表 */
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
// 凭证校验
await authToken(req.headers.authorization);
const {
searchText = '',
pageNum = 1,
@@ -28,7 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
]
};
// 根据分享的模型
// 获取被分享的模型
const [models, total] = await Promise.all([
Model.find(where, '_id avatar name userId share')
.sort({
@@ -45,7 +42,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
pageSize,
data: models.map((item) => ({
_id: item._id,
avatar: item.avatar,
avatar: item.avatar || '/icon/logo.png',
name: item.name,
userId: item.userId,
share: item.share,