-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle embedded static directory properly and fix emotes directory
- Loading branch information
Showing
48 changed files
with
109 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,5 +45,5 @@ subscribers.json | |
/.settings/ | ||
/.project | ||
|
||
# test alt static folder | ||
testStatic | ||
# Emotes dir | ||
emotes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
package files | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
//go:embed static/*.html static/css static/img static/js | ||
var StaticFS embed.FS | ||
type ioFS struct { | ||
diskDir string | ||
replaceKey string | ||
fsys fs.FS | ||
} | ||
|
||
func (f ioFS) Open(name string) (fs.File, error) { | ||
diskPath := path.Join(f.diskDir, strings.TrimPrefix(name, f.replaceKey)) | ||
if file, err := os.Open(diskPath); err == nil { | ||
return file, nil | ||
} | ||
|
||
file, err := f.fsys.Open(name) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not find file on disk in %q or in embedded FS: %w", f.diskDir, err) | ||
} | ||
|
||
return file, nil | ||
} | ||
|
||
func FS(fsys fs.FS, diskDir, replaceKey string) (fs.FS, error) { | ||
if fsys == nil { | ||
return nil, fmt.Errorf("fsys is null") | ||
} | ||
|
||
if diskDir == "" { | ||
// replaceKey is cleared because there is no diskDir to replace with the base dir with | ||
replaceKey = "" | ||
diskDir = RunPath() | ||
} | ||
|
||
return ioFS{ | ||
diskDir: diskDir, | ||
replaceKey: replaceKey, | ||
fsys: fsys, | ||
}, nil | ||
} | ||
|
||
// Return the absolut directory containing the MovieNight binary | ||
func RunPath() string { | ||
ex, er := os.Executable() | ||
if er != nil { | ||
panic(er) | ||
} | ||
dir := filepath.ToSlash(filepath.Dir(ex)) | ||
return strings.TrimPrefix(dir, filepath.VolumeName(dir)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.