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

api: bulk creation of multistream targets #1968

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 27 additions & 9 deletions packages/api/src/controllers/multistream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,33 @@ target.post(
authorizer({}),
validatePost("multistream-target"),
async (req, res) => {
const input = req.body as MultistreamTarget;
const data = await db.multistreamTarget.fillAndCreate({
name: input.name,
url: input.url,
disabled: input.disabled,
userId: req.user.id,
});
res.status(201);
res.json(data);
if (Array.isArray(req.body)) {
const input = req.body as MultistreamTarget[];
let data = [];
for (var i = 0; i < input.length; i++) {
data.push(
await db.multistreamTarget.fillAndCreate({
name: input[i].name,
url: input[i].url,
disabled: input[i].disabled,
userId: req.user.id,
})
);
}
res.status(201);
res.json(data);
return;
} else {
const input = req.body as MultistreamTarget;
const data = await db.multistreamTarget.fillAndCreate({
name: input.name,
url: input.url,
disabled: input.disabled,
userId: req.user.id,
});
res.status(201);
res.json(data);
}
}
);

Expand Down
6 changes: 6 additions & 0 deletions packages/api/src/schema/api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ components:
example:
- id not provided
- user not found
multistream-target-input:
oneOf:
- $ref: "#/multistream-target"
gioelecerati marked this conversation as resolved.
Show resolved Hide resolved
- type: array
items:
$ref: "#/multistream-target"
multistream-target:
type: object
required:
Expand Down