From 42657fafa10f7dcd96cf4040d87fde365a440d73 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 17 Sep 2020 16:19:26 +0200 Subject: [PATCH] [MM-25656] Adds a function to allow to update assets subpath in a given directory (#15020) --- utils/subpath.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/subpath.go b/utils/subpath.go index 6bfccad5f3b..d294de2da52 100644 --- a/utils/subpath.go +++ b/utils/subpath.go @@ -45,14 +45,14 @@ func GetSubpathScriptHash(subpath string) string { return fmt.Sprintf(" 'sha256-%s'", base64.StdEncoding.EncodeToString(scriptHash[:])) } -// UpdateAssetsSubpath rewrites assets in the /client directory to assume the application is hosted -// at the given subpath instead of at the root. No changes are written unless necessary. -func UpdateAssetsSubpath(subpath string) error { +// UpdateAssetsSubpathInDir rewrites assets in the given directory to assume the application is +// hosted at the given subpath instead of at the root. No changes are written unless necessary. +func UpdateAssetsSubpathInDir(subpath, directory string) error { if subpath == "" { subpath = "/" } - staticDir, found := fileutils.FindDir(model.CLIENT_DIR) + staticDir, found := fileutils.FindDir(directory) if !found { return errors.New("failed to find client dir") } @@ -139,6 +139,12 @@ func UpdateAssetsSubpath(subpath string) error { return nil } +// UpdateAssetsSubpath rewrites assets in the /client directory to assume the application is hosted +// at the given subpath instead of at the root. No changes are written unless necessary. +func UpdateAssetsSubpath(subpath string) error { + return UpdateAssetsSubpathInDir(subpath, model.CLIENT_DIR) +} + // UpdateAssetsSubpathFromConfig uses UpdateAssetsSubpath and any path defined in the SiteURL. func UpdateAssetsSubpathFromConfig(config *model.Config) error { // Don't rewrite in development environments, since webpack in developer mode constantly