Many changes

Rewrote file write/read process
Frontend and backend now respects the root setting
Fixed some form bugs
This commit is contained in:
aunefyren 2022-12-03 13:06:48 +01:00
parent fc9c889ac4
commit 266c51556e
14 changed files with 206 additions and 168 deletions

View file

@ -60,17 +60,17 @@ func GetAdminConfig() (*models.AdminConfig, error) {
}
// Load config file for alterations, information
file, err := os.Open(admin_config_path)
file, err := ioutil.ReadFile(admin_config_path)
if err != nil {
log.Println("Admin config opening threw error.")
log.Println("Admin config opening threw error. Error: " + err.Error())
return nil, err
}
defer file.Close()
decoder := json.NewDecoder(file)
admin_config := models.AdminConfig{}
err = decoder.Decode(&admin_config)
err = json.Unmarshal(file, &admin_config)
if err != nil {
log.Println("Admin config parsing threw error.")
log.Println("Admin config parsing threw error. Error: " + err.Error())
return nil, err
}

View file

@ -5,6 +5,7 @@ import (
"aunefyren/wrapperr/utilities"
"encoding/json"
"errors"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -20,7 +21,7 @@ func SaveCache(cache *[]models.WrapperrDay) error {
return err
}
err = os.WriteFile(cache_path, file, 0644)
err = ioutil.WriteFile(cache_path, file, 0644)
if err != nil {
return err
}
@ -70,15 +71,16 @@ func GetCache() ([]models.WrapperrDay, error) {
}
}
// Load cache file for alterations, information
// Define cache
var cache []models.WrapperrDay
file, err := os.Open(cache_path)
// Load cache file
file, err := ioutil.ReadFile(cache_path)
if err != nil {
return nil, err
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(&cache)
err = json.Unmarshal(file, &cache)
if err != nil {
return nil, err
}

View file

@ -4,6 +4,7 @@ import (
"aunefyren/wrapperr/models"
"encoding/json"
"errors"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -104,7 +105,7 @@ func SaveConfig(config *models.WrapperrConfig) error {
return err
}
err = os.WriteFile(config_path, file, 0644)
err = ioutil.WriteFile(config_path, file, 0644)
if err != nil {
return err
}
@ -124,6 +125,8 @@ func CreateConfigFile() error {
var tautulli_config = models.TautulliConfig{
TautulliGrouping: true,
TautulliPort: 80,
TautulliLength: 5000,
}
config.TautulliConfig = append(config.TautulliConfig, tautulli_config)
@ -163,32 +166,29 @@ func GetConfig() (*models.WrapperrConfig, error) {
}
// Load config file
file, err := os.Open(config_path)
file, err := ioutil.ReadFile(config_path)
if err != nil {
log.Println("Get config file threw error trying to open the file.")
return nil, err
}
defer file.Close()
// Parse config file
decoder := json.NewDecoder(file)
config := models.WrapperrConfig{}
err = decoder.Decode(&config)
err = json.Unmarshal(file, &config)
if err != nil {
return nil, err
}
if err != nil {
// Parse config file
log.Println("Failed to parse config file. Trying legacy format. Error: " + err.Error())
// Load config file
file, err := os.Open(config_path)
file, err = ioutil.ReadFile(config_path)
if err != nil {
log.Println("Get config file threw error trying to open the file.")
return nil, err
log.Fatal("Error when opening file: ", err)
}
defer file.Close()
decoder := json.NewDecoder(file)
config_legacy := models.WrapperrConfigLegacy{}
err = decoder.Decode(&config_legacy)
err = json.Unmarshal(file, &config)
convert_failed := false
@ -213,6 +213,8 @@ func GetConfig() (*models.WrapperrConfig, error) {
// if nothing worked, replace config file
if convert_failed {
log.Println("Get config file threw error trying to open the template file.")
// Backup old config
new_save_loc, err := BackUpConfig(config_path)
if err != nil {
@ -223,17 +225,15 @@ func GetConfig() (*models.WrapperrConfig, error) {
}
// Load default config file
file, err = os.Open(default_config_path)
file, err := ioutil.ReadFile(default_config_path)
if err != nil {
log.Println("Get config file threw error trying to open the template file.")
return nil, err
}
defer file.Close()
// Parse default config file
decoder = json.NewDecoder(file)
config = models.WrapperrConfig{}
err = decoder.Decode(&config)
err = json.Unmarshal(file, &config)
if err != nil {
log.Println("Get config file threw error trying to parse the template file.")
return nil, err
@ -243,17 +243,15 @@ func GetConfig() (*models.WrapperrConfig, error) {
}
// Load default config file
file, err = os.Open(default_config_path)
file, err = ioutil.ReadFile(default_config_path)
if err != nil {
log.Println("Get config file threw error trying to open the template file.")
return nil, err
}
defer file.Close()
// Parse default config file
decoder = json.NewDecoder(file)
config_default := models.WrapperrConfig{}
err = decoder.Decode(&config_default)
err = json.Unmarshal(file, &config_default)
if err != nil {
log.Println("Get config file threw error trying to parse the template file.")
return nil, err
@ -294,7 +292,10 @@ func GetConfig() (*models.WrapperrConfig, error) {
config.WrappedEnd = config_default.WrappedEnd // If no start time, set to 31 Dec
}
if config.TautulliConfig == nil {
if config.TautulliConfig == nil || len(config.TautulliConfig) == 0 {
log.Println("Tautulli server array is empty, adding a new one.")
config.TautulliConfig = []models.TautulliConfig{}
NewTautulliConfig := models.TautulliConfig{
@ -307,14 +308,82 @@ func GetConfig() (*models.WrapperrConfig, error) {
// Set Tautulli length to 5000 if zero is set
if config.TautulliConfig[0].TautulliLength == 0 {
log.Println("Tautulli item length on server number 1 is 0, replacing with 5000.")
config.TautulliConfig[0].TautulliLength = config_default.TautulliConfig[0].TautulliLength
}
// Set Tautulli port to 80 if zero is set
if config.TautulliConfig[0].TautulliPort == 0 {
log.Println("Tautulli port on server number 1 is 0, replacing with 80.")
config.TautulliConfig[0].TautulliPort = config_default.TautulliConfig[0].TautulliPort
}
config, err = VerifyNonEmptyCustomValues(config, config_default)
if err != nil {
return nil, err
}
// Save new version of config json
err = SaveConfig(&config)
if err != nil {
return nil, err
}
// Return config object
return &config, nil
}
func BackUpConfig(ConfigPath string) (string, error) {
new_save_loc := ConfigPath + "." + uuid.NewString() + ".replaced"
err := os.Rename(config_path, new_save_loc)
if err != nil {
return "", err
}
return new_save_loc, nil
}
func ConvertLegacyToCurrentConfig(config models.WrapperrConfig, config_legacy models.WrapperrConfigLegacy) (models.WrapperrConfig, error) {
var NewTautulli models.TautulliConfig
NewTautulli.TautulliApiKey = config_legacy.TautulliConfig.TautulliApiKey
NewTautulli.TautulliIP = config_legacy.TautulliConfig.TautulliIP
NewTautulli.TautulliLibraries = config_legacy.TautulliConfig.TautulliLibraries
NewTautulli.TautulliRoot = config_legacy.TautulliConfig.TautulliRoot
NewTautulli.TautulliGrouping = config_legacy.TautulliConfig.TautulliGrouping
NewTautulli.TautulliHttps = config_legacy.TautulliConfig.TautulliHttps
NewTautulli.TautulliLength = config_legacy.TautulliConfig.TautulliLength
NewTautulli.TautulliPort = config_legacy.TautulliConfig.TautulliPort
NewTautulli.TautulliName = "Server 1"
config.TautulliConfig = append(config.TautulliConfig, NewTautulli)
config.WrapperrCustomize = config_legacy.WrapperrCustomize
config.WrapperrVersion = config_legacy.WrapperrVersion
config.Timezone = config_legacy.Timezone
config.ApplicationName = config_legacy.ApplicationName
config.ApplicationURL = config_legacy.ApplicationURL
config.UseCache = config_legacy.UseCache
config.UseLogs = config_legacy.UseLogs
config.ClientKey = config_legacy.ClientKey
config.WrapperrRoot = config_legacy.WrapperrRoot
config.PrivateKey = config_legacy.PrivateKey
config.CreateShareLinks = config_legacy.CreateShareLinks
config.WrappedStart = config_legacy.WrappedStart
config.WrappedEnd = config_legacy.WrappedEnd
config.WrapperrPort = config_legacy.WrapperrPort
config.PlexAuth = config_legacy.PlexAuth
config.WinterTheme = config_legacy.WinterTheme
log.Println("Config migrated.")
return config, nil
}
// verify values and replace empty ones
func VerifyNonEmptyCustomValues(config models.WrapperrConfig, config_default models.WrapperrConfig) (models.WrapperrConfig, error) {
if config.WrapperrCustomize.StatsTopListLength < 0 {
config.WrapperrCustomize.StatsTopListLength = config_default.WrapperrCustomize.StatsTopListLength
}
@ -663,60 +732,6 @@ func GetConfig() (*models.WrapperrConfig, error) {
config.WrapperrCustomize.WrapperrSortDuration = config_default.WrapperrCustomize.WrapperrSortDuration
}
// Save new version of config json
err = SaveConfig(&config)
if err != nil {
return nil, err
}
// Return config object
return &config, nil
}
func BackUpConfig(ConfigPath string) (string, error) {
new_save_loc := ConfigPath + "." + uuid.NewString() + ".replaced"
err := os.Rename(config_path, new_save_loc)
if err != nil {
return "", err
}
return new_save_loc, nil
}
func ConvertLegacyToCurrentConfig(config models.WrapperrConfig, config_legacy models.WrapperrConfigLegacy) (models.WrapperrConfig, error) {
var NewTautulli models.TautulliConfig
NewTautulli.TautulliApiKey = config_legacy.TautulliConfig.TautulliApiKey
NewTautulli.TautulliIP = config_legacy.TautulliConfig.TautulliIP
NewTautulli.TautulliLibraries = config_legacy.TautulliConfig.TautulliLibraries
NewTautulli.TautulliRoot = config_legacy.TautulliConfig.TautulliRoot
NewTautulli.TautulliGrouping = config_legacy.TautulliConfig.TautulliGrouping
NewTautulli.TautulliHttps = config_legacy.TautulliConfig.TautulliHttps
NewTautulli.TautulliLength = config_legacy.TautulliConfig.TautulliLength
NewTautulli.TautulliPort = config_legacy.TautulliConfig.TautulliPort
NewTautulli.TautulliName = "Server 1"
config.TautulliConfig = append(config.TautulliConfig, NewTautulli)
config.WrapperrCustomize = config_legacy.WrapperrCustomize
config.WrapperrVersion = config_legacy.WrapperrVersion
config.Timezone = config_legacy.Timezone
config.ApplicationName = config_legacy.ApplicationName
config.ApplicationURL = config_legacy.ApplicationURL
config.UseCache = config_legacy.UseCache
config.UseLogs = config_legacy.UseLogs
config.ClientKey = config_legacy.ClientKey
config.WrapperrRoot = config_legacy.WrapperrRoot
config.PrivateKey = config_legacy.PrivateKey
config.CreateShareLinks = config_legacy.CreateShareLinks
config.WrappedStart = config_legacy.WrappedStart
config.WrappedEnd = config_legacy.WrappedEnd
config.WrapperrPort = config_legacy.WrapperrPort
config.PlexAuth = config_legacy.PlexAuth
config.WinterTheme = config_legacy.WinterTheme
log.Println("Config migrated.")
return config, nil
}

View file

@ -4,6 +4,7 @@ import (
"aunefyren/wrapperr/models"
"encoding/json"
"errors"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -28,7 +29,7 @@ func SaveLink(link_object *models.WrapperrShareLink) error {
var link_object_path, _ = filepath.Abs(link_path + "/" + strconv.Itoa(link_object.UserID) + ".json")
err = os.WriteFile(link_object_path, file, 0644)
err = ioutil.WriteFile(link_object_path, file, 0644)
if err != nil {
return err
}
@ -83,14 +84,12 @@ func GetLink(UserID string) (*models.WrapperrShareLink, error) {
return nil, errors.New("Invalid share link.")
}
file, err := os.Open(share_link_path)
file, err := ioutil.ReadFile(share_link_path)
if err != nil {
return nil, err
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(&link_object)
err = json.Unmarshal(file, &link_object)
if err != nil {
return nil, err
}

49
main.go
View file

@ -89,36 +89,43 @@ func main() {
// Assign routes
router := mux.NewRouter().StrictSlash(true)
var root string
if config.WrapperrRoot != "" {
root = "/" + config.WrapperrRoot
} else {
root = ""
}
// Admin auth routes
router.HandleFunc("/api/validate/admin", routes.ApiValidateAdmin)
router.HandleFunc("/api/get/config", routes.ApiGetConfig)
router.HandleFunc("/api/get/log", routes.ApiGetLog)
router.HandleFunc("/api/set/config", routes.ApiSetConfig)
router.HandleFunc("/api/update/admin", routes.ApiUpdateAdmin)
router.HandleFunc(root+"/api/validate/admin", routes.ApiValidateAdmin)
router.HandleFunc(root+"/api/get/config", routes.ApiGetConfig)
router.HandleFunc(root+"/api/get/log", routes.ApiGetLog)
router.HandleFunc(root+"/api/set/config", routes.ApiSetConfig)
router.HandleFunc(root+"/api/update/admin", routes.ApiUpdateAdmin)
// No-auth routes
router.HandleFunc("/api/get/config-state", routes.ApiWrapperrConfigured)
router.HandleFunc("/api/login/admin", routes.ApiLogInAdmin)
router.HandleFunc("/api/get/wrapperr-version", routes.ApiGetWrapperrVersion)
router.HandleFunc("/api/get/admin-state", routes.ApiGetAdminState)
router.HandleFunc("/api/get/functions", routes.ApiGetFunctions)
router.HandleFunc("/api/create/admin", routes.ApiCreateAdmin)
router.HandleFunc("/api/get/tautulli-connection", routes.ApiGetTautulliConncection)
router.HandleFunc("/api/get/share-link", routes.ApiGetShareLink)
router.HandleFunc(root+"/api/get/config-state", routes.ApiWrapperrConfigured)
router.HandleFunc(root+"/api/login/admin", routes.ApiLogInAdmin)
router.HandleFunc(root+"/api/get/wrapperr-version", routes.ApiGetWrapperrVersion)
router.HandleFunc(root+"/api/get/admin-state", routes.ApiGetAdminState)
router.HandleFunc(root+"/api/get/functions", routes.ApiGetFunctions)
router.HandleFunc(root+"/api/create/admin", routes.ApiCreateAdmin)
router.HandleFunc(root+"/api/get/tautulli-connection", routes.ApiGetTautulliConncection)
router.HandleFunc(root+"/api/get/share-link", routes.ApiGetShareLink)
// User auth routes
router.HandleFunc("/api/get/login-url", routes.ApiGetLoginURL)
router.HandleFunc("/api/login/plex-auth", routes.ApiLoginPlexAuth)
router.HandleFunc("/api/validate/plex-auth", routes.ApiValidatePlexAuth)
router.HandleFunc("/api/create/share-link", routes.ApiCreateShareLink)
router.HandleFunc("/api/get/user-share-link", routes.ApiGetUserShareLink)
router.HandleFunc("/api/delete/user-share-link", routes.ApiDeleteUserShareLink)
router.HandleFunc(root+"/api/get/login-url", routes.ApiGetLoginURL)
router.HandleFunc(root+"/api/login/plex-auth", routes.ApiLoginPlexAuth)
router.HandleFunc(root+"/api/validate/plex-auth", routes.ApiValidatePlexAuth)
router.HandleFunc(root+"/api/create/share-link", routes.ApiCreateShareLink)
router.HandleFunc(root+"/api/get/user-share-link", routes.ApiGetUserShareLink)
router.HandleFunc(root+"/api/delete/user-share-link", routes.ApiDeleteUserShareLink)
// Get stats route
router.HandleFunc("/api/get/statistics", routes.ApiWrapperGetStatistics)
router.HandleFunc(root+"/api/get/statistics", routes.ApiWrapperGetStatistics)
// Static routes
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/")))
router.PathPrefix(root).Handler(http.StripPrefix(root, http.FileServer(http.Dir("./web/"))))
// Start web-server
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), router))

View file

@ -209,6 +209,7 @@ type WrapperrVersion struct {
PlexAuth bool `json:"plex_auth"`
WrapperrFrontPageTitle string `json:"wrapperr_front_page_title"`
WrapperrFrontPageSubtitle string `json:"wrapperr_front_page_subtitle"`
WrapperrRoot string `json:"wrapperr_root"`
ClientKey string `json:"client_key"`
WrapperrConfigured bool `json:"wrapperr_configured"`
WinterTheme bool `json:"winter_theme"`

View file

@ -71,6 +71,8 @@ func ApiSetConfig(w http.ResponseWriter, r *http.Request) {
utilities.RespondDefaultError(w, r, errors.New("Failed to retrieve Wrapperr configuration."), 500)
} else {
original_root := config.WrapperrRoot
// Read payload from Post input
reqBody, err := ioutil.ReadAll(r.Body)
if err != nil {
@ -145,19 +147,17 @@ func ApiSetConfig(w http.ResponseWriter, r *http.Request) {
return
}
if config_payload.ClearCache {
log.Println("New Wrapperr configuration saved for type: " + config_payload.DataType + ".")
utilities.RespondDefaultOkay(w, r, "Saved new Wrapperr config.")
log.Println("Clear cache setting set to true. Clearing cache.")
err = files.ClearCache()
if config.WrapperrRoot != original_root {
log.Println("Root changed, attempting Wrapperr restart.")
err = utilities.RestartSelf()
if err != nil {
log.Println("Failed to clear cache:")
log.Println(err)
log.Println("Failed to restart. Error: " + err.Error())
}
}
log.Println("New Wrapperr configuration saved for type: " + config_payload.DataType + ".")
utilities.RespondDefaultOkay(w, r, "Saved new Wrapperr config.")
return
}

View file

@ -48,6 +48,7 @@ func ApiGetWrapperrVersion(w http.ResponseWriter, r *http.Request) {
WinterTheme: config.WinterTheme,
Message: "Retrieved Wrapperr version.",
Error: false,
WrapperrRoot: config.WrapperrRoot,
}
ip_string := utilities.GetOriginIPString(w, r)

View file

@ -72,7 +72,7 @@ function log_in() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/login/admin");
xhttp.open("post", api_url + "login/admin");
xhttp.send(admin_login_data);
return;
}
@ -159,7 +159,7 @@ function set_password() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/create/admin");
xhttp.open("post", api_url + "create/admin");
xhttp.send(admin_create_data);
return;
}
@ -255,7 +255,7 @@ function update_password() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/update/admin");
xhttp.open("post", api_url + "update/admin");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(admin_create_data);
@ -290,7 +290,7 @@ function get_admin_state() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "../api/get_admin_state.php");
xhttp.open("post", api_url + "get_admin_state.php");
xhttp.send();
return;
}
@ -673,7 +673,7 @@ function set_tautulli_settings_call() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/set/config");
xhttp.open("post", api_url + "set/config");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(tautulli_settings_data);
@ -852,24 +852,24 @@ function set_wrapperr_settings_call() {
}
if(wrapped_end < wrapped_start) {
document.getElementById("set_wrapperr_customization_form_button").disabled = false;
document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1';
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert('The wrapped end period must be later than the wrapped start period.');
document.getElementById('wrapped_end').focus();
return;
}
if(wrapped_end === '') {
document.getElementById("set_wrapperr_customization_form_button").disabled = false;
document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1';
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert('Ending of wrapped period is required for Wrapperr to function.');
document.getElementById('wrapped_end').focus();
return;
}
if(wrapped_start === '') {
document.getElementById("set_wrapperr_customization_form_button").disabled = false;
document.getElementById("set_wrapperr_customization_form_button").style.opacity = '1';
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert('Start of wrapped period is required for Wrapperr to function.');
document.getElementById('wrapped_start').focus();
return;
@ -878,7 +878,7 @@ function set_wrapperr_settings_call() {
wrapperr_settings_form = {
"clear_cache" : clear_cache,
"data_type" : "wrapperr_data",
"tautulli_config" : {},
"tautulli_config" : [],
"wrapperr_customize" : {},
"wrapperr_data" : {
"use_cache" : use_cache,
@ -922,7 +922,7 @@ function set_wrapperr_settings_call() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/set/config");
xhttp.open("post", api_url + "set/config");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(wrapperr_settings_data);
@ -1907,7 +1907,7 @@ function set_wrapperr_customization_call() {
wrapperr_customization_form = {
"clear_cache" : clear_cache,
"data_type" : "wrapperr_customize",
"tautulli_config" : {},
"tautulli_config" : [],
"wrapperr_data" : {},
"wrapperr_customize" : {
"wrapperr_front_page_title" : wrapperr_front_page_title,
@ -2040,7 +2040,7 @@ function set_wrapperr_customization_call() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/set/config");
xhttp.open("post", api_url + "set/config");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(wrapperr_customization_data);
@ -2237,7 +2237,7 @@ function get_stats(days) {
};
xhttp.withCredentials = true;
xhttp.open("post", root + "api/get/statistics", );
xhttp.open("post", api_url + "get/statistics", );
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(stats_data);
@ -2327,7 +2327,7 @@ function get_log() {
};
xhttp.withCredentials = true;
xhttp.open("post", root + "api/get/log", );
xhttp.open("post", api_url + "get/log", );
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(log_data_data);
@ -2413,7 +2413,7 @@ function test_tautulli_connection(tautulli_id) {
}
};
xhttp.withCredentials = true;
xhttp.open("post", root + 'api/get/tautulli-connection');
xhttp.open("post", api_url + 'get/tautulli-connection');
xhttp.send(config_data);
}
@ -2437,6 +2437,13 @@ function get_wrapper_version() {
document.getElementById('application_name').innerHTML = result.application_name + ' Setup';
document.title = result.application_name;
}
if(result.wrapperr_root != "") {
api_url = window.location.origin + "/" + result.wrapperr_root + "/api/";
console.log("URL: " + api_url)
}
get_admin_state();
}
} else if(this.readyState == 4 && this.status !== 200) {
@ -2446,7 +2453,10 @@ function get_wrapper_version() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/get/wrapperr-version");
root = window.location.pathname.replace('/admin', '')
xhttp.open("post", window.location.origin + "/" + root + "api/get/wrapperr-version");
xhttp.send();
return;
}
@ -2482,7 +2492,7 @@ function get_admin_state() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/get/admin-state");
xhttp.open("post", api_url + "get/admin-state");
xhttp.send();
return;
}
@ -2510,7 +2520,7 @@ function validate_cookie_admin(cookie) {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/validate/admin");
xhttp.open("post", api_url + "validate/admin");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send();
@ -2666,7 +2676,7 @@ function get_config(cookie) {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/get/config");
xhttp.open("post", api_url + "get/config");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send();

View file

@ -46,7 +46,7 @@
<script type="text/javascript">
var root = "../";
var api_url = window.location.origin + "/api/";
var first_time = false;
@ -177,8 +177,6 @@ $(document).ready(function() {
get_wrapper_version();
get_admin_state();
});
</script>

View file

@ -25,6 +25,6 @@ function get_functions() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", root + "api/get/functions");
xhttp.open("post", api_url + "get/functions");
xhttp.send(config_data);
}

View file

@ -51,7 +51,7 @@ function get_stats() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get/statistics");
xhttp.open("post", api_url + "get/statistics");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(stats_data);
@ -1057,7 +1057,7 @@ function create_wrapped_link() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/create/share-link");
xhttp.open("post", api_url + "create/share-link");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(wrapped_data);
@ -1128,7 +1128,7 @@ function delete_new_link_user() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/delete/user-share-link");
xhttp.open("post", api_url + "delete/user-share-link");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(cookie_data);

View file

@ -8,8 +8,8 @@
<title>Wrapperr</title>
<!-- Bootstrap 4 CSS and custom CSS -->
<link rel="stylesheet" type="text/css" href="assets/css/wrapped.css" />
<link rel="shortcut icon" href="assets/img/favicons/favicon.ico" />
<link rel="stylesheet" type="text/css" href="./assets/css/wrapped.css" />
<link rel="shortcut icon" href="./assets/img/favicons/favicon.ico" />
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="./functions.js"></script>
@ -21,7 +21,7 @@
<body id='body'>
<div id="loading">
<img id="loading-image" style="border-radius: 25px; background-color: var(--white); padding: 1em;width: 4em; height: 4em;" src="assets/loading.gif" alt="Loading..." />
<img id="loading-image" style="border-radius: 25px; background-color: var(--white); padding: 1em;width: 4em; height: 4em;" src="./assets/loading.gif" alt="Loading..." />
<div class="form-group" id=''>
<div id="results_error_loading_screen" style="color: var(--white) !important;">Loading...</div>
@ -72,7 +72,7 @@
<div class="boks3" id="" style="padding: 0 !important;">
<div class="boks2" style="float: none !important; display: block; padding: 0; margin: 1em 0 0 0;">
<img src="assets/img/gift.svg" onclick="window.location.href = './';" style="width: 12.5em; cursor: pointer;">
<img src="./assets/img/gift.svg" onclick="window.location.href = './';" style="width: 12.5em; cursor: pointer;">
</div>
</div>
@ -103,7 +103,7 @@
<div class="form-group" id='plex_login_div'>
<button class='form-control btn' name="plex_login_button" id="plex_login_button" onclick='pop_up_login(); return false;' style='opacity: 0.5;' disabled>
<img src='assets/external-link.svg' class='btn_logo'>
<img src='./assets/external-link.svg' class='btn_logo'>
<p2 id='plex_login_button_text'>Sign in using Plex</p2>
</button>
</div>
@ -114,14 +114,14 @@
<div class="form-group" id='search_wrapped_div'>
<button class='form-control btn' name="search_wrapped_button" id="search_wrapped_button" style='opacity: 0.5;' onclick='search_wrapperr()' disabled>
<img src='assets/done.svg' class='btn_logo'>
<img src='./assets/done.svg' class='btn_logo'>
<p2 id='search_wrapped_button_text'>Unwrap</p2>
</button>
</div>
<div class="form-group" id='sign_out_div' style='display: none;'>
<button class='form-control btn' name="plex_signout_button" id="plex_signout_button" onclick='sign_out()'>
<img src='assets/close.svg' class='btn_logo'>
<img src='./assets/close.svg' class='btn_logo'>
<p2 id='plex_signout_button_text'>Sign Out</p2>
</button>
</div>
@ -131,7 +131,7 @@
</div>
<img id="loading_icon" src="assets/loading.gif" style="border-radius: 25px; background-color: var(--white); padding: 1em;width: 4em; height: 4em; display:none; margin: 1em 0 0 0;">
<img id="loading_icon" src="./assets/loading.gif" style="border-radius: 25px; background-color: var(--white); padding: 1em;width: 4em; height: 4em; display:none; margin: 1em 0 0 0;">
<div id="results">
</div>
@ -156,8 +156,8 @@
'>
<div class='form-control btn' id="share_wrapped_delete_button" style='background-color: var(--white); cursor: default;'>
<span id='share_wrapped_url' class='share_wrapped_url' style=''></span>
<img id='share_wrapped_copy' src='assets/external-link.svg' style='' onclick='open_link_user();'>
<img id='share_wrapped_delete' src='assets/trash.svg' style='' onclick='delete_link_user();'>
<img id='share_wrapped_copy' src='./assets/external-link.svg' style='' onclick='open_link_user();'>
<img id='share_wrapped_delete' src='./assets/trash.svg' style='' onclick='delete_link_user();'>
</div>
</div>
@ -218,7 +218,6 @@
<script type="text/javascript">
// Initialize variables for global reference
var root = "./";
var link_mode = false;
var results;
var functions;
@ -226,6 +225,7 @@
var cookie = false;
var client_key = "";
var wrapperr_configured = false;
var api_url = window.location.origin + "/api/";
var url = "";
var code = 0;
@ -259,7 +259,7 @@
link_mode = true;
wrapped_link_actions(hash);
document.getElementById('intro_text').innerHTML = '';
document.getElementById('stats').innerHTML = '<img id="loading_icon" src="assets/loading.gif" style="border-radius: 25px; background-color: white; padding: 1em;width: 4em; height: 4em; display:block; margin: auto;">';
document.getElementById('stats').innerHTML = '<img id="loading_icon" src="./assets/loading.gif" style="border-radius: 25px; background-color: white; padding: 1em;width: 4em; height: 4em; display:block; margin: auto;">';
}
// Contact the Wrapperr API to get configuration details

View file

@ -44,7 +44,7 @@ function wrapped_link_actions(hash) {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get/share-link");
xhttp.open("post", api_url + "get/share-link");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(hash_data);
@ -203,7 +203,7 @@ function check_token(code, id) {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/login/plex-auth");
xhttp.open("post", api_url + "login/plex-auth");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.send(auth_data);
@ -247,7 +247,7 @@ function validate_cookie_user(cookie) {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "/api/validate/plex-auth");
xhttp.open("post", api_url + "validate/plex-auth");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send();
@ -343,6 +343,11 @@ function get_wrapper_version() {
// Set the 'configured' option in the JS variable
wrapperr_configured = result.wrapperr_configured;
if(result.wrapperr_root != "") {
api_url = window.location.origin + "/" + result.wrapperr_root + "/api/";
console.log("URL: " + api_url)
}
// Change search function to use Plex search instead
if(!result.plex_auth) {
wrapperr_search_function();
@ -367,7 +372,7 @@ function get_wrapper_version() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/get/wrapperr-version");
xhttp.open("post", window.location + "api/get/wrapperr-version");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.send();
return;
@ -407,7 +412,7 @@ function delete_link_user() {
}
};
xhttp.withCredentials = true;
xhttp.open("post", "api/delete/user-share-link");
xhttp.open("post", api_url + "delete/user-share-link");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", "Bearer " + cookie);
xhttp.send(cookie_data);