Skip to content

Commit

Permalink
Create Lease
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Aug 22, 2024
1 parent 7768518 commit 9ccc623
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
22 changes: 22 additions & 0 deletions api/lib/control/video-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,26 @@ export default class VideoServiceControl {

return lease;
}

async delete(leaseid: string): Promise<void> {
const video = await this.settings();

if (!video.configured) throw new Err(400, null, 'Media Integration is not configured');

const headers = this.headers(video.username, video.password);

const lease = await this.config.models.VideoLease.from(leaseid);

await this.config.models.VideoLease.delete(leaseid);

const url = new URL(`/v3/config/paths/delete/${lease.path}`, video.url);
url.port = '9997';

await fetch(url, {
method: 'DELETE',
headers,
})

return;
}
}
13 changes: 8 additions & 5 deletions api/routes/video-lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ export default async function router(schema: Schema, config: Config) {
const user = await Auth.as_user(config, req);

if (user.access === AuthUserAccess.ADMIN) {
await config.models.VideoLease.delete(req.params.lease);
await videoControl.delete(req.params.lease);
} else {
await config.models.VideoLease.delete(sql`
username = ${user.email}
AND id = ${req.params.lease}
`);
const lease = await config.models.VideoLease.from(req.params.lease);

if (lease.username === user.email) {
await videoControl.delete(req.params.lease);
} else {
throw new Err(400, null, 'You can only delete a least you created');
}
}

return res.json({
Expand Down

0 comments on commit 9ccc623

Please sign in to comment.