This project consists of several modules:
EdgeStorage.ts
: Provides functionality for interacting with BunnyCDN storage endpoints.Collection.ts
: Represents a video collection in Bunny Stream and provides functions for modifying the collection.Stream.ts
: Provides the main functionalities and interacts with Bunny Stream API's - Video and Collection management operations.import BunnyCDN, { StorageEndpoints } from "bunnycdn";
const cdn = new BunnyCDN({
AccessKey: "access-key",
StorageZone: StorageEndpoints.Falkenstein
});
import { EdgeStorage, StorageEndpoints } from "bunnycdn";
const edgeStorage = new EdgeStorage("access-key", StorageEndpoints.Falkenstein);
const storageZone = edgeStorage.CreateClient("storage-zone-name");
const files = await storageZone.ListFiles('.')
for (let file of files) {
console.log(`A file was found with the name ${file.ObjectName} and the guid ${file.Guid} with ${file.Length} bytes.`)
}
import { Stream } from "bunnycdn";
const stream = new Stream();
const library = stream.GetLibrary(1234, 'access-key');
const MyCollection = await library.GetCollection("collection-guid");
const result = (
await library.ListVideos({
collection: MyCollection.data?.collectionId,
page: 1,
itemsPerPage: 100,
orderBy: 'date',
search: 'My Video'
})
).data || {};
console.log(
result.itemsPerPage,
result.currentPage,
result.totalItems,
);
for (let video of result) {
console.log(`${video.title}} has ${video.views} views and is ${video.length} seconds long`);
}
Type: interface
interface ErrorResponse {
HttpCode: number;
Message: string;
}
HttpCode
and Message
.Type: enum
enum StatusResponse {
OK = 200,
CREATED = 201,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
NOT_FOUND = 404,
INTERNAL_SERVER_ERROR = 500,
// Undefined
UNDEFINED = 0
}
Declares VideoCaption
, VideoChapter
, VideoMoment
, VideoMetaTag
, VideoTranscodingMessageLevel
,
VideoTranscodingMessage
, VideoStatus
, Video
, APIVideo
, VideoStatics
, and VideoList
.
Please refer to the provided typings for their definitions.
To create an instance of EdgeStorage, you need to provide AccessKey
and optionally, StorageZone
as parameters.
Example:
const edgeStorage = new EdgeStorage('your-access-key', StorageEndpoints.Falkenstein);
Methods:
edgeStorage.Endpoint
edgeStorage.Endpoint = StorageEndpoints.NY
edgeStorage.AccessKey
edgeStorage.AccessKey = 'access-key-2'
EdgeStorageClient
.
edgeStorage.CreateClient('storage-zone-name')
Extends from EdgeStorage.
Methods:
await edgeStorageClient.ListFiles('.')
await edgeStorageClient.DownloadFile('videos/hello_world.mp4')
await edgeStorageClient.UploadFile('images/javascript.png', MyImageBuffer)
await edgeStorageClient.DeleteFile('temp/old_database.json')
interface APICollection {
videoLibraryId: number;
guid?: string;
name?: string;
videoCount: number;
totalSize: number;
previewVideoIds?: string;
}
This class represents a video collection with methods to update and delete itself.
Constructor parameters:
data: APICollection
collectionId: string
library: Library
Methods:
await myCollection.Update('my-collection-updated')
await myCollection.Delete()
Main class for working with Bunny Stream APIs.
Constructor:
const stream = new Stream();
Methods:
This class represents a Bunny Stream library.
Constructor parameters:
libraryId: number
accessKey: string
Methods:
await stream.GetVideo(12345)
await stream.GetVideoStatistics({
dateFrom: '2023-01-01T12:00:00.000Z',
dateTo: '2023-04-03T12:00:00.000Z',
hourly: true,
videoGuid: 'my-unique-guid'
})
await stream.ListVideos({
page: 1;
itemsPerPage: 100;
search: 'My video';
collection: 'my-collection-guid',
orderBy: 'date'
})
await stream.CreateVideo({
title: 'My Newest Video',
collectionId: 'my-collection-guid',
thumbnailTime: 67 // hours * 3600 + minutes * 60 + seconds
})
await stream.FetchVideo({
url: 'https://example.com/my-video-link',
headers: {
'my-header-key': 'my-header-value',
// ...
}
}, {
collectionId: 'my-collection-guid',
lowPriority: true,
thumbnailTime: 67 // hours * 3600 + minutes * 60 + seconds
})
await stream.GetCollection('my-collection-guid')
await stream.GetCollection({
page: 1,
itemsPerPage: 100,
search: 'My Collection',
orderBy: "date"
})
await stream.CreateCollection('my-collection')
export interface UpdateParams {
title?: string;
collectionId?: string;
chapters?: VideoChapter[];
moments?: VideoMoment[];
metaTags?: VideoMetaTag[];
}
Update
method.This class encapsulates a video in Bunny Stream.
Constructor parameters:
library: Library
data: APIVideo
videoId: number
Methods:
Update(props: UpdateParams)
: Updates the video with the provided properties.
Give a object whose is suitable for UpdateParams
Delete()
: Deletes the video.
await video.Delete()
Upload(enabledResolutions?: string)
: Uploads the video with the specified resolutions (optional).
Coming SoonGetHeatmap()
: Retrieves the video heatmap data.
await video.GetHeatmap()
Reencode()
: Re-encodes the video.
await video.Reencode()
SetThumbnail(payload: { thumbnailUrl?: string; })
: Sets the thumbnail of the video.
await video.SetThumbnail({
thumbnailUrl: 'https://example.com/my-thumbnail.png'
})
AddCaption(srclang: string, params: { srclang?: string; label?: string; captionsFile?: string; })
: Adds a caption to the video.
await video.AddCaption('tr', {
srclang: 'tr',
label: 'Turkish',
captionsFile: Base64(MyFileContent)
})
DeleteCaption(srclang: string)
: Deletes a caption from the video.
await video.DeleteCaption('tr')
By using the Video
class, you can manage individual videos in your Bunny Stream library.
By using these classes and methods, you can perform various operations related to BunnyCDN Storage and Bunny Stream.