mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix status page domain service.
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import PostgresDatabase from '../Infrastructure/PostgresDatabase';
|
||||
import Model from 'Model/Models/StatusPageDomain';
|
||||
import DatabaseService, { OnCreate } from './DatabaseService';
|
||||
import DatabaseService, { OnCreate, OnDelete } from './DatabaseService';
|
||||
import CreateBy from '../Types/Database/CreateBy';
|
||||
import DomainService from './DomainService';
|
||||
import Domain from 'Model/Models/Domain';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import StatusPageCertificateService from './StatusPageCertificateService';
|
||||
import DeleteBy from '../Types/Database/DeleteBy';
|
||||
import LIMIT_MAX from 'Common/Types/Database/LimitMax';
|
||||
import ObjectID from 'Common/Types/ObjectID';
|
||||
|
||||
export class Service extends DatabaseService<Model> {
|
||||
public constructor(postgresDatabase?: PostgresDatabase) {
|
||||
@@ -21,12 +26,16 @@ export class Service extends DatabaseService<Model> {
|
||||
'',
|
||||
},
|
||||
populate: {},
|
||||
select: { domain: true },
|
||||
select: { domain: true, isVerified: true },
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!domain?.isVerified) {
|
||||
throw new BadDataException("This domain is not verified. Please verify it bu going to Settings > Domains");
|
||||
}
|
||||
|
||||
if (domain) {
|
||||
createBy.data.fullDomain =
|
||||
createBy.data.subdomain + '.' + domain.domain;
|
||||
@@ -34,5 +43,38 @@ export class Service extends DatabaseService<Model> {
|
||||
|
||||
return { createBy, carryForward: null };
|
||||
}
|
||||
|
||||
protected override async onCreateSuccess(_onCreate: OnCreate<Model>, createdItem: Model): Promise<Model> {
|
||||
// Add this domain to greenlock for certificate generation.
|
||||
await StatusPageCertificateService.add(createdItem.fullDomain as string);
|
||||
return createdItem;
|
||||
}
|
||||
|
||||
protected override async onBeforeDelete(deleteBy: DeleteBy<Model>): Promise<OnDelete<Model>> {
|
||||
const domains: Array<Model> = await this.findBy({
|
||||
query: deleteBy.query,
|
||||
populate: {},
|
||||
skip: 0,
|
||||
limit: LIMIT_MAX,
|
||||
select: { fullDomain: true },
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
return { deleteBy, carryForward: domains };
|
||||
}
|
||||
|
||||
protected override async onDeleteSuccess(onDelete: OnDelete<Model>, _itemIdsBeforeDelete: ObjectID[]): Promise<OnDelete<Model>> {
|
||||
for (const domain of onDelete.carryForward) {
|
||||
await StatusPageCertificateService.remove(domain.fullDomain as string);
|
||||
}
|
||||
|
||||
return onDelete;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
export default new Service();
|
||||
|
||||
@@ -5,7 +5,7 @@ import StatusPageDomain from 'Model/Models/StatusPageDomain';
|
||||
import StatusPageDomainService from 'CommonServer/Services/StatusPageDomainService';
|
||||
// @ts-ignore
|
||||
import Greenlock from 'greenlock';
|
||||
import HTTPChallenge from '../../Utils/Greenlock/HTTPChallenge';
|
||||
import HTTPChallenge from '../../Utils/Greenlock/HttpChallenge';
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
import Store from '../../Utils/Greenlock/Store';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
|
||||
Reference in New Issue
Block a user