save config to yaml file
This commit is contained in:
parent
d4a2ad1d4f
commit
92a2a4f38c
@ -2,12 +2,25 @@ import os
|
||||
from platform import uname
|
||||
from time import sleep
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
import psutil
|
||||
import yaml
|
||||
|
||||
from django.conf import settings
|
||||
from natsort import natsorted
|
||||
|
||||
|
||||
def read_yaml():
|
||||
if os.path.isfile(settings.FFPLAYOUT_CONFIG):
|
||||
with open(settings.FFPLAYOUT_CONFIG, 'r') as config_file:
|
||||
return yaml.safe_load(config_file)
|
||||
|
||||
|
||||
def write_yaml(data):
|
||||
if os.path.isfile(settings.FFPLAYOUT_CONFIG):
|
||||
with open(settings.FFPLAYOUT_CONFIG, 'w') as outfile:
|
||||
yaml.dump(data, outfile, default_flow_style=False, sort_keys=False)
|
||||
|
||||
|
||||
def sizeof_fmt(num, suffix='B'):
|
||||
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
|
||||
if abs(num) < 1024.0:
|
||||
|
@ -1,17 +1,7 @@
|
||||
import os
|
||||
|
||||
import yaml
|
||||
|
||||
from django.conf import settings
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from .utils import SystemStats, get_media_path
|
||||
|
||||
|
||||
def read_config(path):
|
||||
with open(path, 'r') as config_file:
|
||||
return yaml.safe_load(config_file)
|
||||
from .utils import read_yaml, write_yaml, SystemStats, get_media_path
|
||||
|
||||
|
||||
class Config(APIView):
|
||||
@ -22,9 +12,10 @@ class Config(APIView):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if 'config' in request.GET.dict():
|
||||
if os.path.isfile(settings.FFPLAYOUT_CONFIG):
|
||||
yaml = read_config(settings.FFPLAYOUT_CONFIG)
|
||||
return Response(yaml)
|
||||
yaml_input = read_yaml()
|
||||
|
||||
if yaml_input:
|
||||
return Response(yaml_input)
|
||||
else:
|
||||
return Response({
|
||||
"success": False,
|
||||
@ -34,8 +25,8 @@ class Config(APIView):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if 'data' in request.data:
|
||||
# TODO: do save data to config
|
||||
print(request.data['data'])
|
||||
write_yaml(request.data['data'])
|
||||
return Response({"success": True})
|
||||
|
||||
return Response({"success": False})
|
||||
|
||||
|
@ -44,7 +44,8 @@
|
||||
v-else-if="Array.isArray(prop)"
|
||||
v-model="config[key][name]"
|
||||
input-id="tags-basic"
|
||||
placeholder="add item..."
|
||||
separator=" ,;"
|
||||
:placeholder="`add ${name}...`"
|
||||
class="mb-2"
|
||||
/>
|
||||
<b-form-input v-else :id="name" v-model="config[key][name]" :value="prop" />
|
||||
@ -80,8 +81,9 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
onSubmit (evt) {
|
||||
async onSubmit (evt) {
|
||||
evt.preventDefault()
|
||||
await this.$store.dispatch('auth/inspectToken')
|
||||
this.$store.dispatch('config/setConfig', this.config)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user