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

Video Lease Renewal #389

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 16 additions & 2 deletions api/routes/video-lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export default async function router(schema: Schema, config: Config) {
}),
body: Type.Object({
name: Type.Optional(Type.String()),
duration: Type.Optional(Type.Integer({
minimum: 0,
description: 'Duration in Seconds'
})),
}),
res: Type.Object({
lease: VideoLeaseResponse,
Expand All @@ -157,14 +161,24 @@ export default async function router(schema: Schema, config: Config) {
try {
const user = await Auth.as_user(config, req);

if (user.access !== AuthUserAccess.ADMIN && req.body.duration > 60 * 60 * 16) {
throw new Err(400, null, 'Only Administrators can request a lease > 16 hours')
}

let lease;
if (user.access === AuthUserAccess.ADMIN) {
lease = await config.models.VideoLease.commit(req.params.lease, req.body);
lease = await config.models.VideoLease.commit(req.params.lease, {
...req.body,
expiration: moment().add(req.body.duration, 'seconds').toISOString(),
});
} else {
lease = await config.models.VideoLease.from(req.params.lease);

if (lease.username === user.email) {
lease = await config.models.VideoLease.commit(req.params.lease, req.body);
lease = await config.models.VideoLease.commit(req.params.lease, {
...req.body,
expiration: moment().add(req.body.duration, 'seconds').toISOString(),
});
} else {
throw new Err(400, null, 'You can only update a lease you created');
}
Expand Down
132 changes: 66 additions & 66 deletions api/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</template>

<script setup lang='ts'>
import { ref, computed, defineProps, onMounted } from 'vue'
import { ref, computed, onMounted } from 'vue'
import type { ComputedRef } from 'vue';
import type { MissionLog } from '../../../../types.ts';
import {
Expand Down
Loading
Loading