-
Notifications
You must be signed in to change notification settings - Fork 0
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
Giska
wants to merge
2
commits into
main
Choose a base branch
from
feature/add-metadata-route
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -8,5 +8,6 @@ | |
"files": { | ||
"include": ["src/"] | ||
} | ||
} | ||
}, | ||
"lock": false | ||
} |
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,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 { | ||
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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) { | ||
|
@@ -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`, | ||
{ | ||
|
@@ -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; | ||
}); | ||
|
@@ -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; | ||
}); | ||
|
@@ -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, | ||
|
@@ -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`, | ||
{ | ||
|
@@ -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`, | ||
{ | ||
|
@@ -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> { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 quetype
?There was a problem hiding this comment.
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