({
videoId,
duration,
resolution,
videoCodec,
audioCodec,
isScreenshot = false,
isUpload = false,
folderId,
orgId,
screenshotContentType,
supportsUploadProgress = false,
}: {
videoId?: Video.VideoId;
duration?: number;
resolution?: string;
videoCodec?: string;
audioCodec?: string;
isScreenshot?: boolean;
isUpload?: boolean;
folderId?: Folder.FolderId;
orgId: Organisation.OrganisationId;
screenshotContentType?: string;
// TODO: Remove this once we are happy with it's stability
supportsUploadProgress?: boolean;
})
| 110 | } |
| 111 | |
| 112 | export async function createVideoAndGetUploadUrl({ |
| 113 | videoId, |
| 114 | duration, |
| 115 | resolution, |
| 116 | videoCodec, |
| 117 | audioCodec, |
| 118 | isScreenshot = false, |
| 119 | isUpload = false, |
| 120 | folderId, |
| 121 | orgId, |
| 122 | screenshotContentType, |
| 123 | supportsUploadProgress = false, |
| 124 | }: { |
| 125 | videoId?: Video.VideoId; |
| 126 | duration?: number; |
| 127 | resolution?: string; |
| 128 | videoCodec?: string; |
| 129 | audioCodec?: string; |
| 130 | isScreenshot?: boolean; |
| 131 | isUpload?: boolean; |
| 132 | folderId?: Folder.FolderId; |
| 133 | orgId: Organisation.OrganisationId; |
| 134 | screenshotContentType?: string; |
| 135 | // TODO: Remove this once we are happy with it's stability |
| 136 | supportsUploadProgress?: boolean; |
| 137 | }) { |
| 138 | const user = await getCurrentUser(); |
| 139 | |
| 140 | if (!user) throw new Error("Unauthorized"); |
| 141 | |
| 142 | try { |
| 143 | if (!userIsPro(user) && duration && duration > 300) |
| 144 | throw new Error("upgrade_required"); |
| 145 | |
| 146 | await requireOrganizationAccess(user.id, orgId); |
| 147 | |
| 148 | const date = new Date(); |
| 149 | const formattedDate = `${date.getDate()} ${date.toLocaleString("default", { |
| 150 | month: "long", |
| 151 | })} ${date.getFullYear()}`; |
| 152 | |
| 153 | if (videoId) { |
| 154 | const [existingVideo] = await db() |
| 155 | .select() |
| 156 | .from(videos) |
| 157 | .where(eq(videos.id, videoId)); |
| 158 | |
| 159 | if (existingVideo) { |
| 160 | if (existingVideo.ownerId !== user.id) throw new Error("Forbidden"); |
| 161 | |
| 162 | const existingVideoDomain = Video.Video.decodeSync({ |
| 163 | ...existingVideo, |
| 164 | bucketId: existingVideo.bucket, |
| 165 | storageIntegrationId: existingVideo.storageIntegrationId, |
| 166 | createdAt: existingVideo.createdAt.toISOString(), |
| 167 | updatedAt: existingVideo.updatedAt.toISOString(), |
| 168 | metadata: existingVideo.metadata, |
| 169 | }); |
no test coverage detected