mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
shields update
This commit is contained in:
21
dashboard/server/api/shields/domains/add.post.ts
Normal file
21
dashboard/server/api/shields/domains/add.post.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { DomainWhitelistModel } from "~/shared/schema/shields/DomainWhitelistSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestData(event, [], ['OWNER']);
|
||||
if (!data) return;
|
||||
|
||||
const body = await readBody(event);
|
||||
const { domain } = body;
|
||||
|
||||
if (domain.trim().length == 0) return setResponseStatus(event, 400, 'Domain is required');
|
||||
|
||||
const whitelist = await DomainWhitelistModel.updateOne({
|
||||
project_id: data.project_id
|
||||
},
|
||||
{ $push: { domains: domain } },
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
return { ok: true };
|
||||
});
|
||||
18
dashboard/server/api/shields/domains/delete.delete.ts
Normal file
18
dashboard/server/api/shields/domains/delete.delete.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { DomainWhitelistModel } from "~/shared/schema/shields/DomainWhitelistSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestData(event, [], ['OWNER']);
|
||||
if (!data) return;
|
||||
|
||||
const body = await readBody(event);
|
||||
const { domain } = body;
|
||||
|
||||
const removal = await DomainWhitelistModel.updateOne({
|
||||
project_id: data.project_id
|
||||
},
|
||||
{ $pull: { domains: domain } },
|
||||
);
|
||||
|
||||
return { ok: removal.modifiedCount == 1 };
|
||||
});
|
||||
10
dashboard/server/api/shields/domains/list.ts
Normal file
10
dashboard/server/api/shields/domains/list.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { DomainWhitelistModel } from "~/shared/schema/shields/DomainWhitelistSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const data = await getRequestData(event, [], ['OWNER']);
|
||||
if (!data) return;
|
||||
const whitelist = await DomainWhitelistModel.findOne({ project_id: data.project_id });
|
||||
if (!whitelist) return [];
|
||||
const domains = whitelist.domains;
|
||||
return domains;
|
||||
});
|
||||
11
dashboard/server/api/shields/ip/add.post.ts
Normal file
11
dashboard/server/api/shields/ip/add.post.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { AddressBlacklistModel } from "~/shared/schema/shields/AddressBlacklistSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const data = await getRequestData(event, [], ['OWNER']);
|
||||
if (!data) return;
|
||||
const body = await readBody(event);
|
||||
const { address, description } = body;
|
||||
if (address.trim().length == 0) return setResponseStatus(event, 400, 'Address is required');
|
||||
const result = await AddressBlacklistModel.updateOne({ project_id: data.project_id, address }, { description }, { upsert: true });
|
||||
return { ok: result.acknowledged };
|
||||
});
|
||||
14
dashboard/server/api/shields/ip/delete.delete.ts
Normal file
14
dashboard/server/api/shields/ip/delete.delete.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { AddressBlacklistModel } from "~/shared/schema/shields/AddressBlacklistSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestData(event, [], ['OWNER']);
|
||||
if (!data) return;
|
||||
|
||||
const body = await readBody(event);
|
||||
const { address } = body;
|
||||
|
||||
const removal = await AddressBlacklistModel.deleteOne({ project_id: data.project_id, address });
|
||||
|
||||
return { ok: removal.deletedCount == 1 };
|
||||
});
|
||||
8
dashboard/server/api/shields/ip/list.ts
Normal file
8
dashboard/server/api/shields/ip/list.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { AddressBlacklistModel } from "~/shared/schema/shields/AddressBlacklistSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const data = await getRequestData(event, [], ['OWNER']);
|
||||
if (!data) return;
|
||||
const blacklist = await AddressBlacklistModel.find({ project_id: data.project_id });
|
||||
return blacklist.map(e => e.toJSON());
|
||||
});
|
||||
Reference in New Issue
Block a user