fix(core): update

This commit is contained in:
Philipp Kunz 2019-07-19 12:39:39 +02:00
parent d3a68b4fef
commit 82701c19e7
3 changed files with 7 additions and 6 deletions

View File

@ -6,10 +6,10 @@ export interface IWorkerRoute extends interfaces.ICflareWorkerRoute {
zoneName: string; zoneName: string;
} }
export class Worker { export class CloudflareWorker {
// STATIC // STATIC
public static async fromApiObject(workerManager: WorkerManager, apiObject): Promise<Worker> { public static async fromApiObject(workerManager: WorkerManager, apiObject): Promise<CloudflareWorker> {
const newWorker = new Worker(workerManager); const newWorker = new CloudflareWorker(workerManager);
Object.assign(newWorker, apiObject.result); Object.assign(newWorker, apiObject.result);
await newWorker.getRoutes(); await newWorker.getRoutes();
return newWorker; return newWorker;

View File

@ -1,6 +1,6 @@
import * as plugins from './cloudflare.plugins'; import * as plugins from './cloudflare.plugins';
import { CloudflareAccount } from './cloudflare.classes.account'; import { CloudflareAccount } from './cloudflare.classes.account';
import { Worker } from './cloudflare.classes.worker'; import { CloudflareWorker } from './cloudflare.classes.worker';
export class WorkerManager { export class WorkerManager {
public cfAccount: CloudflareAccount; public cfAccount: CloudflareAccount;
@ -9,14 +9,14 @@ export class WorkerManager {
this.cfAccount = cfAccountArg; this.cfAccount = cfAccountArg;
} }
public async createWorker(workerName: string, workerScript: string): Promise<Worker> { public async createWorker(workerName: string, workerScript: string): Promise<CloudflareWorker> {
const accountIdentifier = await this.cfAccount.getAccountIdentifier(); const accountIdentifier = await this.cfAccount.getAccountIdentifier();
const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`; const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`;
const responseBody = await this.cfAccount.request('PUT', route, workerScript, { const responseBody = await this.cfAccount.request('PUT', route, workerScript, {
'Content-Type': 'application/javascript', 'Content-Type': 'application/javascript',
'Content-Length': Buffer.byteLength(workerScript) 'Content-Length': Buffer.byteLength(workerScript)
}); });
return Worker.fromApiObject(this, responseBody); return CloudflareWorker.fromApiObject(this, responseBody);
} }
/** /**

View File

@ -1 +1,2 @@
export { CloudflareAccount } from './cloudflare.classes.account'; export { CloudflareAccount } from './cloudflare.classes.account';
export { CloudflareWorker } from './cloudflare.classes.worker';