fix API paths

This commit is contained in:
Jan Koppe 2024-05-04 14:06:46 +02:00
parent 0a857a194c
commit 6005ce6170
Signed by: thunfisch
GPG Key ID: BE935B0735A2129B
7 changed files with 82 additions and 87 deletions

View File

@ -21,12 +21,12 @@ class PullPatch(ModelSchema):
extra = "forbid" extra = "forbid"
@router.get('/pulls', response=List[Pull]) @router.get('/', response=List[Pull])
def list_pulls(request): def list_pulls(request):
return get_objects_for_user(request.user, 'view_pull', models.Pull.objects.all()) return get_objects_for_user(request.user, 'view_pull', models.Pull.objects.all())
@router.post('/pulls', response=Pull) @router.post('/', response=Pull)
def create_pull(request, payload: Pull): def create_pull(request, payload: Pull):
if not request.user.has_perm('view_stream', payload.stream): if not request.user.has_perm('view_stream', payload.stream):
raise HttpError(401, "unauthorized") raise HttpError(401, "unauthorized")
@ -38,7 +38,7 @@ def create_pull(request, payload: Pull):
return pull return pull
@router.get('/pulls/{id}', response=Pull) @router.get('/{id}', response=Pull)
def get_pull(request, id: int): def get_pull(request, id: int):
pull = get_object_or_404(models.Pull, id=id) pull = get_object_or_404(models.Pull, id=id)
@ -48,7 +48,7 @@ def get_pull(request, id: int):
return pull return pull
@router.patch('/pulls/{id}', response=Pull) @router.patch('/{id}', response=Pull)
def patch_pull(request, id: int, payload: PullPatch): def patch_pull(request, id: int, payload: PullPatch):
pull = get_object_or_404(models.Pull, id=id) pull = get_object_or_404(models.Pull, id=id)
@ -67,7 +67,7 @@ def patch_pull(request, id: int, payload: PullPatch):
return pull return pull
@router.delete('/pulls/{id}', response=None) @router.delete('/{id}', response=None)
def delete_pull(request, id: int): def delete_pull(request, id: int):
pull = get_object_or_404(models.Pull, id=id) pull = get_object_or_404(models.Pull, id=id)

View File

@ -23,11 +23,11 @@ class LocalRecordingStoragePatch(ModelSchema):
extra = "forbid" extra = "forbid"
@router.get('/storage/local', response=List[LocalRecordingStorage]) @router.get('/local', response=List[LocalRecordingStorage])
def list_local_recording_storage(request): def list_local_recording_storage(request):
return get_objects_for_user(request.user, 'view_localrecordingstorage', models.LocalRecordingStorage.objects.all()) return get_objects_for_user(request.user, 'view_localrecordingstorage', models.LocalRecordingStorage.objects.all())
@router.get('/storage/local/{id}', response=LocalRecordingStorage) @router.get('/local/{id}', response=LocalRecordingStorage)
def get_local_recording_storage(request, id: int): def get_local_recording_storage(request, id: int):
obj = get_object_or_404(models.LocalRecordingStorage, id=id) obj = get_object_or_404(models.LocalRecordingStorage, id=id)
@ -36,7 +36,7 @@ def get_local_recording_storage(request, id: int):
return obj return obj
@router.post('/storage/local', response=LocalRecordingStorage) @router.post('/local', response=LocalRecordingStorage)
def create_local_recording_storage(request, payload: LocalRecordingStorage): def create_local_recording_storage(request, payload: LocalRecordingStorage):
obj = models.LocalRecordingStorage.objects.create(**payload.dict()) obj = models.LocalRecordingStorage.objects.create(**payload.dict())
@ -45,7 +45,7 @@ def create_local_recording_storage(request, payload: LocalRecordingStorage):
assign_perm('delete_localrecordingstorage', request.user, obj) assign_perm('delete_localrecordingstorage', request.user, obj)
return obj return obj
@router.patch('/storage/local/{id}', response=LocalRecordingStorage) @router.patch('/local/{id}', response=LocalRecordingStorage)
def patch_local_recording_storage(request, id: int, payload: LocalRecordingStoragePatch): def patch_local_recording_storage(request, id: int, payload: LocalRecordingStoragePatch):
obj = get_object_or_404(models.LocalRecordingStorage, id=id) obj = get_object_or_404(models.LocalRecordingStorage, id=id)
@ -57,7 +57,7 @@ def patch_local_recording_storage(request, id: int, payload: LocalRecordingStora
obj.save() obj.save()
return obj return obj
@router.delete('/storage/local/{id}', response=None) @router.delete('/local/{id}', response=None)
def delete_local_recording_storage(request, id: int): def delete_local_recording_storage(request, id: int):
obj = get_object_or_404(models.LocalRecordingStorage, id=id) obj = get_object_or_404(models.LocalRecordingStorage, id=id)
if not request.user.has_perm('delete_localrecordingstorage', obj): if not request.user.has_perm('delete_localrecordingstorage', obj):

View File

@ -22,12 +22,12 @@ class RestreamPatch(ModelSchema):
extra = "forbid" extra = "forbid"
@router.get('/restreams', response=List[Restream]) @router.get('/', response=List[Restream])
def list_restreams(request): def list_restreams(request):
return get_objects_for_user(request.user, 'view_restream', models.Restream.objects.all()) return get_objects_for_user(request.user, 'view_restream', models.Restream.objects.all())
@router.post('/restreams', response=Restream) @router.post('/', response=Restream)
def create_restream(request, payload: Restream): def create_restream(request, payload: Restream):
if not request.user.has_perm('view_stream', payload.stream): if not request.user.has_perm('view_stream', payload.stream):
raise HttpError(401, "unauthorized") raise HttpError(401, "unauthorized")
@ -39,7 +39,7 @@ def create_restream(request, payload: Restream):
return restream return restream
@router.get('/restreams/{id}', response=Restream) @router.get('/{id}', response=Restream)
def get_restream(request, id: int): def get_restream(request, id: int):
restream = get_object_or_404(models.Restream, id=id) restream = get_object_or_404(models.Restream, id=id)
@ -49,7 +49,7 @@ def get_restream(request, id: int):
return restream return restream
@router.patch('/restreams/{id}', response=Restream) @router.patch('/{id}', response=Restream)
def update_restream(request, id: int, payload: RestreamPatch): def update_restream(request, id: int, payload: RestreamPatch):
restream = get_object_or_404(models.Restream, id=id) restream = get_object_or_404(models.Restream, id=id)
@ -68,7 +68,7 @@ def update_restream(request, id: int, payload: RestreamPatch):
return restream return restream
@router.delete('/restreams/{id}', response=None) @router.delete('/{id}', response=None)
def delete_restream(request, id: int): def delete_restream(request, id: int):
restream = get_object_or_404(models.Restream, id=id) restream = get_object_or_404(models.Restream, id=id)

View File

@ -28,12 +28,12 @@ class StreamCreate(ModelSchema):
extra = "forbid" extra = "forbid"
@router.get('/streams', response=List[Stream]) @router.get('/', response=List[Stream])
def list_streams(request): def list_streams(request):
return get_objects_for_user(request.user, 'view_stream', models.Stream.objects.all()) return get_objects_for_user(request.user, 'view_stream', models.Stream.objects.all())
@router.post('/streams', response=Stream) @router.post('/', response=Stream)
def create_stream(request, payload: StreamCreate): def create_stream(request, payload: StreamCreate):
stream = models.Stream.objects.create(**payload.dict()) stream = models.Stream.objects.create(**payload.dict())
assign_perm('view_stream', request.user, stream) assign_perm('view_stream', request.user, stream)
@ -42,7 +42,7 @@ def create_stream(request, payload: StreamCreate):
return stream return stream
@router.get('/streams/{id}', response=Stream) @router.get('/{id}', response=Stream)
def get_stream(request, id: int): def get_stream(request, id: int):
stream = get_object_or_404(models.Stream, id=id) stream = get_object_or_404(models.Stream, id=id)
@ -51,7 +51,7 @@ def get_stream(request, id: int):
return stream return stream
@router.patch('/streams/{id}', response=Stream) @router.patch('/{id}', response=Stream)
def update_stream(request, id: int, payload: StreamPatch): def update_stream(request, id: int, payload: StreamPatch):
stream = get_object_or_404(models.Stream, id=id) stream = get_object_or_404(models.Stream, id=id)
@ -63,7 +63,7 @@ def update_stream(request, id: int, payload: StreamPatch):
return stream return stream
@router.delete('/streams/{id}', response=None) @router.delete('/{id}', response=None)
def delete_stream(request, id: int): def delete_stream(request, id: int):
stream = get_object_or_404(models.Stream, id=id) stream = get_object_or_404(models.Stream, id=id)

View File

@ -1,37 +1,34 @@
var app = new Vue({ var app = new Vue({
el: '#app', el: "#app",
data: { data: {
cfgs: [], cfgs: [],
isLoading: true isLoading: true,
}, },
methods: { methods: {
detailLink(id) { detailLink(id) {
return `${id}/` return `${id}/`;
}, },
deleteLink(id) { deleteLink(id) {
return `${id}/delete` return `${id}/delete`;
}, },
toggleActive(cfg) { toggleActive(cfg) {
axios axios
.patch('/api/v2/config/pulls/' + cfg.id, { active: !cfg.active }) .patch("/api/v2/config/pull/" + cfg.id, { active: !cfg.active })
.then(response => { .then((response) => {
i = this.cfgs.findIndex((obj => obj.id == cfg.id)) i = this.cfgs.findIndex((obj) => obj.id == cfg.id);
Vue.set(this.cfgs, i, response.data) Vue.set(this.cfgs, i, response.data);
} });
)
}, },
fetchData() { fetchData() {
axios axios.get("/api/v2/config/pull").then((response) => {
.get('/api/v2/config/pulls') this.cfgs = response.data;
.then(response => { this.isLoading = false;
this.cfgs = response.data });
this.isLoading = false
})
}
}, },
mounted () { },
axios.defaults.xsrfCookieName = 'csrftoken' mounted() {
axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN' axios.defaults.xsrfCookieName = "csrftoken";
this.fetchData() axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
} this.fetchData();
}) },
});

View File

@ -1,37 +1,34 @@
var app = new Vue({ var app = new Vue({
el: '#app', el: "#app",
data: { data: {
cfgs: [], cfgs: [],
isLoading: true isLoading: true,
}, },
methods: { methods: {
detailLink(id) { detailLink(id) {
return `${id}/` return `${id}/`;
}, },
deleteLink(id) { deleteLink(id) {
return `${id}/delete` return `${id}/delete`;
}, },
toggleActive(cfg) { toggleActive(cfg) {
axios axios
.patch('/api/v2/config/restreams/' + cfg.id, { active: !cfg.active }) .patch("/api/v2/config/restream/" + cfg.id, { active: !cfg.active })
.then(response => { .then((response) => {
i = this.cfgs.findIndex((obj => obj.id == cfg.id)) i = this.cfgs.findIndex((obj) => obj.id == cfg.id);
Vue.set(this.cfgs, i, response.data) Vue.set(this.cfgs, i, response.data);
} });
)
}, },
fetchData() { fetchData() {
axios axios.get("/api/v2/config/restream").then((response) => {
.get('/api/v2/config/restreams') this.cfgs = response.data;
.then(response => { this.isLoading = false;
this.cfgs = response.data });
this.isLoading = false
})
}
}, },
mounted () { },
axios.defaults.xsrfCookieName = 'csrftoken' mounted() {
axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN' axios.defaults.xsrfCookieName = "csrftoken";
this.fetchData() axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
} this.fetchData();
}) },
});

View File

@ -1,34 +1,35 @@
var app = new Vue({ var app = new Vue({
el: '#app', el: "#app",
data: { data: {
streams: [], streams: [],
isLoading: true isLoading: true,
}, },
methods: { methods: {
isPublishing(stream) { isPublishing(stream) {
return stream.publish_counter > 0 return stream.publish_counter > 0;
}, },
detailLink(id) { detailLink(id) {
return `${id}/` return `${id}/`;
}, },
deleteLink(id) { deleteLink(id) {
return `${id}/delete` return `${id}/delete`;
}, },
fetchData() { fetchData() {
axios axios.get("/api/v2/config/stream").then((response) => {
.get('/api/v2/config/streams') this.streams = response.data;
.then(response => { this.isLoading = false;
this.streams = response.data });
this.isLoading = false
})
}
}, },
mounted () { },
axios.defaults.xsrfCookieName = 'csrftoken' mounted() {
axios.defaults.xsrfHeaderName = 'X-CSRFTOKEN' axios.defaults.xsrfCookieName = "csrftoken";
this.fetchData() axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
setInterval(function () {
this.fetchData(); this.fetchData();
}.bind(this), 1000); setInterval(
} function () {
}) this.fetchData();
}.bind(this),
1000,
);
},
});