mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-24 06:25:48 +00:00
feat: add HandleInstanceResolve API handler
This commit is contained in:
parent
564f65047b
commit
9908f770e6
@ -22,6 +22,7 @@ __export(lib_exports, {
|
|||||||
HandleInstanceBeforeUpdate: () => HandleInstanceBeforeUpdate,
|
HandleInstanceBeforeUpdate: () => HandleInstanceBeforeUpdate,
|
||||||
HandleInstanceCreate: () => HandleInstanceCreate,
|
HandleInstanceCreate: () => HandleInstanceCreate,
|
||||||
HandleInstanceDelete: () => HandleInstanceDelete,
|
HandleInstanceDelete: () => HandleInstanceDelete,
|
||||||
|
HandleInstanceResolve: () => HandleInstanceResolve,
|
||||||
HandleInstanceUpdate: () => HandleInstanceUpdate,
|
HandleInstanceUpdate: () => HandleInstanceUpdate,
|
||||||
HandleInstanceVersionValidation: () => HandleInstanceVersionValidation,
|
HandleInstanceVersionValidation: () => HandleInstanceVersionValidation,
|
||||||
HandleInstancesResetIdle: () => HandleInstancesResetIdle,
|
HandleInstancesResetIdle: () => HandleInstancesResetIdle,
|
||||||
@ -146,6 +147,54 @@ var HandleInstanceDelete = (c) => {
|
|||||||
return c.json(200, { status: "ok" });
|
return c.json(200, { status: "ok" });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// src/lib/handlers/instance/api/HandleInstanceResolve.ts
|
||||||
|
var HandleInstanceResolve = (c) => {
|
||||||
|
const dao = $app.dao();
|
||||||
|
const log = mkLog(`GET:instance/resolve`);
|
||||||
|
log(`***TOP OF GET`);
|
||||||
|
const host = c.queryParam("host");
|
||||||
|
if (!host) {
|
||||||
|
throw new BadRequestError(`Host is required when resolving an instance.`);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const record = $app.dao().findFirstRecordByData("instances", "cname", host);
|
||||||
|
if (record) {
|
||||||
|
return c.json(200, { instance: record });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(`${host} is not a cname`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const [subdomain, ...junk] = host.split(".");
|
||||||
|
if (!subdomain) {
|
||||||
|
throw new BadRequestError(
|
||||||
|
`Subdomain is required when resolving an instance.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const record = $app.dao().findRecordById("instances", subdomain);
|
||||||
|
if (record) {
|
||||||
|
return c.json(200, { instance: record });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(`${subdomain} is not an instance ID`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const record = $app.dao().findFirstRecordByData("instances", `subdomain`, subdomain);
|
||||||
|
if (record) {
|
||||||
|
return c.json(200, { instance: record });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(`${subdomain} is not a subdomain`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new BadRequestError(`Instance not found.`);
|
||||||
|
};
|
||||||
|
|
||||||
// ../../../../node_modules/.pnpm/@s-libs+micro-dash@18.0.0/node_modules/@s-libs/micro-dash/fesm2022/micro-dash.mjs
|
// ../../../../node_modules/.pnpm/@s-libs+micro-dash@18.0.0/node_modules/@s-libs/micro-dash/fesm2022/micro-dash.mjs
|
||||||
function keysOfNonArray(object) {
|
function keysOfNonArray(object) {
|
||||||
return object ? Object.getOwnPropertyNames(object) : [];
|
return object ? Object.getOwnPropertyNames(object) : [];
|
||||||
@ -3133,6 +3182,7 @@ var HandleVersionsRequest = (c) => {
|
|||||||
HandleInstanceBeforeUpdate,
|
HandleInstanceBeforeUpdate,
|
||||||
HandleInstanceCreate,
|
HandleInstanceCreate,
|
||||||
HandleInstanceDelete,
|
HandleInstanceDelete,
|
||||||
|
HandleInstanceResolve,
|
||||||
HandleInstanceUpdate,
|
HandleInstanceUpdate,
|
||||||
HandleInstanceVersionValidation,
|
HandleInstanceVersionValidation,
|
||||||
HandleInstancesResetIdle,
|
HandleInstancesResetIdle,
|
||||||
|
|||||||
@ -23,6 +23,14 @@ routerAdd(
|
|||||||
},
|
},
|
||||||
$apis.requireRecordAuth()
|
$apis.requireRecordAuth()
|
||||||
);
|
);
|
||||||
|
routerAdd(
|
||||||
|
"GET",
|
||||||
|
"/api/instance/resolve",
|
||||||
|
(c) => {
|
||||||
|
return require(`${__hooks}/mothership`).HandleInstanceResolve(c);
|
||||||
|
},
|
||||||
|
$apis.requireAdminAuth()
|
||||||
|
);
|
||||||
onModelBeforeCreate((e) => {
|
onModelBeforeCreate((e) => {
|
||||||
return require(`${__hooks}/mothership`).HandleInstanceVersionValidation(e);
|
return require(`${__hooks}/mothership`).HandleInstanceVersionValidation(e);
|
||||||
}, "instances");
|
}, "instances");
|
||||||
|
|||||||
@ -0,0 +1,61 @@
|
|||||||
|
import { mkLog } from '$util/Logger'
|
||||||
|
|
||||||
|
export const HandleInstanceResolve = (c: echo.Context) => {
|
||||||
|
const dao = $app.dao()
|
||||||
|
|
||||||
|
const log = mkLog(`GET:instance/resolve`)
|
||||||
|
|
||||||
|
log(`***TOP OF GET`)
|
||||||
|
const host = c.queryParam('host')
|
||||||
|
|
||||||
|
if (!host) {
|
||||||
|
throw new BadRequestError(`Host is required when resolving an instance.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const record = $app
|
||||||
|
.dao()
|
||||||
|
.findFirstRecordByData('instances', 'cname', host)
|
||||||
|
if (record) {
|
||||||
|
return c.json(200, { instance: record })
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(`${host} is not a cname`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [subdomain, ...junk] = host.split('.')
|
||||||
|
|
||||||
|
if (!subdomain) {
|
||||||
|
throw new BadRequestError(
|
||||||
|
`Subdomain is required when resolving an instance.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const record = $app.dao().findRecordById('instances', subdomain)
|
||||||
|
if (record) {
|
||||||
|
return c.json(200, { instance: record })
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(`${subdomain} is not an instance ID`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const record = $app
|
||||||
|
.dao()
|
||||||
|
.findFirstRecordByData('instances', `subdomain`, subdomain)
|
||||||
|
if (record) {
|
||||||
|
return c.json(200, { instance: record })
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(`${subdomain} is not a subdomain`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BadRequestError(`Instance not found.`)
|
||||||
|
}
|
||||||
@ -22,6 +22,14 @@ routerAdd(
|
|||||||
},
|
},
|
||||||
$apis.requireRecordAuth(),
|
$apis.requireRecordAuth(),
|
||||||
)
|
)
|
||||||
|
routerAdd(
|
||||||
|
'GET',
|
||||||
|
'/api/instance/resolve',
|
||||||
|
(c) => {
|
||||||
|
return require(`${__hooks}/mothership`).HandleInstanceResolve(c)
|
||||||
|
},
|
||||||
|
$apis.requireAdminAuth(),
|
||||||
|
)
|
||||||
/** Validate instance version */
|
/** Validate instance version */
|
||||||
onModelBeforeCreate((e) => {
|
onModelBeforeCreate((e) => {
|
||||||
return require(`${__hooks}/mothership`).HandleInstanceVersionValidation(e)
|
return require(`${__hooks}/mothership`).HandleInstanceVersionValidation(e)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
export * from './api/HandleInstanceCreate'
|
export * from './api/HandleInstanceCreate'
|
||||||
export * from './api/HandleInstanceDelete'
|
export * from './api/HandleInstanceDelete'
|
||||||
|
export * from './api/HandleInstanceResolve'
|
||||||
export * from './api/HandleInstanceUpdate'
|
export * from './api/HandleInstanceUpdate'
|
||||||
export * from './bootstrap/HandleInstancesResetIdle'
|
export * from './bootstrap/HandleInstancesResetIdle'
|
||||||
export * from './bootstrap/HandleMigrateInstanceVersions'
|
export * from './bootstrap/HandleMigrateInstanceVersions'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user