fix(api): dashboard restarts api

darta 2022-01-18 19:16:24 +01:00
parent 8b4054fef5
commit d39bb23829
8 changed files with 80 additions and 29 deletions

View File

@ -4,7 +4,7 @@ from pprint import pprint
import os, shutil import os, shutil
from requests import get, post import requests
from schema import And, Optional, Schema, SchemaError, Use from schema import And, Optional, Schema, SchemaError, Use
import yaml import yaml
@ -83,6 +83,7 @@ class Dashboard:
return self.apply_updates() return self.apply_updates()
def apply_updates(self): def apply_updates(self):
# Keycloak resp = requests.get(
# Api "http://isard-sso-api:7039/restart"
)
return True return True

View File

@ -35,11 +35,11 @@ $(document).ready(function() {
init_background_cropper() init_background_cropper()
$('#save-colors').click(function () { $('#save-colors').click(function () {
console.log({ // console.log({
'background': $('#colorpicker-background-input').val(), // 'background': $('#colorpicker-background-input').val(),
'primary': $('#colorpicker-primary-input').val(), // 'primary': $('#colorpicker-primary-input').val(),
'secondary': $('#colorpicker-secondary-input').val() // 'secondary': $('#colorpicker-secondary-input').val()
}) // })
$.ajax({ $.ajax({
type: "PUT", type: "PUT",
url:"/api/dashboard/colours", url:"/api/dashboard/colours",
@ -104,7 +104,7 @@ function init_logo_cropper() {
if (typeof ($.fn.cropper) === 'undefined') { return; } if (typeof ($.fn.cropper) === 'undefined') { return; }
console.log('init_logo_cropper'); // console.log('init_logo_cropper');
var $image = $('#image_logo'); var $image = $('#image_logo');
var $dataX = $('#dataX'); var $dataX = $('#dataX');
@ -139,25 +139,25 @@ function init_logo_cropper() {
// Cropper // Cropper
$image.on({ $image.on({
'build.cropper': function (e) { 'build.cropper': function (e) {
console.log(e.type); // console.log(e.type);
}, },
'built.cropper': function (e) { 'built.cropper': function (e) {
console.log(e.type); // console.log(e.type);
}, },
'cropstart.cropper': function (e) { 'cropstart.cropper': function (e) {
console.log(e.type, e.action); // console.log(e.type, e.action);
}, },
'cropmove.cropper': function (e) { 'cropmove.cropper': function (e) {
console.log(e.type, e.action); // console.log(e.type, e.action);
}, },
'cropend.cropper': function (e) { 'cropend.cropper': function (e) {
console.log(e.type, e.action); // console.log(e.type, e.action);
}, },
'crop.cropper': function (e) { 'crop.cropper': function (e) {
console.log(e.type, e.x, e.y, e.width, e.height, e.rotate, e.scaleX, e.scaleY); // console.log(e.type, e.x, e.y, e.width, e.height, e.rotate, e.scaleX, e.scaleY);
}, },
'zoom.cropper': function (e) { 'zoom.cropper': function (e) {
console.log(e.type, e.ratio); // console.log(e.type, e.ratio);
} }
}).cropper(options); }).cropper(options);
@ -277,7 +277,7 @@ function init_background_cropper() {
if (typeof ($.fn.cropper) === 'undefined') { return; } if (typeof ($.fn.cropper) === 'undefined') { return; }
console.log('init_background_cropper'); // console.log('init_background_cropper');
var $image = $('#image_background'); var $image = $('#image_background');
var $dataX = $('#dataX'); var $dataX = $('#dataX');
@ -312,25 +312,25 @@ function init_background_cropper() {
// Cropper // Cropper
$image.on({ $image.on({
'build.cropper': function (e) { 'build.cropper': function (e) {
console.log(e.type); // console.log(e.type);
}, },
'built.cropper': function (e) { 'built.cropper': function (e) {
console.log(e.type); // console.log(e.type);
}, },
'cropstart.cropper': function (e) { 'cropstart.cropper': function (e) {
console.log(e.type, e.action); // console.log(e.type, e.action);
}, },
'cropmove.cropper': function (e) { 'cropmove.cropper': function (e) {
console.log(e.type, e.action); // console.log(e.type, e.action);
}, },
'cropend.cropper': function (e) { 'cropend.cropper': function (e) {
console.log(e.type, e.action); // console.log(e.type, e.action);
}, },
'crop.cropper': function (e) { 'crop.cropper': function (e) {
console.log(e.type, e.x, e.y, e.width, e.height, e.rotate, e.scaleX, e.scaleY); // console.log(e.type, e.x, e.y, e.width, e.height, e.rotate, e.scaleX, e.scaleY);
}, },
'zoom.cropper': function (e) { 'zoom.cropper': function (e) {
console.log(e.type, e.ratio); // console.log(e.type, e.ratio);
} }
}).cropper(options); }).cropper(options);
@ -350,10 +350,10 @@ function init_background_cropper() {
contentType: false, contentType: false,
success: function () { success: function () {
// Update background image // Update background image
console.log('Upload success'); // console.log('Upload success');
}, },
error: function () { error: function () {
console.log('Upload error'); // console.log('Upload error');
} }
}); });
}); });

View File

@ -473,7 +473,7 @@ def check_upload_errors(data):
} }
log.error(resp) log.error(resp)
return resp return resp
return {"pass": True, "msg":""} return {"pass": True, "msg": ""}
@app.route("/api/dashboard/<item>", methods=["PUT"]) @app.route("/api/dashboard/<item>", methods=["PUT"])

View File

@ -20,6 +20,13 @@ server {
access_log off; access_log off;
} }
location /restart {
proxy_pass http://127.0.0.1:7039/restart;
expires max;
log_not_found off;
access_log off;
}
location /user_menu/json { location /user_menu/json {
alias /api/api/static/templates/user_menu_header.json; alias /api/api/static/templates/user_menu_header.json;
default_type application/json; default_type application/json;

View File

@ -50,4 +50,4 @@ def send_templates(path):
""" """
Import all views Import all views
""" """
from .views import AvatarsViews, MenuViews from .views import AvatarsViews, MenuViews, InternalViews

View File

@ -0,0 +1,23 @@
# coding=utf-8
import os
from flask import Response, jsonify, redirect, render_template, request, url_for
from .decorators import is_internal
from api import app
@app.route("/restart", methods=["GET"])
@is_internal
def api_restart():
os.system("kill 1")
# @app.route('/user_menu/<format>', methods=['GET'])
# @app.route('/user_menu/<format>/<application>', methods=['GET'])
# def api_v2_user_menu(format,application=False):
# if application == False:
# if format == 'json':
# if application == False:
# return json.dumps(menu.get_user_nenu()), 200, {'Content-Type': 'application/json'}

View File

@ -36,7 +36,6 @@ def api_v2_header(format, application=False):
if application == "wordpress": if application == "wordpress":
return render_template("header_wordpress.html") return render_template("header_wordpress.html")
# @app.route('/user_menu/<format>', methods=['GET']) # @app.route('/user_menu/<format>', methods=['GET'])
# @app.route('/user_menu/<format>/<application>', methods=['GET']) # @app.route('/user_menu/<format>/<application>', methods=['GET'])
# def api_v2_user_menu(format,application=False): # def api_v2_user_menu(format,application=False):

View File

@ -0,0 +1,21 @@
#!flask/bin/python
# coding=utf-8
import socket
from functools import wraps
from flask import redirect, request, url_for
def is_internal(fn):
@wraps(fn)
def decorated_view(*args, **kwargs):
remote_addr = (
request.headers["X-Forwarded-For"].split(",")[0]
if "X-Forwarded-For" in request.headers
else request.remote_addr.split(",")[0]
)
if socket.gethostbyname("isard-sso-admin") == remote_addr:
return fn(*args, **kwargs)
return ""
return decorated_view