fixup crash
This commit is contained in:
@@ -17,12 +17,18 @@ export async function POST(req: Request) {
|
||||
|
||||
const {
|
||||
CLOUDFLARE_ZONE_ID,
|
||||
CLOUDFLARE_ZONE_NAME,
|
||||
CLOUDFLARE_API_KEY,
|
||||
CLOUDFLARE_EMAIL,
|
||||
NEXT_PUBLIC_FREE_RECORD_QUOTA,
|
||||
} = env;
|
||||
|
||||
if (!CLOUDFLARE_ZONE_ID || !CLOUDFLARE_API_KEY || !CLOUDFLARE_EMAIL) {
|
||||
if (
|
||||
!CLOUDFLARE_ZONE_ID ||
|
||||
!CLOUDFLARE_ZONE_NAME ||
|
||||
!CLOUDFLARE_API_KEY ||
|
||||
!CLOUDFLARE_EMAIL
|
||||
) {
|
||||
return Response.json("API key、zone iD and email are required", {
|
||||
status: 400,
|
||||
statusText: "API key、zone iD and email are required",
|
||||
@@ -35,7 +41,6 @@ export async function POST(req: Request) {
|
||||
if (
|
||||
user.role !== "ADMIN" &&
|
||||
user_records_count >= Number(NEXT_PUBLIC_FREE_RECORD_QUOTA)
|
||||
// Number(NEXT_PUBLIC_FREE_RECORD_QUOTA) > 0 &&
|
||||
) {
|
||||
return Response.json("Your records have reached the free limit.", {
|
||||
status: 409,
|
||||
@@ -53,6 +58,7 @@ export async function POST(req: Request) {
|
||||
const record_name = record.name.endsWith(".wr.do")
|
||||
? record.name
|
||||
: record.name + ".wr.do";
|
||||
|
||||
if (reservedDomains.includes(record_name)) {
|
||||
return Response.json("Domain name is reserved", {
|
||||
status: 403,
|
||||
@@ -78,15 +84,17 @@ export async function POST(req: Request) {
|
||||
CLOUDFLARE_EMAIL,
|
||||
record,
|
||||
);
|
||||
|
||||
if (!data.success || !data.result?.id) {
|
||||
return Response.json(data.errors, {
|
||||
console.log("[data]", data);
|
||||
return Response.json(data.messages, {
|
||||
status: 501,
|
||||
});
|
||||
} else {
|
||||
const res = await createUserRecord(user.id, {
|
||||
record_id: data.result.id,
|
||||
zone_id: data.result.zone_id,
|
||||
zone_name: data.result.zone_name,
|
||||
zone_id: CLOUDFLARE_ZONE_ID,
|
||||
zone_name: CLOUDFLARE_ZONE_NAME,
|
||||
name: data.result.name,
|
||||
type: data.result.type,
|
||||
content: data.result.content,
|
||||
@@ -99,6 +107,7 @@ export async function POST(req: Request) {
|
||||
modified_on: data.result.modified_on,
|
||||
active: 0,
|
||||
});
|
||||
|
||||
if (res.status !== "success") {
|
||||
return Response.json(res.status, {
|
||||
status: 502,
|
||||
@@ -108,7 +117,7 @@ export async function POST(req: Request) {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[错误]", error);
|
||||
return Response.json(error?.statusText || error, {
|
||||
return Response.json(error, {
|
||||
status: error?.status || 500,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,8 +14,18 @@ export async function POST(req: Request) {
|
||||
});
|
||||
}
|
||||
|
||||
const { CLOUDFLARE_ZONE_ID, CLOUDFLARE_API_KEY, CLOUDFLARE_EMAIL } = env;
|
||||
if (!CLOUDFLARE_ZONE_ID || !CLOUDFLARE_API_KEY || !CLOUDFLARE_EMAIL) {
|
||||
const {
|
||||
CLOUDFLARE_ZONE_ID,
|
||||
CLOUDFLARE_ZONE_NAME,
|
||||
CLOUDFLARE_API_KEY,
|
||||
CLOUDFLARE_EMAIL,
|
||||
} = env;
|
||||
if (
|
||||
!CLOUDFLARE_ZONE_ID ||
|
||||
!CLOUDFLARE_ZONE_NAME ||
|
||||
!CLOUDFLARE_API_KEY ||
|
||||
!CLOUDFLARE_EMAIL
|
||||
) {
|
||||
return Response.json("API key、zone iD and email are required", {
|
||||
status: 400,
|
||||
});
|
||||
@@ -42,8 +52,8 @@ export async function POST(req: Request) {
|
||||
} else {
|
||||
const res = await updateUserRecord(userId, {
|
||||
record_id: data.result.id,
|
||||
zone_id: data.result.zone_id,
|
||||
zone_name: data.result.zone_name,
|
||||
zone_id: CLOUDFLARE_ZONE_ID,
|
||||
zone_name: CLOUDFLARE_ZONE_NAME,
|
||||
name: data.result.name,
|
||||
type: data.result.type,
|
||||
content: data.result.content,
|
||||
|
||||
@@ -14,8 +14,18 @@ export async function POST(req: Request) {
|
||||
const user = checkUserStatus(await getCurrentUser());
|
||||
if (user instanceof Response) return user;
|
||||
|
||||
const { CLOUDFLARE_ZONE_ID, CLOUDFLARE_API_KEY, CLOUDFLARE_EMAIL } = env;
|
||||
if (!CLOUDFLARE_ZONE_ID || !CLOUDFLARE_API_KEY || !CLOUDFLARE_EMAIL) {
|
||||
const {
|
||||
CLOUDFLARE_ZONE_ID,
|
||||
CLOUDFLARE_ZONE_NAME,
|
||||
CLOUDFLARE_API_KEY,
|
||||
CLOUDFLARE_EMAIL,
|
||||
} = env;
|
||||
if (
|
||||
!CLOUDFLARE_ZONE_ID ||
|
||||
!CLOUDFLARE_ZONE_NAME ||
|
||||
!CLOUDFLARE_API_KEY ||
|
||||
!CLOUDFLARE_EMAIL
|
||||
) {
|
||||
return Response.json("API key andzone id are required.", { status: 401 });
|
||||
}
|
||||
|
||||
@@ -37,6 +47,8 @@ export async function POST(req: Request) {
|
||||
recordId,
|
||||
record,
|
||||
);
|
||||
console.log("updateDNSRecord", data);
|
||||
|
||||
if (!data.success || !data.result?.id) {
|
||||
return Response.json(data.errors, {
|
||||
status: 501,
|
||||
@@ -44,8 +56,8 @@ export async function POST(req: Request) {
|
||||
} else {
|
||||
const res = await updateUserRecord(user.id, {
|
||||
record_id: data.result.id,
|
||||
zone_id: data.result.zone_id,
|
||||
zone_name: data.result.zone_name,
|
||||
zone_id: CLOUDFLARE_ZONE_ID,
|
||||
zone_name: CLOUDFLARE_ZONE_NAME,
|
||||
name: data.result.name,
|
||||
type: data.result.type,
|
||||
content: data.result.content,
|
||||
@@ -65,7 +77,7 @@ export async function POST(req: Request) {
|
||||
return Response.json(res.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.log(error);
|
||||
return Response.json(error?.statusText || error, {
|
||||
status: error?.status || 500,
|
||||
});
|
||||
|
||||
@@ -116,7 +116,7 @@ export function RecordForm({
|
||||
});
|
||||
if (!response.ok || response.status !== 200) {
|
||||
toast.error("Update Failed", {
|
||||
description: await response.json(),
|
||||
description: response.statusText,
|
||||
});
|
||||
} else {
|
||||
const res = await response.json();
|
||||
@@ -142,7 +142,7 @@ export function RecordForm({
|
||||
});
|
||||
if (!response.ok || response.status !== 200) {
|
||||
toast.error("Delete Failed", {
|
||||
description: await response.json(),
|
||||
description: response.statusText,
|
||||
});
|
||||
} else {
|
||||
await response.json();
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ export const createDNSRecord = async (
|
||||
return data;
|
||||
} catch (error) {
|
||||
// console.error("Error creating DNS record.", error);
|
||||
throw error;
|
||||
return error;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ export async function createUserRecord(
|
||||
// revalidatePath('/dashboard/settings');
|
||||
return { status: "success", data: res };
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
// console.log(error);
|
||||
return { status: error };
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ export async function getUserRecordCount(
|
||||
role === "USER"
|
||||
? {
|
||||
userId: userId,
|
||||
active,
|
||||
// active,
|
||||
}
|
||||
: {},
|
||||
});
|
||||
@@ -140,11 +140,11 @@ export async function getUserRecordByTypeNameContent(
|
||||
) {
|
||||
return await prisma.userRecord.findMany({
|
||||
where: {
|
||||
userId,
|
||||
// userId,
|
||||
type,
|
||||
content,
|
||||
// content,
|
||||
name,
|
||||
active,
|
||||
// active,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -160,7 +160,7 @@ export async function deleteUserRecord(
|
||||
userId,
|
||||
record_id,
|
||||
zone_id,
|
||||
active,
|
||||
// active,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -190,7 +190,7 @@ export async function updateUserRecord(
|
||||
record_id,
|
||||
zone_id,
|
||||
zone_name,
|
||||
active: active,
|
||||
// active: active,
|
||||
},
|
||||
data: {
|
||||
type,
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user