Skip to content

Commit

Permalink
feat(nodejs): remove nodejs specific dependancies
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierapivideo authored Dec 28, 2023
1 parent 35430c3 commit 12cf953
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 180 deletions.
23 changes: 0 additions & 23 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import axios, { AxiosError, AxiosHeaders, AxiosProgressEvent } from 'axios';
import ApiVideoError from './ApiVideoError';
import ProblemDetails from './model/ProblemDetails';
import { encode } from 'js-base64';
import { Readable, Stream } from 'stream';
import AccessToken from './model/AccessToken';

export type QueryOptions = {
Expand Down Expand Up @@ -107,25 +106,3 @@ export default class HttpClient {
}
}
}

export async function readableToBuffer(readable: Readable): Promise<Buffer> {
const writableStream = new Stream.Writable({
defaultEncoding: 'utf-8',
});
const data: Buffer[] = [];
writableStream._write = (chunk, encoding, next) => {
data.push(Buffer.from(chunk, encoding));
next();
};

return new Promise((resolve, reject) => {
Stream.pipeline(readable, writableStream, async (err) => {
if (err) {
reject(err);
}

const buffer = Buffer.concat(data);
resolve(buffer);
});
});
}
1 change: 0 additions & 1 deletion src/api/AnalyticsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Do not edit the class manually.
*/

import { URLSearchParams } from 'url';
import ObjectSerializer from '../ObjectSerializer';
import HttpClient, { QueryOptions } from '../HttpClient';
import AnalyticsPlaysResponse from '../model/AnalyticsPlaysResponse';
Expand Down
19 changes: 4 additions & 15 deletions src/api/CaptionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
* Do not edit the class manually.
*/

import path from 'path';
import { createReadStream } from 'fs';
import { URLSearchParams } from 'url';
import FormData from 'form-data';
import ObjectSerializer from '../ObjectSerializer';
import HttpClient, { QueryOptions } from '../HttpClient';
import Caption from '../model/Caption';
import CaptionsListResponse from '../model/CaptionsListResponse';
import CaptionsUpdatePayload from '../model/CaptionsUpdatePayload';
import { Readable } from 'stream';
import { readableToBuffer } from '../HttpClient';
import { createBufferFromPartialData } from '../utils';

/**
* no description
Expand All @@ -41,7 +37,7 @@ export default class CaptionsApi {
public async upload(
videoId: string,
language: string,
file: string | Readable | Buffer
file: Buffer | Blob | ArrayBuffer
): Promise<Caption> {
const queryParams: QueryOptions = {};
queryParams.headers = {};
Expand All @@ -55,15 +51,8 @@ export default class CaptionsApi {
'Required parameter language was null or undefined when calling upload.'
);
}
let fileName = 'file';
let fileBuffer = file;
if (typeof file === 'string') {
fileName = path.basename(file);
fileBuffer = createReadStream(file);
}
if (file instanceof Readable) {
fileBuffer = await readableToBuffer(file);
}
const fileName = 'file';
const fileBuffer = createBufferFromPartialData(file);

// Path Params
const localVarPath = '/videos/{videoId}/captions/{language}'
Expand Down
19 changes: 4 additions & 15 deletions src/api/ChaptersApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
* Do not edit the class manually.
*/

import path from 'path';
import { createReadStream } from 'fs';
import { URLSearchParams } from 'url';
import FormData from 'form-data';
import ObjectSerializer from '../ObjectSerializer';
import HttpClient, { QueryOptions } from '../HttpClient';
import Chapter from '../model/Chapter';
import ChaptersListResponse from '../model/ChaptersListResponse';
import { Readable } from 'stream';
import { readableToBuffer } from '../HttpClient';
import { createBufferFromPartialData } from '../utils';

/**
* no description
Expand All @@ -40,7 +36,7 @@ export default class ChaptersApi {
public async upload(
videoId: string,
language: string,
file: string | Readable | Buffer
file: Buffer | Blob | ArrayBuffer
): Promise<Chapter> {
const queryParams: QueryOptions = {};
queryParams.headers = {};
Expand All @@ -54,15 +50,8 @@ export default class ChaptersApi {
'Required parameter language was null or undefined when calling upload.'
);
}
let fileName = 'file';
let fileBuffer = file;
if (typeof file === 'string') {
fileName = path.basename(file);
fileBuffer = createReadStream(file);
}
if (file instanceof Readable) {
fileBuffer = await readableToBuffer(file);
}
const fileName = 'file';
const fileBuffer = createBufferFromPartialData(file);

// Path Params
const localVarPath = '/videos/{videoId}/chapters/{language}'
Expand Down
19 changes: 4 additions & 15 deletions src/api/LiveStreamsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
* Do not edit the class manually.
*/

import path from 'path';
import { createReadStream } from 'fs';
import { URLSearchParams } from 'url';
import FormData from 'form-data';
import ObjectSerializer from '../ObjectSerializer';
import HttpClient, { QueryOptions } from '../HttpClient';
import LiveStream from '../model/LiveStream';
import LiveStreamCreationPayload from '../model/LiveStreamCreationPayload';
import LiveStreamListResponse from '../model/LiveStreamListResponse';
import LiveStreamUpdatePayload from '../model/LiveStreamUpdatePayload';
import { Readable } from 'stream';
import { readableToBuffer } from '../HttpClient';
import { createBufferFromPartialData } from '../utils';

/**
* no description
Expand Down Expand Up @@ -328,7 +324,7 @@ export default class LiveStreamsApi {
*/
public async uploadThumbnail(
liveStreamId: string,
file: string | Readable | Buffer
file: Buffer | Blob | ArrayBuffer
): Promise<LiveStream> {
const queryParams: QueryOptions = {};
queryParams.headers = {};
Expand All @@ -337,15 +333,8 @@ export default class LiveStreamsApi {
'Required parameter liveStreamId was null or undefined when calling uploadThumbnail.'
);
}
let fileName = 'file';
let fileBuffer = file;
if (typeof file === 'string') {
fileName = path.basename(file);
fileBuffer = createReadStream(file);
}
if (file instanceof Readable) {
fileBuffer = await readableToBuffer(file);
}
const fileName = 'file';
const fileBuffer = createBufferFromPartialData(file);

// Path Params
const localVarPath = '/live-streams/{liveStreamId}/thumbnail'
Expand Down
19 changes: 4 additions & 15 deletions src/api/PlayerThemesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
* Do not edit the class manually.
*/

import path from 'path';
import { createReadStream } from 'fs';
import { URLSearchParams } from 'url';
import FormData from 'form-data';
import ObjectSerializer from '../ObjectSerializer';
import HttpClient, { QueryOptions } from '../HttpClient';
import PlayerTheme from '../model/PlayerTheme';
import PlayerThemeCreationPayload from '../model/PlayerThemeCreationPayload';
import PlayerThemeUpdatePayload from '../model/PlayerThemeUpdatePayload';
import PlayerThemesListResponse from '../model/PlayerThemesListResponse';
import { Readable } from 'stream';
import { readableToBuffer } from '../HttpClient';
import { createBufferFromPartialData } from '../utils';

/**
* no description
Expand Down Expand Up @@ -302,7 +298,7 @@ export default class PlayerThemesApi {
*/
public async uploadLogo(
playerId: string,
file: string | Readable | Buffer,
file: Buffer | Blob | ArrayBuffer,
link?: string
): Promise<PlayerTheme> {
const queryParams: QueryOptions = {};
Expand All @@ -312,15 +308,8 @@ export default class PlayerThemesApi {
'Required parameter playerId was null or undefined when calling uploadLogo.'
);
}
let fileName = 'file';
let fileBuffer = file;
if (typeof file === 'string') {
fileName = path.basename(file);
fileBuffer = createReadStream(file);
}
if (file instanceof Readable) {
fileBuffer = await readableToBuffer(file);
}
const fileName = 'file';
const fileBuffer = createBufferFromPartialData(file);

// Path Params
const localVarPath = '/players/{playerId}/logo'
Expand Down
1 change: 0 additions & 1 deletion src/api/UploadTokensApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Do not edit the class manually.
*/

import { URLSearchParams } from 'url';
import ObjectSerializer from '../ObjectSerializer';
import HttpClient, { QueryOptions } from '../HttpClient';
import TokenCreationPayload from '../model/TokenCreationPayload';
Expand Down
Loading

0 comments on commit 12cf953

Please sign in to comment.