Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve api schema #2156

Merged
merged 37 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3b4a79e
Update api-schema.yaml
suhailkakar Apr 29, 2024
41132ef
add userId to components
suhailkakar Apr 29, 2024
957a045
Update api-schema.yaml
suhailkakar Apr 29, 2024
f619066
add null support to issues component
suhailkakar Apr 30, 2024
c00b23c
add kind and userId to session component
suhailkakar Apr 30, 2024
232c22b
add userId to multistream component
suhailkakar Apr 30, 2024
e1fa6a5
make error optional
suhailkakar Apr 30, 2024
65975d3
remove required params from response
suhailkakar Apr 30, 2024
ffba83c
add webhook request body
suhailkakar Apr 30, 2024
1484c40
temp: add type ignore
suhailkakar Apr 30, 2024
a28546e
Update webhook.ts
suhailkakar Apr 30, 2024
10c719b
Update api-schema.yaml
suhailkakar Apr 30, 2024
35d7e0e
Update [id].tsx
suhailkakar Apr 30, 2024
026ed84
final fixes/improvments
suhailkakar May 1, 2024
9d8c42a
for schemas
suhailkakar May 1, 2024
239193d
update webhook payload
suhailkakar May 1, 2024
5129331
Merge commit 'e59ea2791906162b1eb1d309d37adeb01ec88083' into sk/schem…
0xcadams May 14, 2024
f18100b
fix: recordings playback IDs can be null
0xcadams May 14, 2024
db46d77
fix: schema validation
0xcadams May 14, 2024
60d9270
fix: schema default
0xcadams May 14, 2024
fc49743
fix: added null for profiles
0xcadams May 14, 2024
9d5beaf
Merge commit 'f01c4572da84cbee8c106b3d560214b6fe7be0be' into sk/schem…
0xcadams May 14, 2024
8eb2d38
fix: compile schemas
0xcadams May 14, 2024
ea0ab89
fix: change asset responses to 201
0xcadams May 15, 2024
2e87688
fix: change to nullable create/patch stream
0xcadams May 15, 2024
ee2cbf3
feat: added nullable to asset profiles field
0xcadams May 15, 2024
792704d
Merge commit 'ee2cbf3f33b6d01bd42998981d04119e5123090d' into sk/schem…
0xcadams May 15, 2024
c19abe3
fix: merge latest
0xcadams May 15, 2024
66b2ef2
fix: added back 200 response for create asset
0xcadams May 15, 2024
3f544b1
api: Handle null profiles appropriately
victorges May 15, 2024
0fd5380
Merge commit '3f544b16921d31d51b86dce8e7a8c27d540f9713' into sk/schem…
0xcadams May 15, 2024
063df12
Merge commit 'd1936e9ef6f04e9bfcd00bb10b6eb821efe5e0b3' into sk/schem…
0xcadams May 15, 2024
89f5251
api/schema: Add breakdownBy[] to /data/usage docs
victorges May 16, 2024
e86b1d6
api: Delete the deprecated (now broken) /import API
victorges May 16, 2024
2679555
api/schema: Address PR comments
victorges May 16, 2024
9306dae
api/schema: Fix schemas of upload APIs
victorges May 16, 2024
9efd51a
fix: isMobile oneof
0xcadams May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/api/src/compile-schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,26 @@ const data = _.merge({}, apiData, dbData);
const indexPath = path.resolve(validatorDir, "index.js");
write(indexPath, indexStr);

const typeDefinition = `export type InputCreatorId =
const creatorIdTypeDefinition = `export type InputCreatorId =
| {
type: "unverified";
value: string;
}
| string;`;

const playbackPolicyTypeDefinition = "export type PlaybackPolicy1 = null;";
const playbackPolicy2TypeDefinition =
"export type PlaybackPolicy2 = PlaybackPolicy | PlaybackPolicy1;";

let typeStr = types.join("\n\n");
const cleanedTypeStr = typeStr.split(typeDefinition).join("");
typeStr = `${cleanedTypeStr.trim()}\n\n${typeDefinition}`;
const cleanedTypeStr = typeStr
.split(creatorIdTypeDefinition)
.join("")
.split(playbackPolicyTypeDefinition)
.join("")
.split(playbackPolicy2TypeDefinition)
.join("");
typeStr = `${cleanedTypeStr.trim()}\n\n${creatorIdTypeDefinition}\n\n${playbackPolicyTypeDefinition}\n\n${playbackPolicy2TypeDefinition}`;

const typePath = path.resolve(schemaDir, "types.d.ts");
write(typePath, typeStr);
Expand Down
145 changes: 71 additions & 74 deletions packages/api/src/controllers/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,88 +804,85 @@ app.post(
}
);

const uploadWithUrlHandler: RequestHandler = async (req, res) => {
let { url, encryption, c2pa, profiles, targetSegmentSizeSecs } =
req.body as NewAssetFromUrlPayload;
if (!url) {
return res.status(422).json({
errors: [`Must provide a "url" field for the asset contents`],
});
}
if (encryption) {
if (encryption.encryptedKey) {
if (!isValidBase64(encryption.encryptedKey)) {
return res.status(422).json({
errors: [`"encryptedKey" must be valid base64`],
});
app.post(
"/upload/url",
authorizer({}),
Dismissed Show dismissed Hide dismissed
validatePost("new-asset-from-url-payload"),
async (req, res) => {
let { url, encryption, c2pa, profiles, targetSegmentSizeSecs } =
req.body as NewAssetFromUrlPayload;
if (!url) {
return res.status(422).json({
errors: [`Must provide a "url" field for the asset contents`],
});
}
if (encryption) {
if (encryption.encryptedKey) {
if (!isValidBase64(encryption.encryptedKey)) {
return res.status(422).json({
errors: [`"encryptedKey" must be valid base64`],
});
}
}
}
}

const id = uuid();
const playbackId = await generateUniquePlaybackId(id);
const newAsset = await validateAssetPayload(req, id, playbackId, Date.now(), {
type: "url",
url,
encryption: assetEncryptionWithoutKey(encryption),
});
const dupAsset = await db.asset.findDuplicateUrlUpload(
url,
req.user.id,
req.project?.id
);
if (dupAsset) {
const [task] = await db.task.find({ outputAssetId: dupAsset.id });
if (!task.length) {
console.error("Found asset with no task", dupAsset);
// proceed as a regular new asset
} else {
// return the existing asset and task, as if created now, with a slightly
// different status code (200, not 201). Should be transparent to clients.
res.status(200).json({ asset: dupAsset, task: { id: task[0].id } });
return;
const id = uuid();
const playbackId = await generateUniquePlaybackId(id);
const newAsset = await validateAssetPayload(
req,
id,
playbackId,
Date.now(),
{
type: "url",
url,
encryption: assetEncryptionWithoutKey(encryption),
}
);
const dupAsset = await db.asset.findDuplicateUrlUpload(
url,
req.user.id,
req.project?.id
);
if (dupAsset) {
const [task] = await db.task.find({ outputAssetId: dupAsset.id });
if (!task.length) {
console.error("Found asset with no task", dupAsset);
// proceed as a regular new asset
} else {
// return the existing asset and task, as if created now, with a slightly
// different status code (200, not 201). Should be transparent to clients.
res.status(200).json({ asset: dupAsset, task: { id: task[0].id } });
return;
}
}
}

await ensureQueueCapacity(req.config, req.user.id);
await ensureQueueCapacity(req.config, req.user.id);

const asset = await createAsset(newAsset, req.queue);
const task = await req.taskScheduler.createAndScheduleTask(
"upload",
{
upload: {
url,
c2pa,
catalystPipelineStrategy: catalystPipelineStrategy(req),
encryption,
thumbnails: !(await isExperimentSubject(
"vod-thumbs-off",
req.user?.id
)),
...(profiles ? { profiles } : null), // avoid serializing null profiles on the task,
targetSegmentSizeSecs,
const asset = await createAsset(newAsset, req.queue);
const task = await req.taskScheduler.createAndScheduleTask(
"upload",
{
upload: {
url,
c2pa,
catalystPipelineStrategy: catalystPipelineStrategy(req),
encryption,
thumbnails: !(await isExperimentSubject(
"vod-thumbs-off",
req.user?.id
)),
...(profiles ? { profiles } : null), // avoid serializing null profiles on the task,
targetSegmentSizeSecs,
},
},
},
undefined,
asset
);

res.status(201);
res.json({ asset, task: { id: task.id } });
};
undefined,
asset
);

app.post(
"/upload/url",
authorizer({}),
validatePost("new-asset-from-url-payload"),
uploadWithUrlHandler
);
// TODO: Remove this at some point. Registered only for backward compatibility.
app.post(
"/import",
authorizer({}),
validatePost("new-asset-payload"),
uploadWithUrlHandler
res.status(201);
res.json({ asset, task: { id: task.id } });
}
);

app.post(
Expand Down
Loading
Loading