From 9ccc6231a543059420078faf0fa9200f16769177 Mon Sep 17 00:00:00 2001 From: ingalls Date: Thu, 22 Aug 2024 12:51:04 -0600 Subject: [PATCH] Create Lease --- api/lib/control/video-service.ts | 22 ++++++++++++++++++++++ api/routes/video-lease.ts | 13 ++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/api/lib/control/video-service.ts b/api/lib/control/video-service.ts index 589bdffd1..2cac67553 100644 --- a/api/lib/control/video-service.ts +++ b/api/lib/control/video-service.ts @@ -158,4 +158,26 @@ export default class VideoServiceControl { return lease; } + + async delete(leaseid: string): Promise { + 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; + } } diff --git a/api/routes/video-lease.ts b/api/routes/video-lease.ts index 2de7010fe..2c2059bb8 100644 --- a/api/routes/video-lease.ts +++ b/api/routes/video-lease.ts @@ -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({