Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 75795547040a83a34bd3c32885cf7383fd490420
  • Loading branch information
Redditbara authored and caio1516 committed Mar 3, 2025
1 parent c630e47 commit cc4632e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion devvit-docs/docs/api/redditapi/modules/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ An individual Removal Reason object.

### <a id="submitmediaoptions" name="submitmediaoptions"></a> SubmitMediaOptions

Ƭ **SubmitMediaOptions**: [`CommonSubmitPostOptions`](models.md#commonsubmitpostoptions) & \{ `imageUrls?`: [`string`] ; `kind`: `"image"` \| `"video"` \| `"videogif"` ; `videoPosterUrl`: `string` }
Ƭ **SubmitMediaOptions**: [`CommonSubmitPostOptions`](models.md#commonsubmitpostoptions) & \{ `imageUrls?`: [`string`] ; `kind`: `"image"` \| `"video"` \| `"videogif"` ; `videoPosterUrl?`: `string` }

---

Expand Down
4 changes: 2 additions & 2 deletions packages/public-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
},
"filesize": {
"dist/public-api.min.js": {
"gzip": "60 KB",
"none": "213.1 KB"
"gzip": "61 KB",
"none": "214 KB"
}
},
"source": "./src/index.ts"
Expand Down
16 changes: 11 additions & 5 deletions packages/public-api/src/apis/reddit/models/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export type SubmitMediaOptions = CommonSubmitPostOptions & {
kind: 'image' | 'video' | 'videogif';
// If `kind` is "video" or "videogif" this must be set to the thumbnail URL
// https://www.reddit.com/dev/api/#POST_api_submit
videoPosterUrl: string;
videoPosterUrl?: string;
// If `kind` is "image" this must be set to the image URL
// Currently Devvit only supports posts with a single image
imageUrls?: [string];
Expand Down Expand Up @@ -1117,10 +1117,16 @@ export class Post {
// Post Id might not be present as image/video post creation can happen asynchronously
const isAllowedMediaType =
'kind' in options && ['image', 'video', 'videogif'].includes(options.kind);
if (isAllowedMediaType && !response.json?.data?.id && 'url' in options) {
throw new Error(
`Post of ${options.kind} type with ${options.url} is being created asynchronously and should be updated in the subreddit soon.`
);
if (isAllowedMediaType && !response.json?.data?.id) {
if (options.kind === 'image' && 'imageUrls' in options) {
throw new Error(
`Image post type with ${options.imageUrls} is being created asynchronously and should be updated in the subreddit soon.`
);
} else if ('videoPosterUrl' in options) {
throw new Error(
`Post of ${options.kind} type with ${options.videoPosterUrl} is being created asynchronously and should be updated in the subreddit soon.`
);
}
}

if (!response.json?.data?.id || response.json?.errors?.length) {
Expand Down

0 comments on commit cc4632e

Please sign in to comment.