-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(strapi-implementation): add new types
- Loading branch information
1 parent
155cb92
commit db331df
Showing
8 changed files
with
92 additions
and
27 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 |
---|---|---|
|
@@ -28,3 +28,7 @@ amplifytools.xcconfig | |
.secret-* | ||
**.sample | ||
#amplify-do-not-edit-end | ||
|
||
.env | ||
.env.development | ||
.env.production |
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,17 +1,41 @@ | ||
import { VideoOnDemand } from '../models' | ||
import { VideoOnDemand } from './api.interface' | ||
import { IApi } from './IApi' | ||
import { StrapiMedia } from './strapi.interface' | ||
|
||
export class StrapiApi implements IApi { | ||
private readonly endpoint: string | ||
private readonly baseUrl: string | ||
|
||
private readonly token: string | ||
|
||
constructor(endpoint: string, token: string) { | ||
this.endpoint = endpoint | ||
constructor({ baseUrl, token }: { baseUrl?: string; token?: string }) { | ||
if (!baseUrl || !token) | ||
throw new Error('StrapiApi: baseUrl and token are required') | ||
|
||
this.baseUrl = baseUrl | ||
this.token = token | ||
} | ||
|
||
async fetchHighlightedVideos(): Promise<VideoOnDemand[]> { | ||
return [] | ||
const response = await fetch( | ||
`${this.baseUrl}/api/vods?filters[highlighted][$eq]=true`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
}, | ||
} | ||
) | ||
|
||
const videos: StrapiMedia[] = await response | ||
.json() | ||
.then((res) => res.data) | ||
return videos.map((video: StrapiMedia) => ({ | ||
id: video.id, | ||
title: video.attributes.Name, | ||
description: video.attributes.description, | ||
highlighted: video.attributes.highlighted, | ||
createdAt: video.attributes.createdAt, | ||
updatedAt: video.attributes.updatedAt, | ||
src: video.attributes.media_url, | ||
})) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface Thumbnail { | ||
src: string | ||
} | ||
|
||
export interface VideoOnDemand { | ||
id: string | ||
title: string | ||
description: string | ||
highlighted: boolean | ||
thumbnail?: Thumbnail | ||
createdAt: string | ||
updatedAt: string | ||
src: string | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface StrapiMedia { | ||
id: string | ||
attributes: { | ||
Name: string | ||
createdAt: string | ||
updatedAt: string | ||
rotation_start?: number | ||
rotation_end?: number | ||
description: string | ||
type?: string | ||
media_url: string | ||
highlighted: boolean | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { IApi } from '../api/IApi' | ||
import { StrapiApi } from '../api/StrapiApi' | ||
import { createContext } from 'react' | ||
|
||
export const CMSContext = createContext<{ | ||
api: IApi | ||
}>({ | ||
api: new StrapiApi({ | ||
baseUrl: process.env.REACT_APP_CMS_BASE_URL, | ||
token: process.env.REACT_APP_CMS_TOKEN, | ||
}), | ||
}) |
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