{"id":13602126,"url":"https://github.com/wraith4081/bunnycdn","last_synced_at":"2025-04-11T08:31:36.567Z","repository":{"id":150336374,"uuid":"623058031","full_name":"wraith4081/bunnycdn","owner":"wraith4081","description":"Use the unofficial BunnyCDN library quickly and easily with Javascript","archived":false,"fork":false,"pushed_at":"2024-08-17T10:14:29.000Z","size":6959,"stargazers_count":9,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T00:46:22.665Z","etag":null,"topics":["api","bunny","bunnycdn","cdn","javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wraith4081.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-03T15:56:49.000Z","updated_at":"2024-08-12T15:51:55.000Z","dependencies_parsed_at":"2023-11-12T04:23:19.417Z","dependency_job_id":"d3c1bcb5-4059-4f32-9512-8fc326cfa780","html_url":"https://github.com/wraith4081/bunnycdn","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wraith4081%2Fbunnycdn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wraith4081%2Fbunnycdn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wraith4081%2Fbunnycdn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wraith4081%2Fbunnycdn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wraith4081","download_url":"https://codeload.github.com/wraith4081/bunnycdn/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247851454,"owners_count":21006762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bunny","bunnycdn","cdn","javascript","typescript"],"created_at":"2024-08-01T18:01:14.679Z","updated_at":"2025-04-11T08:31:36.237Z","avatar_url":"https://github.com/wraith4081.png","language":"TypeScript","funding_links":[],"categories":["api"],"sub_categories":[],"readme":"## Documentation\r\n\r\n### Overview\r\n\r\nThis project consists of several modules:\r\n\r\n1. Types and Definitions: Defining ErrorResponse, StatusResponse, Video related types and other types, and utility types.\r\n2. `EdgeStorage.ts`: Provides functionality for interacting with BunnyCDN storage endpoints.\r\n3. `Collection.ts`: Represents a video collection in Bunny Stream and provides functions for modifying the collection.\r\n4. `Stream.ts`: Provides the main functionalities and interacts with Bunny Stream API's - Video and Collection management operations.\r\n\r\n### Quick Start\r\n#### Global\r\n```ts\r\nimport BunnyCDN, { StorageEndpoints } from \"bunnycdn\";\r\n\r\nconst cdn = new BunnyCDN({\r\n    AccessKey: \"access-key\",\r\n    StorageZone: StorageEndpoints.Falkenstein\r\n});\r\n```\r\n#### Spesific\r\n##### EdgeStorage\r\n```ts\r\nimport { EdgeStorage, StorageEndpoints } from \"bunnycdn\";\r\n\r\nconst edgeStorage = new EdgeStorage(\"access-key\", StorageEndpoints.Falkenstein);\r\nconst storageZone = edgeStorage.CreateClient(\"storage-zone-name\");\r\n```\r\n```ts\r\nconst files = await storageZone.ListFiles('.')\r\nfor (let file of files) {\r\n    console.log(`A file was found with the name ${file.ObjectName} and the guid ${file.Guid} with ${file.Length} bytes.`)\r\n}\r\n```\r\n##### Stream\r\n```ts\r\nimport { Stream } from \"bunnycdn\";\r\n\r\nconst stream = new Stream();\r\nconst library = stream.GetLibrary(1234, 'access-key');\r\n```\r\n```ts\r\nconst MyCollection = await library.GetCollection(\"collection-guid\");\r\n\r\nconst result = (\r\n    await library.ListVideos({\r\n        collection: MyCollection.data?.collectionId,\r\n        page: 1,\r\n        itemsPerPage: 100,\r\n        orderBy: 'date',\r\n        search: 'My Video'\r\n    })\r\n).data || {};\r\n\r\nconsole.log(\r\n    result.itemsPerPage,\r\n    result.currentPage,\r\n    result.totalItems,\r\n);\r\n\r\nfor (let video of result) {\r\n    console.log(`${video.title}} has ${video.views} views and is ${video.length} seconds long`);\r\n}\r\n```\r\n### Types and Definitions\r\n\r\n#### ErrorResponse\r\n\r\nType: `interface`\r\n\r\n```ts\r\ninterface ErrorResponse {\r\n    HttpCode: number;\r\n    Message: string;\r\n}\r\n```\r\n\r\n- Represents an error response object with the properties `HttpCode` and `Message`.\r\n\r\n#### StatusResponse\r\n\r\nType: `enum`\r\n\r\n```ts\r\nenum StatusResponse {\r\n    OK = 200,\r\n    CREATED = 201,\r\n\r\n    BAD_REQUEST = 400,\r\n    UNAUTHORIZED = 401,\r\n    NOT_FOUND = 404,\r\n\r\n    INTERNAL_SERVER_ERROR = 500,\r\n\r\n    // Undefined\r\n    UNDEFINED = 0\r\n}\r\n```\r\n\r\n- Represents the possible HTTP status code responses.\r\n\r\n#### Video related types\r\n\r\nDeclares `VideoCaption`, `VideoChapter`, `VideoMoment`, `VideoMetaTag`, `VideoTranscodingMessageLevel`,\r\n`VideoTranscodingMessage`, `VideoStatus`, `Video`, `APIVideo`, `VideoStatics`, and `VideoList`.\r\n\r\nPlease refer to the provided typings for their definitions.\r\n\r\n### EdgeStorage.ts\r\n\r\n#### Class: EdgeStorage\r\n\r\nTo create an instance of EdgeStorage, you need to provide `AccessKey` and optionally, `StorageZone` as parameters.\r\n\r\nExample:\r\n\r\n```javascript\r\nconst edgeStorage = new EdgeStorage('your-access-key', StorageEndpoints.Falkenstein);\r\n```\r\n\r\nMethods:\r\n\r\n- get Endpoint(): Returns the current storage endpoint being used.\r\n  ```ts\r\n    edgeStorage.Endpoint\r\n  ```\r\n- set Endpoint(StorageZone: StorageEndpoints): Sets the current storage endpoint.\r\n  ```ts\r\n    edgeStorage.Endpoint = StorageEndpoints.NY\r\n  ```\r\n- get AccessKey(): Returns the access key being used.\r\n  ```ts\r\n    edgeStorage.AccessKey\r\n  ```\r\n- set AccessKey(AccessKey: string): Sets the access key.\r\n  ```ts\r\n    edgeStorage.AccessKey = 'access-key-2'\r\n  ```\r\n- CreateClient(StorageZoneName: string): Creates and returns an instance of `EdgeStorageClient`.\r\n  ```ts\r\n    edgeStorage.CreateClient('storage-zone-name')\r\n  ```\r\n\r\n#### Class: EdgeStorageClient\r\n\r\nExtends from EdgeStorage.\r\n\r\nMethods:\r\n\r\n- ListFiles(path: string): Fetches and returns a list of storage entities for the given path.\r\n  ```ts\r\n    await edgeStorageClient.ListFiles('.')\r\n  ```\r\n- DownloadFile(path: string): Downloads the file at the given path.\r\n  ```ts\r\n    await edgeStorageClient.DownloadFile('videos/hello_world.mp4')\r\n  ```\r\n- UploadFile(path: string, fileContent: Buffer): Uploads a file with the specified content to the given path.\r\n  ```ts\r\n    await edgeStorageClient.UploadFile('images/javascript.png', MyImageBuffer)\r\n  ```\r\n- DeleteFile(path: string): Deletes a file at the given path.\r\n  ```ts\r\n    await edgeStorageClient.DeleteFile('temp/old_database.json')\r\n  ```\r\n\r\n### Collection.ts\r\n\r\n#### Interface: APICollection\r\n\r\n```ts\r\ninterface APICollection {\r\n    videoLibraryId: number;\r\n    guid?: string;\r\n    name?: string;\r\n    videoCount: number;\r\n    totalSize: number;\r\n    previewVideoIds?: string;\r\n}\r\n```\r\n\r\n- Represents the API response for a video collection.\r\n\r\n#### Class: Collection\r\n\r\nThis class represents a video collection with methods to update and delete itself.\r\n\r\nConstructor parameters:\r\n- `data: APICollection`\r\n- `collectionId: string`\r\n- `library: Library`\r\n\r\nMethods:\r\n\r\n- Update(name?: string): Updates the collection with the new name if provided.\r\n  ```ts\r\n    await myCollection.Update('my-collection-updated')\r\n  ```\r\n- Delete(): Deletes the collection.\r\n  ```ts\r\n    await myCollection.Delete()\r\n  ```\r\n\r\n### Stream.ts\r\n\r\n#### Class: Stream\r\n\r\nMain class for working with Bunny Stream APIs.\r\n\r\nConstructor:\r\n\r\n```javascript\r\nconst stream = new Stream();\r\n```\r\n\r\nMethods:\r\n\r\n- GetLibrary(libraryId: number, accessKey: string): Retrieves the library with the given library ID and access key.\r\n\r\n#### Class: Library\r\n\r\nThis class represents a Bunny Stream library.\r\n\r\nConstructor parameters:\r\n- `libraryId: number`\r\n- `accessKey: string`\r\n\r\nMethods:\r\n\r\n- GetVideo(videoId: number): Retrieves a video with the given video ID.\r\n  ```ts\r\n    await stream.GetVideo(12345)\r\n  ```\r\n- GetVideoStatistics(params: object): Fetches video statistics based on given parameters.\r\n  ```ts\r\n    await stream.GetVideoStatistics({\r\n        dateFrom: '2023-01-01T12:00:00.000Z',\r\n        dateTo: '2023-04-03T12:00:00.000Z',\r\n        hourly: true,\r\n        videoGuid: 'my-unique-guid'\r\n    })\r\n  ```\r\n- ListVideos(params: object): Lists videos in the library based on given parameters.\r\n  ```ts\r\n    await stream.ListVideos({\r\n        page: 1;\r\n        itemsPerPage: 100;\r\n        search: 'My video';\r\n        collection: 'my-collection-guid',\r\n        orderBy: 'date'\r\n    })\r\n  ```\r\n- CreateVideo(params: object): Creates a new video in the library.\r\n  ```ts\r\n    await stream.CreateVideo({\r\n        title: 'My Newest Video',\r\n        collectionId: 'my-collection-guid',\r\n        thumbnailTime: 67 // hours * 3600 + minutes * 60 + seconds\r\n    })\r\n  ```\r\n- FetchVideo(bodyParams: object, queryParams: object): Fetches a video from a remote URL.\r\n  ```ts\r\n    await stream.FetchVideo({\r\n        url: 'https://example.com/my-video-link',\r\n        headers: {\r\n            'my-header-key': 'my-header-value',\r\n            // ...\r\n        }\r\n    }, {\r\n        collectionId: 'my-collection-guid',\r\n        lowPriority: true,\r\n        thumbnailTime: 67 // hours * 3600 + minutes * 60 + seconds\r\n    })\r\n  ```\r\n- GetCollection(collectionId: string): Retrieves a collection with the given collection ID.\r\n  ```ts\r\n    await stream.GetCollection('my-collection-guid')\r\n  ```\r\n- GetCollectionList(queryParams: object): Retrieves a list of collections based on given parameters.\r\n  ```ts\r\n    await stream.GetCollection({\r\n        page: 1,\r\n        itemsPerPage: 100,\r\n        search: 'My Collection',\r\n        orderBy: \"date\"\r\n    })\r\n  ```\r\n- CreateCollection(name?: string): Creates a new collection in the library with the specified name.\r\n  ```ts\r\n    await stream.CreateCollection('my-collection')\r\n  ```\r\n\r\n### Video.ts\r\n\r\n#### Interface: UpdateParams\r\n\r\n```ts\r\nexport interface UpdateParams {\r\n    title?: string;\r\n    collectionId?: string;\r\n    chapters?: VideoChapter[];\r\n    moments?: VideoMoment[];\r\n    metaTags?: VideoMetaTag[];\r\n}\r\n```\r\n\r\n- Represents the parameters that can be updated when calling the `Update` method.\r\n\r\n#### Class: Video\r\n\r\nThis class encapsulates a video in Bunny Stream.\r\n\r\nConstructor parameters:\r\n\r\n- `library: Library`\r\n- `data: APIVideo`\r\n- `videoId: number`\r\n\r\nMethods:\r\n\r\n- `Update(props: UpdateParams)`: Updates the video with the provided properties.\r\n  ***Give a object whose is suitable for `UpdateParams`***\r\n- `Delete()`: Deletes the video.\r\n  ```ts\r\n    await video.Delete()\r\n  ```\r\n- `Upload(enabledResolutions?: string)`: Uploads the video with the specified resolutions (optional).\r\n  ***Coming Soon***\r\n- `GetHeatmap()`: Retrieves the video heatmap data.\r\n  ```ts\r\n    await video.GetHeatmap()\r\n  ```\r\n- `Reencode()`: Re-encodes the video.\r\n  ```ts\r\n    await video.Reencode()\r\n  ```\r\n- `SetThumbnail(payload: { thumbnailUrl?: string; })`: Sets the thumbnail of the video.\r\n  ```ts\r\n    await video.SetThumbnail({ \r\n        thumbnailUrl: 'https://example.com/my-thumbnail.png'\r\n    })\r\n  ```\r\n- `AddCaption(srclang: string, params: { srclang?: string; label?: string; captionsFile?: string; })`: Adds a caption to the video.\r\n  ```ts\r\n    await video.AddCaption('tr', {\r\n        srclang: 'tr',\r\n        label: 'Turkish',\r\n        captionsFile: Base64(MyFileContent)\r\n    })\r\n  ```\r\n- `DeleteCaption(srclang: string)`: Deletes a caption from the video.\r\n  ```ts\r\n    await video.DeleteCaption('tr')\r\n  ```\r\n\r\nBy using the `Video` class, you can manage individual videos in your Bunny Stream library.\r\n\r\nBy using these classes and methods, you can perform various operations related to BunnyCDN Storage and Bunny Stream.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwraith4081%2Fbunnycdn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwraith4081%2Fbunnycdn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwraith4081%2Fbunnycdn/lists"}