feat: openapi crd

This commit is contained in:
archer
2023-04-07 23:15:30 +08:00
parent 22cc9c85be
commit f6c4b4c96d
5 changed files with 131 additions and 17 deletions

View File

@@ -17,16 +17,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await connectToDatabase();
const findResponse = await OpenApi.find({ userId });
const findResponse = await OpenApi.find({ userId }).sort({ _id: -1 });
// jus save four data
const apiKeys = findResponse.map<UserOpenApiKey>((item) => {
const key = item.apiKey;
return {
id: item._id,
apiKey: `${key.substring(0, 2)}******${key.substring(key.length - 2)}`
};
});
const apiKeys = findResponse.map<UserOpenApiKey>(
({ _id, apiKey, createTime, lastUsedTime }) => {
return {
id: _id,
apiKey: `${apiKey.substring(0, 2)}******${apiKey.substring(apiKey.length - 2)}`,
createTime,
lastUsedTime
};
}
);
jsonRes(res, {
data: apiKeys

View File

@@ -4,7 +4,7 @@ import { jsonRes } from '@/service/response';
import { connectToDatabase, OpenApi } from '@/service/mongo';
import { authToken } from '@/service/utils/tools';
import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890-', 20);
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890');
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {