mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-16 23:41:11 +02:00
make update raw resource port functional
This commit is contained in:
parent
a7c99b016c
commit
65a537a670
2 changed files with 55 additions and 22 deletions
|
@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from "express";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db } from "@server/db";
|
import { db } from "@server/db";
|
||||||
import { orgs, resources, sites } from "@server/db/schema";
|
import { orgs, resources, sites } from "@server/db/schema";
|
||||||
import { eq, or } from "drizzle-orm";
|
import { eq, or, and } from "drizzle-orm";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import createHttpError from "http-errors";
|
import createHttpError from "http-errors";
|
||||||
|
@ -63,13 +63,16 @@ export async function updateResource(
|
||||||
const { resourceId } = parsedParams.data;
|
const { resourceId } = parsedParams.data;
|
||||||
const updateData = parsedBody.data;
|
const updateData = parsedBody.data;
|
||||||
|
|
||||||
const resource = await db
|
const [result] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(resources)
|
.from(resources)
|
||||||
.where(eq(resources.resourceId, resourceId))
|
.where(eq(resources.resourceId, resourceId))
|
||||||
.leftJoin(orgs, eq(resources.orgId, orgs.orgId));
|
.leftJoin(orgs, eq(resources.orgId, orgs.orgId));
|
||||||
|
|
||||||
if (resource.length === 0) {
|
const resource = result.resources;
|
||||||
|
const org = result.orgs;
|
||||||
|
|
||||||
|
if (!resource || !org) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.NOT_FOUND,
|
HttpCode.NOT_FOUND,
|
||||||
|
@ -78,7 +81,41 @@ export async function updateResource(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resource[0].orgs?.domain) {
|
if (updateData.proxyPort) {
|
||||||
|
const proxyPort = updateData.proxyPort;
|
||||||
|
const existingResource = await db
|
||||||
|
.select()
|
||||||
|
.from(resources)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(resources.protocol, resource.protocol),
|
||||||
|
eq(resources.proxyPort, proxyPort!)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (proxyPort === 443 || proxyPort === 80) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"Port 80 and 443 are reserved for https resources"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
existingResource.length > 0 &&
|
||||||
|
existingResource[0].resourceId !== resourceId
|
||||||
|
) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.CONFLICT,
|
||||||
|
"Resource with that protocol and port already exists"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!org?.domain) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.BAD_REQUEST,
|
HttpCode.BAD_REQUEST,
|
||||||
|
@ -88,7 +125,7 @@ export async function updateResource(
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullDomain = updateData.subdomain
|
const fullDomain = updateData.subdomain
|
||||||
? `${updateData.subdomain}.${resource[0].orgs.domain}`
|
? `${updateData.subdomain}.${org.domain}`
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const updatePayload = {
|
const updatePayload = {
|
||||||
|
@ -111,10 +148,6 @@ export async function updateResource(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resource[0].resources.ssl !== updatedResource[0].ssl) {
|
|
||||||
// invalidate all sessions?
|
|
||||||
}
|
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
data: updatedResource[0],
|
data: updatedResource[0],
|
||||||
success: true,
|
success: true,
|
||||||
|
|
|
@ -145,14 +145,11 @@ export default function GeneralForm() {
|
||||||
setSaveLoading(true);
|
setSaveLoading(true);
|
||||||
|
|
||||||
const res = await api
|
const res = await api
|
||||||
.post<AxiosResponse<GetResourceAuthInfoResponse>>(
|
.post(`resource/${resource?.resourceId}`, {
|
||||||
`resource/${resource?.resourceId}`,
|
name: data.name,
|
||||||
{
|
subdomain: data.subdomain,
|
||||||
name: data.name,
|
proxyPort: data.proxyPort
|
||||||
subdomain: data.subdomain
|
})
|
||||||
// siteId: data.siteId,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
|
@ -170,7 +167,11 @@ export default function GeneralForm() {
|
||||||
description: "The resource has been updated successfully"
|
description: "The resource has been updated successfully"
|
||||||
});
|
});
|
||||||
|
|
||||||
updateResource({ name: data.name, subdomain: data.subdomain });
|
updateResource({
|
||||||
|
name: data.name,
|
||||||
|
subdomain: data.subdomain,
|
||||||
|
proxyPort: data.proxyPort
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setSaveLoading(false);
|
setSaveLoading(false);
|
||||||
}
|
}
|
||||||
|
@ -395,9 +396,7 @@ export default function GeneralForm() {
|
||||||
{sites.map(
|
{sites.map(
|
||||||
(site) => (
|
(site) => (
|
||||||
<CommandItem
|
<CommandItem
|
||||||
value={
|
value={`${site.name}:${site.siteId}`}
|
||||||
`${site.name}:${site.siteId}`
|
|
||||||
}
|
|
||||||
key={
|
key={
|
||||||
site.siteId
|
site.siteId
|
||||||
}
|
}
|
||||||
|
@ -431,7 +430,8 @@ export default function GeneralForm() {
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
<FormDescription>
|
<FormDescription>
|
||||||
Select the new site to transfer this resource to.
|
Select the new site to transfer
|
||||||
|
this resource to.
|
||||||
</FormDescription>
|
</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue