fix(core): update
This commit is contained in:
@ -2,7 +2,6 @@ import plugins = require('./cloudflare.plugins');
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
// interfaces
|
||||
import { TDnsRecord } from '@tsclass/tsclass';
|
||||
import { WorkerManager } from './cloudflare.classes.workermanager';
|
||||
import { ZoneManager } from './cloudflare.classes.zonemanager';
|
||||
|
||||
@ -61,7 +60,7 @@ export class CloudflareAccount {
|
||||
*/
|
||||
public async getRecord(
|
||||
domainNameArg: string,
|
||||
typeArg: TDnsRecord
|
||||
typeArg: plugins.tsclass.network.TDnsRecord
|
||||
): Promise<interfaces.ICflareRecord> {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const recordArrayArg = await this.listRecords(domain.zoneName);
|
||||
@ -73,7 +72,7 @@ export class CloudflareAccount {
|
||||
|
||||
public async createRecord(
|
||||
domainNameArg: string,
|
||||
typeArg: TDnsRecord,
|
||||
typeArg: plugins.tsclass.network.TDnsRecord,
|
||||
contentArg: string
|
||||
): Promise<any> {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
@ -96,7 +95,10 @@ export class CloudflareAccount {
|
||||
* @param domainNameArg
|
||||
* @param typeArg
|
||||
*/
|
||||
public async removeRecord(domainNameArg: string, typeArg: TDnsRecord): Promise<any> {
|
||||
public async removeRecord(
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecord
|
||||
): Promise<any> {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const cflareRecord = await this.getRecord(domain.fullName, typeArg);
|
||||
if (cflareRecord) {
|
||||
@ -221,4 +223,6 @@ export class CloudflareAccount {
|
||||
private authCheck() {
|
||||
return this.authEmail && this.authKey; // check if auth is available
|
||||
}
|
||||
|
||||
// acme convenience functions
|
||||
}
|
||||
|
@ -8,7 +8,10 @@ export interface IWorkerRoute extends interfaces.ICflareWorkerRoute {
|
||||
|
||||
export class CloudflareWorker {
|
||||
// STATIC
|
||||
public static async fromApiObject(workerManager: WorkerManager, apiObject): Promise<CloudflareWorker> {
|
||||
public static async fromApiObject(
|
||||
workerManager: WorkerManager,
|
||||
apiObject
|
||||
): Promise<CloudflareWorker> {
|
||||
const newWorker = new CloudflareWorker(workerManager);
|
||||
Object.assign(newWorker, apiObject.result);
|
||||
await newWorker.getRoutes();
|
||||
@ -17,7 +20,7 @@ export class CloudflareWorker {
|
||||
|
||||
// INSTANCE
|
||||
private workerManager: WorkerManager;
|
||||
|
||||
|
||||
public script: string;
|
||||
public id: string;
|
||||
public etag: string;
|
||||
@ -38,19 +41,21 @@ export class CloudflareWorker {
|
||||
const zones = await this.workerManager.cfAccount.listZones();
|
||||
for (const zone of zones) {
|
||||
const requestRoute = `/zones/${zone.id}/workers/routes`;
|
||||
const response: {result: interfaces.ICflareWorkerRoute[]} = await this.workerManager.cfAccount.request('GET', requestRoute);
|
||||
const response: {
|
||||
result: interfaces.ICflareWorkerRoute[];
|
||||
} = await this.workerManager.cfAccount.request('GET', requestRoute);
|
||||
for (const route of response.result) {
|
||||
console.log('hey');
|
||||
console.log(route);
|
||||
console.log(this.id);
|
||||
if (route.script === this.id) {
|
||||
this.routes.push({...route, zoneName: zone.name});
|
||||
this.routes.push({ ...route, zoneName: zone.name });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async setRoutes(routeArray: Array<{zoneName: string, pattern: string}>) {
|
||||
public async setRoutes(routeArray: Array<{ zoneName: string; pattern: string }>) {
|
||||
for (const newRoute of routeArray) {
|
||||
// lets determine wether a route is new, needs an update or already up to date.
|
||||
let routeStatus: 'new' | 'needsUpdate' | 'alreadyUpToDate' = 'new';
|
||||
|
@ -26,6 +26,11 @@ export class WorkerManager {
|
||||
const accountIdentifier = await this.cfAccount.getAccountIdentifier();
|
||||
const route = `/accounts/${accountIdentifier}/workers/scripts`;
|
||||
const response = await this.cfAccount.request('GET', route);
|
||||
console.log(response);
|
||||
const results = response.result;
|
||||
const workers: CloudflareWorker[] = [];
|
||||
for (const apiObject of results) {
|
||||
workers.push(await CloudflareWorker.fromApiObject(this, apiObject));
|
||||
}
|
||||
return workers;
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,4 @@ import * as interfaces from './interfaces';
|
||||
|
||||
export class CloudflareZone {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
@ -12,4 +12,4 @@ export interface ICflareRecord {
|
||||
created_on: string;
|
||||
modified_on: string;
|
||||
data: any;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user