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"
@router.get('/pulls', response=List[Pull])
@router.get('/', response=List[Pull])
def list_pulls(request):
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):
if not request.user.has_perm('view_stream', payload.stream):
raise HttpError(401, "unauthorized")
@ -38,7 +38,7 @@ def create_pull(request, payload: Pull):
return pull
@router.get('/pulls/{id}', response=Pull)
@router.get('/{id}', response=Pull)
def get_pull(request, id: int):
pull = get_object_or_404(models.Pull, id=id)
@ -48,7 +48,7 @@ def get_pull(request, id: int):
return pull
@router.patch('/pulls/{id}', response=Pull)
@router.patch('/{id}', response=Pull)
def patch_pull(request, id: int, payload: PullPatch):
pull = get_object_or_404(models.Pull, id=id)
@ -67,7 +67,7 @@ def patch_pull(request, id: int, payload: PullPatch):
return pull
@router.delete('/pulls/{id}', response=None)
@router.delete('/{id}', response=None)
def delete_pull(request, id: int):
pull = get_object_or_404(models.Pull, id=id)

View File

@ -23,11 +23,11 @@ class LocalRecordingStoragePatch(ModelSchema):
extra = "forbid"
@router.get('/storage/local', response=List[LocalRecordingStorage])
@router.get('/local', response=List[LocalRecordingStorage])
def list_local_recording_storage(request):
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):
obj = get_object_or_404(models.LocalRecordingStorage, id=id)
@ -36,7 +36,7 @@ def get_local_recording_storage(request, id: int):
return obj
@router.post('/storage/local', response=LocalRecordingStorage)
@router.post('/local', response=LocalRecordingStorage)
def create_local_recording_storage(request, payload: LocalRecordingStorage):
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)
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):
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()
return obj
@router.delete('/storage/local/{id}', response=None)
@router.delete('/local/{id}', response=None)
def delete_local_recording_storage(request, id: int):
obj = get_object_or_404(models.LocalRecordingStorage, id=id)
if not request.user.has_perm('delete_localrecordingstorage', obj):

View File

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

View File

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

View File

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

View File

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

View File

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