-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redis, encore clients. first attempt at a working application
Signed-off-by: Fredrik Lundkvist <[email protected]>
- Loading branch information
Showing
12 changed files
with
359 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
testEnvironment: 'node' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
|
||
export interface AdNormalizerConfiguration { | ||
encoreUrl: string; | ||
callbackListenerUrl: string; | ||
minioUrl: string; | ||
minioAccessKey: string; | ||
minioSecretKey: string; | ||
minioBucket: string; | ||
adServerUrl: string; | ||
redisUrl: string; | ||
encoreUrl: string; | ||
callbackListenerUrl: string; | ||
minioUrl: string; | ||
minioAccessKey: string; | ||
minioSecretKey: string; | ||
minioBucket: string; | ||
adServerUrl: string; | ||
redisUrl: string; | ||
serviceAccessToken?: string; | ||
} | ||
|
||
let config: AdNormalizerConfiguration | null = null; | ||
|
||
let loadConfiguration = (): AdNormalizerConfiguration => { | ||
const encoreUrl = process.env.ENCORE_URL; | ||
const callbackListenerUrl = process.env.CALLBACK_LISTENER_URL; | ||
const minioUrl = process.env.MINIO_URL; | ||
const minioAccessKey = process.env.MINIO_ACCESS_KEY; | ||
const minioSecretKey = process.env.MINIO_SECRET_KEY; | ||
const adServerUrl = process.env.AD_SERVER_URL; | ||
const redisUrl = process.env.REDIS_URL; | ||
const minioBucket = process.env.MINIO_BUCKET; | ||
const configuration = { | ||
encoreUrl: encoreUrl, | ||
callbackListenerUrl: callbackListenerUrl, | ||
minioUrl: minioUrl, | ||
minioAccessKey: minioAccessKey, | ||
minioSecretKey: minioSecretKey, | ||
adServerUrl: adServerUrl, | ||
redisUrl: redisUrl, | ||
minioBucket: minioBucket | ||
} as AdNormalizerConfiguration; | ||
const loadConfiguration = (): AdNormalizerConfiguration => { | ||
const encoreUrl = process.env.ENCORE_URL; | ||
const callbackListenerUrl = process.env.CALLBACK_LISTENER_URL; | ||
const minioUrl = process.env.MINIO_URL; | ||
const minioAccessKey = process.env.MINIO_ACCESS_KEY; | ||
const minioSecretKey = process.env.MINIO_SECRET_KEY; | ||
const adServerUrl = process.env.AD_SERVER_URL; | ||
const redisUrl = process.env.REDIS_URL; | ||
const minioBucket = process.env.MINIO_BUCKET; | ||
const serviceAccessToken = process.env.SERVICE_ACCESS_TOKEN; | ||
const configuration = { | ||
encoreUrl: encoreUrl, | ||
callbackListenerUrl: callbackListenerUrl, | ||
minioUrl: minioUrl, | ||
minioAccessKey: minioAccessKey, | ||
minioSecretKey: minioSecretKey, | ||
adServerUrl: adServerUrl, | ||
redisUrl: redisUrl, | ||
minioBucket: minioBucket, | ||
serviceAccessToken: serviceAccessToken | ||
} as AdNormalizerConfiguration; | ||
|
||
return configuration; | ||
} | ||
return configuration; | ||
}; | ||
|
||
/** | ||
* Gets the application config. Configuration is treated as a singleton. | ||
* If the configuration has not been loaded yet, it will be loaded from environment variables. | ||
* If the configuration has not been loaded yet, it will be loaded from environment variables. | ||
* @returns configuration object | ||
*/ | ||
export default function getConfiguration(): AdNormalizerConfiguration { | ||
if (config === null) { | ||
config = loadConfiguration(); | ||
} | ||
return config as AdNormalizerConfiguration; | ||
} | ||
if (config === null) { | ||
config = loadConfiguration(); | ||
} | ||
return config as AdNormalizerConfiguration; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,51 @@ | ||
import logger from "../util/logger" | ||
import { ManifestAsset } from "../vast/vastApi"; | ||
import { EncoreJob, InputType } from "./types" | ||
import logger from '../util/logger'; | ||
import { ManifestAsset } from '../vast/vastApi'; | ||
import { EncoreJob, InputType } from './types'; | ||
|
||
export class EncoreClient { | ||
constructor(private url: string, private callbackUrl: string) { } | ||
constructor( | ||
private url: string, | ||
private callbackUrl: string, | ||
private serviceAccessToken?: string | ||
) {} | ||
|
||
async submitJob(job: EncoreJob): Promise<Response> { | ||
logger.info('Submitting job to Encore', { job }); | ||
return fetch(`${this.url}/encoreJobs`, { | ||
method: 'POST', | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Accept": "application/hal+json" | ||
}, | ||
body: JSON.stringify(job), | ||
}) | ||
async submitJob(job: EncoreJob): Promise<Response> { | ||
logger.info('Submitting job to Encore', { job }); | ||
let headersWithToken = undefined; | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/hal+json' | ||
}; | ||
if (this.serviceAccessToken) { | ||
headersWithToken = { | ||
...headers, | ||
'x-jwt': `Bearer ${this.serviceAccessToken}` | ||
}; | ||
const sat = this.serviceAccessToken; | ||
} | ||
return fetch(`${this.url}/encoreJobs`, { | ||
method: 'POST', | ||
headers: headersWithToken ? headersWithToken : headers, | ||
body: JSON.stringify(job) | ||
}); | ||
} | ||
|
||
async createEncoreJob(creative: ManifestAsset): Promise<Response> { | ||
const job: EncoreJob = { | ||
externalId: creative.creativeId, | ||
profile: 'program', | ||
outputFolder: creative.creativeId, | ||
baseName: creative.creativeId, | ||
progressCallbackUri: this.callbackUrl, | ||
inputs: [{ | ||
uri: creative.masterPlaylistUrl, | ||
seekTo: 0, | ||
copyTs: true, | ||
type: InputType.AUDIO_VIDEO | ||
}] | ||
async createEncoreJob(creative: ManifestAsset): Promise<Response> { | ||
const job: EncoreJob = { | ||
externalId: creative.creativeId, | ||
profile: 'program', | ||
outputFolder: '/usercontent/', | ||
baseName: creative.creativeId, | ||
progressCallbackUri: this.callbackUrl, | ||
inputs: [ | ||
{ | ||
uri: 'https://testcontent.eyevinn.technology/mp4/stswe-tvplus-promo.mp4', // TODO: Use the correct URI from the VAST response | ||
seekTo: 0, | ||
copyTs: true, | ||
type: InputType.AUDIO_VIDEO | ||
} | ||
return this.submitJob(job); | ||
} | ||
] | ||
}; | ||
return this.submitJob(job); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import { EncoreJob, InputFile, InputType } from "./types"; | ||
import { EncoreJob, InputFile, InputType } from './types'; | ||
|
||
const testJob: EncoreJob = { | ||
externalId: "123", | ||
profile: "ad", | ||
outputFolder: "test", | ||
basename: "ad", | ||
progressCallbackUri: "http://localhost:3000", | ||
inputs: [ | ||
{ | ||
uri: "test", | ||
seekTo: 0, | ||
copyTs: true, | ||
type: InputType.AUDIO_VIDEO | ||
} as InputFile | ||
] | ||
} | ||
externalId: '123', | ||
profile: 'ad', | ||
outputFolder: 'test', | ||
baseName: 'ad', | ||
progressCallbackUri: 'http://localhost:3000', | ||
inputs: [ | ||
{ | ||
uri: 'test', | ||
seekTo: 0, | ||
copyTs: true, | ||
type: InputType.AUDIO_VIDEO | ||
} as InputFile | ||
] | ||
}; | ||
|
||
describe('EncoreJob', () => { | ||
it('should serialize to JSON correctly', () => { | ||
const expected = '{"externalId":"123","profile":"ad","outputFolder":"test","basename":"ad","progressCallbackUri":"http://localhost:3000","inputs":[{"uri":"test","seekTo":0,"copyTs":true,"type":"AudioVideo"}]}'; | ||
const serialized = JSON.stringify(testJob); | ||
expect(serialized).toEqual(expected); | ||
}); | ||
}); | ||
it('should serialize to JSON correctly', () => { | ||
const expected = | ||
'{"externalId":"123","profile":"ad","outputFolder":"test","baseName":"ad","progressCallbackUri":"http://localhost:3000","inputs":[{"uri":"test","seekTo":0,"copyTs":true,"type":"AudioVideo"}]}'; | ||
const serialized = JSON.stringify(testJob); | ||
expect(serialized).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
// Minimal implementation of an encore job | ||
export type EncoreJob = { | ||
externalId: string; | ||
profile: string; | ||
outputFolder: string; | ||
baseName: string; | ||
progressCallbackUri: string; | ||
inputs: InputFile[]; | ||
} | ||
externalId: string; | ||
profile: string; | ||
outputFolder: string; | ||
baseName: string; | ||
progressCallbackUri: string; | ||
inputs: InputFile[]; | ||
}; | ||
|
||
export type InputFile = { | ||
uri: string; | ||
seekTo: number; | ||
copyTs: boolean; | ||
type: InputType | ||
} | ||
uri: string; | ||
seekTo: number; | ||
copyTs: boolean; | ||
type: InputType; | ||
}; | ||
|
||
export enum InputType { | ||
AUDIO ="Audio", | ||
VIDEO="Video", | ||
AUDIO_VIDEO="AudioVideo" | ||
AUDIO = 'Audio', | ||
VIDEO = 'Video', | ||
AUDIO_VIDEO = 'AudioVideo' | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.