Skip to content

Commit b60804b

Browse files
authored
Merge pull request #84 from KnorpelSenf/housekeeping
Housekeeping
2 parents e70f642 + 7ed3165 commit b60804b

7 files changed

Lines changed: 129 additions & 90 deletions

File tree

lib/CloudConvert.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import axios, { AxiosInstance } from 'axios';
1+
import axios, { type AxiosInstance } from 'axios';
22
import io from 'socket.io-client';
3-
import JobsResource, { JobEventData } from './JobsResource';
4-
import TasksResource, { TaskEventData } from './TasksResource';
3+
import JobsResource, { type JobEventData } from './JobsResource';
4+
import TasksResource, { type TaskEventData } from './TasksResource';
55
import UsersResource from './UsersResource';
66
import WebhooksResource from './WebhooksResource';
77
import { version } from '../package.json';
@@ -35,11 +35,8 @@ export default class CloudConvert {
3535
? 'https://api.sandbox.cloudconvert.com/v2/'
3636
: 'https://api.cloudconvert.com/v2/',
3737
headers: {
38-
Authorization: 'Bearer ' + this.apiKey,
39-
'User-Agent':
40-
'cloudconvert-node/v' +
41-
version +
42-
' (https://github.com/cloudconvert/cloudconvert-node)'
38+
Authorization: `Bearer ${this.apiKey}`,
39+
'User-Agent': `cloudconvert-node/v${version} (https://github.com/cloudconvert/cloudconvert-node)`
4340
}
4441
});
4542
}
@@ -48,8 +45,8 @@ export default class CloudConvert {
4845
this.tasks = new TasksResource(this);
4946
this.jobs = new JobsResource(this);
5047
this.users = new UsersResource(this);
51-
this.webhooks = new WebhooksResource(this);
52-
this.signedUrls = new SignedUrlResource(this);
48+
this.webhooks = new WebhooksResource();
49+
this.signedUrls = new SignedUrlResource();
5350
}
5451

5552
subscribe(
@@ -76,7 +73,7 @@ export default class CloudConvert {
7673
channel,
7774
auth: {
7875
headers: {
79-
Authorization: 'Bearer ' + this.apiKey
76+
Authorization: `Bearer ${this.apiKey}`
8077
}
8178
}
8279
});

lib/JobsResource.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import CloudConvert from './CloudConvert';
2-
import { Operation, Task, TaskEventData, TaskStatus } from './TasksResource';
2+
import {
3+
type Operation,
4+
type Task,
5+
type TaskEventData,
6+
type TaskStatus
7+
} from './TasksResource';
38

49
export type JobEvent = 'created' | 'updated' | 'finished' | 'failed';
510
export type JobStatus = 'processing' | 'finished' | 'error';
@@ -31,14 +36,14 @@ export default class JobsResource {
3136
}
3237

3338
async get(id: string, query = null): Promise<Job> {
34-
const response = await this.cloudConvert.axios.get('jobs/' + id, {
39+
const response = await this.cloudConvert.axios.get(`jobs/${id}`, {
3540
params: query || {}
3641
});
3742
return response.data.data;
3843
}
3944

4045
async wait(id: string): Promise<Job> {
41-
const response = await this.cloudConvert.axios.get('jobs/' + id, {
46+
const response = await this.cloudConvert.axios.get(`jobs/${id}`, {
4247
baseURL: this.cloudConvert.useSandbox
4348
? 'https://sync.api.sandbox.cloudconvert.com/v2/'
4449
: 'https://sync.api.cloudconvert.com/v2/'
@@ -68,7 +73,7 @@ export default class JobsResource {
6873
}
6974

7075
async delete(id: string): Promise<void> {
71-
await this.cloudConvert.axios.delete('jobs/' + id);
76+
await this.cloudConvert.axios.delete(`jobs/${id}`);
7277
}
7378

7479
async subscribeEvent(
@@ -77,8 +82,8 @@ export default class JobsResource {
7782
callback: (event: JobEventData) => void
7883
): Promise<void> {
7984
this.cloudConvert.subscribe(
80-
'private-job.' + id,
81-
'job.' + event,
85+
`private-job.${id}`,
86+
`job.${event}`,
8287
callback
8388
);
8489
}
@@ -89,8 +94,8 @@ export default class JobsResource {
8994
callback: (event: TaskEventData) => void
9095
): Promise<void> {
9196
this.cloudConvert.subscribe(
92-
'private-job.' + id + '.tasks',
93-
'task.' + event,
97+
`private-job.${id}.tasks`,
98+
`task.${event}`,
9499
callback
95100
);
96101
}
@@ -130,4 +135,5 @@ interface TaskContainer {
130135
export interface JobTemplate {
131136
tasks: TaskContainer;
132137
tag?: string;
138+
webhook_url?: string;
133139
}

lib/SignedUrlResource.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
11
import * as crypto from 'crypto';
2-
import CloudConvert from './CloudConvert';
3-
import { JobTemplate } from './JobsResource';
2+
import { type JobTemplate } from './JobsResource';
43

54
export default class SignedUrlResource {
6-
private readonly cloudConvert: CloudConvert;
7-
8-
constructor(cloudConvert: CloudConvert) {
9-
this.cloudConvert = cloudConvert;
10-
}
11-
125
sign(
136
base: string,
147
signingSecret: string,
158
job: JobTemplate,
169
cacheKey: string | null
1710
): string {
1811
const json = JSON.stringify(job);
19-
const base64 = new Buffer(json || '').toString('base64');
12+
const base64 = Buffer.from(json || '').toString('base64');
2013
const base64UrlSafe = base64
2114
.replace('+', '-')
2215
.replace('/', '_')
2316
.replace(/=+$/, '');
2417

25-
let url = base + '?job=' + base64UrlSafe;
18+
let url = `${base}?job=${base64UrlSafe}`;
2619

2720
if (cacheKey) {
28-
url += '&cache_key=' + cacheKey;
21+
url += `&cache_key=${cacheKey}`;
2922
}
3023

3124
const hmac = crypto.createHmac('sha256', signingSecret);
3225
const signature = hmac.update(Buffer.from(url, 'utf-8')).digest('hex');
3326

34-
url += '&s=' + signature;
27+
url += `&s=${signature}`;
3528

3629
return url;
3730
}

0 commit comments

Comments
 (0)