🎨 增加 Go 后端
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { defineEventHandler } from 'h3';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
interface AddSuffixBody {
|
||||
suffix: string;
|
||||
server: string;
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body: AddSuffixBody = await readBody(event);
|
||||
const filePath = path.join('server/whois/json', 'whois-servers.json');
|
||||
|
||||
const fileContent = fs.readFileSync(filePath, { encoding: 'utf8' });
|
||||
const data: Record<string, string> = JSON.parse(fileContent);
|
||||
|
||||
// 添加或更新域名后缀
|
||||
data[body.suffix] = body.server;
|
||||
|
||||
// 写入更新
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), { encoding: 'utf8' });
|
||||
|
||||
return { message: 'ok' };
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { defineEventHandler } from 'h3';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
interface RemoveSuffixBody {
|
||||
suffix: string;
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body: RemoveSuffixBody = await readBody(event);
|
||||
const filePath = path.join('server/whois/json', 'whois-servers.json');
|
||||
|
||||
const fileContent = fs.readFileSync(filePath, { encoding: 'utf8' });
|
||||
const data: Record<string, string> = JSON.parse(fileContent);
|
||||
|
||||
// 删除域名后缀
|
||||
delete data[body.suffix];
|
||||
|
||||
// 写入更新
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), { encoding: 'utf8' });
|
||||
|
||||
return { message: 'ok' };
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
const domain = body.domain;
|
||||
const serverName = body.serverName;
|
||||
if (serverName == '') {
|
||||
return ""
|
||||
}
|
||||
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const baseUrl = runtimeConfig.public.baseUrl
|
||||
switch (serverName) {
|
||||
case "nuxt": {
|
||||
return ""
|
||||
}
|
||||
default:
|
||||
return await $fetch(`${baseUrl}/server/getDns`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
name: serverName,
|
||||
domain: domain,
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
// 定义 DNS 服务器配置
|
||||
const doMainServers: any = {
|
||||
whocx: 'https://who.cx/api/price',
|
||||
};
|
||||
|
||||
interface DomainInfoResponse {
|
||||
code: number;
|
||||
currency: string;
|
||||
currency_symbol: string;
|
||||
domain: string;
|
||||
new: string;
|
||||
renew: string;
|
||||
premium: boolean;
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
const domain = body.domain;
|
||||
const flag = body.flag;
|
||||
const domainServerKey = body.domainServer;
|
||||
|
||||
|
||||
//判断是否开启DNS
|
||||
console.log(flag)
|
||||
if (!flag) {
|
||||
return {
|
||||
status: 200,
|
||||
data: {
|
||||
status: 'success',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (domainServerKey) {
|
||||
case 'whocx':
|
||||
const res: any = await $fetch(doMainServers.whocx, {
|
||||
method: "GET",
|
||||
params: {
|
||||
domain: domain,
|
||||
}
|
||||
});
|
||||
return {
|
||||
code: 200,
|
||||
currency: res.currency,
|
||||
currency_symbol: res.currency_symbol,
|
||||
domain: res.domain,
|
||||
new: res.new,
|
||||
renew: res.renew,
|
||||
premium: false,
|
||||
} as DomainInfoResponse
|
||||
default:
|
||||
return null
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import {whois} from "~/server/whois/whois";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
const serverName = body.serverName;
|
||||
const domain = body.domain
|
||||
if (serverName == '') {
|
||||
return ""
|
||||
}
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const baseUrl = runtimeConfig.public.baseUrl
|
||||
switch (serverName) {
|
||||
case "nuxt": {
|
||||
return await whois(domain)
|
||||
}
|
||||
default:
|
||||
return await $fetch(`${baseUrl}/server/getWhois`, {
|
||||
method: 'POST',
|
||||
body: {
|
||||
name: serverName,
|
||||
domain: domain,
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user