This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bluesky): add support for video
- Loading branch information
1 parent
10dfac4
commit 57d58e4
Showing
5 changed files
with
112 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createMediaRecord } from "../create-media-record"; | ||
|
||
describe("createMediaRecord", () => { | ||
const mockImageAttachments = [ | ||
{ alt_text: "Alt text 1", data: { blob: { original: "image1.jpg" } } }, | ||
{ alt_text: "Alt text 2", data: { blob: { original: "image2.jpg" } } }, | ||
]; | ||
|
||
const mockVideoAttachment = [ | ||
{ alt_text: null, data: { blob: { original: "video.mp4" } } }, | ||
]; | ||
|
||
it("should an image media record for 'image' mediaType", () => { | ||
const result = createMediaRecord("image", mockImageAttachments); | ||
expect(result).toEqual({ | ||
media: { | ||
$type: "app.bsky.embed.images", | ||
images: [ | ||
{ alt: "Alt text 1", image: "image1.jpg" }, | ||
{ alt: "Alt text 2", image: "image2.jpg" }, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it("should a video media record for 'video' mediaType", () => { | ||
const result = createMediaRecord("video", mockVideoAttachment); | ||
expect(result).toEqual({ | ||
media: { | ||
$type: "app.bsky.embed.video", | ||
video: "video.mp4", | ||
}, | ||
}); | ||
}); | ||
|
||
it("should return an empty object for undefined mediaType", () => { | ||
const result = createMediaRecord(undefined, []); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it("should return an empty object for unhandled mediaType", () => { | ||
const result = createMediaRecord("audio", []); | ||
expect(result).toEqual({}); | ||
}); | ||
}); |
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,37 @@ | ||
import { BlueskyMediaAttachment } from "../../types"; | ||
|
||
/** | ||
* Creates a media record based on the given media type and attachments. | ||
* | ||
* @param {'image' | 'video' | undefined} mediaType - The type of the media (image or video). | ||
* @param {BlueskyMediaAttachment[]} mediaAttachments - The media attachments to include in the record. | ||
* @returns {Object} The media record object tailored to the media type. | ||
*/ | ||
export const createMediaRecord = ( | ||
mediaType: "image" | "video" | undefined, | ||
mediaAttachments: BlueskyMediaAttachment[], | ||
) => { | ||
switch (mediaType) { | ||
case "image": | ||
return { | ||
media: { | ||
$type: "app.bsky.embed.images", | ||
images: mediaAttachments.map((i) => ({ | ||
alt: i.alt_text ?? "", | ||
image: i.data.blob.original, | ||
})), | ||
}, | ||
}; | ||
|
||
case "video": | ||
return { | ||
media: { | ||
$type: "app.bsky.embed.video", | ||
video: mediaAttachments[0].data.blob.original, | ||
}, | ||
}; | ||
|
||
default: | ||
return {}; | ||
} | ||
}; |
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
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