Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update metadata route #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.NewMetadata,
): 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
69 changes: 60 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,16 +506,67 @@ export interface FluffyStream {

export interface Metadata {
show: string;
firstBroadcastedAt: null;
broadcasterShowId: null;
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 interface NewMetadata {
firstBroadcastedAt?: Date;
broadcasterShowId?: string;
enableAutoAccept: boolean;
productionCompanyName?: string;
productionYear?: number;
programType?: ProgramType;
fileType?: FileType;
fileFormat?: FileFormat;
aspectRatio?: AspectRatio;
textedVideoType?: TextedVideoType;
}

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",
}
Comment on lines +559 to 570
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il y a une raison d'utiliser enum plutôt que type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'aime bien les enum car on peut les reutiliser si on a besoin dans le code. Contrairement aux types


export interface ShowOrganization {
Expand Down