Skip to content

Commit

Permalink
Add update metadata route
Browse files Browse the repository at this point in the history
  • Loading branch information
Giska committed Dec 4, 2023
1 parent b37713b commit 0d84645
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 56 deletions.
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"files": {
"include": ["src/"]
}
}
},
"lock": false
}
100 changes: 55 additions & 45 deletions src/nomalab.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import {
CopyToBroadcastable,
Deliveries,
DeliverPayload,
Job,
Node,
NodeClass,
NodeKind,
Organization,
Path,
Show,
ShowClass,
ShowKind,
} from "./types.ts";
import * as types from "./types.ts";
import * as mod from "https://deno.land/[email protected]/http/cookie.ts";

export class AlreadyPresentDeliverable extends Error {
Expand All @@ -29,32 +16,32 @@ export class Nomalab {
this.#apiToken = apiToken;
}

async getShow(showUuid: string): Promise<Show> {
async getShow(showUuid: string): Promise<types.Show> {
const response = await this.#fetch(`shows/${showUuid}`, {});
if (!response.ok) {
this.#throwError(
`ERROR - Can't find show with id ${showUuid}.`,
response,
);
}
return response.json() as Promise<Show>;
return response.json() as Promise<types.Show>;
}

async getRoots(organizationId: string): Promise<NodeClass[]> {
async getRoots(organizationId: string): Promise<types.NodeClass[]> {
const response = await this.#requestWithSwitch(
organizationId,
"hierarchy",
);
if (!response.ok) this.#throwError(`ERROR - Can't find root.`, response);
return response.json() as Promise<NodeClass[]>;
return response.json() as Promise<types.NodeClass[]>;
}

async createHierarchy(
organizationId: string,
name: string,
kind: NodeKind,
kind: types.NodeKind,
parent?: string,
): Promise<NodeClass> {
): Promise<types.NodeClass> {
const response = await this.#requestWithSwitch(
organizationId,
"hierarchy",
Expand All @@ -68,13 +55,13 @@ export class Nomalab {
if (!response.ok) {
this.#throwError(`ERROR - Can't create ${kind} ${name}.`, response);
}
return response.json() as Promise<NodeClass>;
return response.json() as Promise<types.NodeClass>;
}

async createShow(
nodeId: string,
name: string,
kind: ShowKind,
kind: types.ShowKind,
): Promise<string> {
const response = await this.#fetch(`hierarchy/${nodeId}/shows`, {
method: "POST",
Expand All @@ -87,7 +74,7 @@ export class Nomalab {
if (!response.ok) {
this.#throwError(`ERROR - Can't create show ${kind} ${name}.`, response);
}
const { id } = await response.json() as ShowClass;
const { id } = await response.json() as types.ShowClass;
return id;
}

Expand Down Expand Up @@ -127,18 +114,36 @@ export class Nomalab {
);
}

async getChildren(nodeUuid: string): Promise<NodeClass[]> {
async updateMetadata(
show: string,
metadata: types.partialMetadata,
): Promise<types.Metadata> {
const response = await this.#fetch(`shows/${show}/metadata`, {
method: "PUT",
bodyJsonObject: metadata,
});

if (!response.ok) {
this.#throwError(
`ERROR - Can't update metadata for show ${show}.`,
response,
);
}
return await response.json() as types.Metadata;
}

async getChildren(nodeUuid: string): Promise<types.NodeClass[]> {
const response = await this.#fetch(`hierarchy/${nodeUuid}/children`, {});
if (!response.ok) {
this.#throwError(
`ERROR - Can't find children with id ${nodeUuid}.`,
response,
);
}
return response.json() as Promise<NodeClass[]>;
return response.json() as Promise<types.NodeClass[]>;
}

async getDeliveries(): Promise<Deliveries> {
async getDeliveries(): Promise<types.Deliveries> {
const response = await this.#fetch(`shows/deliveries`, {});
if (!response.ok) {
if (response.status == 409) {
Expand All @@ -149,32 +154,32 @@ export class Nomalab {
this.#throwError(`ERROR - Can't get deliveries.`, response);
}
}
return response.json() as Promise<Deliveries>;
return response.json() as Promise<types.Deliveries>;
}

async getNode(nodeUuid: string): Promise<Node> {
async getNode(nodeUuid: string): Promise<types.Node> {
const response = await this.#fetch(`hierarchy/${nodeUuid}`, {});
if (!response.ok) {
this.#throwError(
`ERROR - Can't find node with id ${nodeUuid}.`,
response,
);
}
return response.json() as Promise<Node>;
return response.json() as Promise<types.Node>;
}

async getShowsForNode(nodeUuid: string): Promise<ShowClass[]> {
async getShowsForNode(nodeUuid: string): Promise<types.ShowClass[]> {
const response = await this.#fetch(`hierarchy/${nodeUuid}/shows`, {});
if (!response.ok) {
this.#throwError(
`ERROR - error when retrieving shows for node ${nodeUuid}.`,
response,
);
}
return response.json() as Promise<ShowClass[]>;
return response.json() as Promise<types.ShowClass[]>;
}

async getPath(showUuid: string): Promise<Path[]> {
async getPath(showUuid: string): Promise<types.Path[]> {
const response = await this.#fetch(
`admin/shows/path`,
{
Expand All @@ -188,18 +193,18 @@ export class Nomalab {
response,
);
}
return response.json() as Promise<Path[]>;
return response.json() as Promise<types.Path[]>;
}

async getOrganizations(): Promise<Organization[]> {
async getOrganizations(): Promise<types.Organization[]> {
const response = await this.#fetch(`organizations`, {});
if (!response.ok) {
this.#throwError(`ERROR - Can't get organizations.`, response);
}
return response.json() as Promise<Organization[]>;
return response.json() as Promise<types.Organization[]>;
}

async getOrganization(organizationId: string): Promise<Organization> {
async getOrganization(organizationId: string): Promise<types.Organization> {
const organisation = (await this.getOrganizations()).filter((org) => {
return org.id == organizationId;
});
Expand All @@ -209,7 +214,9 @@ export class Nomalab {
return Promise.resolve(organisation[0]);
}

async getOrganizationByName(organizationName: string): Promise<Organization> {
async getOrganizationByName(
organizationName: string,
): Promise<types.Organization> {
const organisation = (await this.getOrganizations()).filter((org) => {
return org.name == organizationName;
});
Expand All @@ -219,15 +226,15 @@ export class Nomalab {
return Promise.resolve(organisation[0]);
}

async getJob(jobUuid: string): Promise<Job> {
async getJob(jobUuid: string): Promise<types.Job> {
const response = await this.#fetch(`jobs/${jobUuid}`, {});
if (!response.ok) {
this.#throwError(`ERROR - Can't find job with id ${jobUuid}.`, response);
}
return response.json() as Promise<Job>;
return response.json() as Promise<types.Job>;
}

async s3Upload(payload: CopyToBroadcastable): Promise<void> {
async s3Upload(payload: types.CopyToBroadcastable): Promise<void> {
const url = payload.destRole ? "aws/copyFromExt" : "aws/copy";
const response = await this.#fetch(
url,
Expand All @@ -249,19 +256,22 @@ export class Nomalab {
return Promise.resolve();
}

async accept(showId: string): Promise<ShowClass> {
async accept(showId: string): Promise<types.ShowClass> {
const response = await this.#fetch(
`shows/${showId}/accept`,
{ method: "POST" },
);
if (!response.ok) {
this.#throwError(`ERROR - Can't accept show. ${showId}`, response);
}
return response.json() as Promise<ShowClass>;
return response.json() as Promise<types.ShowClass>;
}

// Deliver with starting a transcode
async deliver(showId: string, deliverPayload: DeliverPayload): Promise<void> {
async deliver(
showId: string,
deliverPayload: types.DeliverPayload,
): Promise<void> {
const response = await this.#fetch(
`broadcastables/${showId}/deliver`,
{
Expand Down Expand Up @@ -335,7 +345,7 @@ export class Nomalab {
async deliverWithoutTranscoding(
broadcastableId: string,
targetOrgId: string,
): Promise<ShowClass> {
): Promise<types.ShowClass> {
const response = await this.#fetch(
`broadcastables/${broadcastableId}/copyToOrganization`,
{
Expand All @@ -355,7 +365,7 @@ export class Nomalab {
);
}
}
return response.json() as Promise<ShowClass>;
return response.json() as Promise<types.ShowClass>;
}

async getManifest(proxyId: string): Promise<Blob> {
Expand Down
61 changes: 51 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,18 +504,59 @@ export interface FluffyStream {
subtitleType: string;
}

export interface Metadata {
export interface Metadata extends partialMetadata {
show: string;
firstBroadcastedAt: null;
broadcasterShowId: null;
}

export interface partialMetadata {
firstBroadcastedAt?: Date | null;
broadcasterShowId?: string | null;
enableAutoAccept: boolean;
productionCompanyName: null;
productionYear: null;
programType: null;
fileType: null;
fileFormat: null;
aspectRatio: null;
textedVideoType: null;
productionCompanyName?: string | null;
productionYear?: number | null;
programType?: ProgramType | null;
fileType?: FileType | null;
fileFormat?: FileFormat | null;
aspectRatio?: AspectRatio | null;
textedVideoType?: TextedVideoType | null;
}

export type ProgramType =
| "Program"
| "Trailer"
| "Teaser"
| "Neutral bases";

export type FileFormat =
| "SD"
| "HD"
| "UHD"
| "2k"
| "4k"
| "DCP";

export type AspectRatio =
| "1.33"
| "1.66"
| "1.77"
| "1.85"
| "2.00"
| "2.20"
| "2.35"
| "2.39"
| "2.40";

export enum TextedVideoType {
Full = "Full",
Partial = "Partial",
InsertOnly = "InsertOnly",
}

export enum FileType {
Video = "Video",
Audio = "Audio",
Subtitle = "Subtitle",
Extra = "Extra",
}

export interface ShowOrganization {
Expand Down

0 comments on commit 0d84645

Please sign in to comment.