Skip to content

Commit 976e16a

Browse files
committed
Add ability to display alert banner on web
Introduces the ability to create a banner for users on the web, using the YEETFILE_BANNER environment variable. This banner appears for logged in users only, and can be permanently cleared by the user.
1 parent 9c48150 commit 976e16a

File tree

12 files changed

+75
-3
lines changed

12 files changed

+75
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ All environment variables can be defined in a file named `.env` at the root leve
349349
| YEETFILE_LOCKDOWN | Disables anonymous (not logged in) interactions | 0 | `1` to enable lockdown, `0` to allow anonymous usage |
350350
| YEETFILE_PROFILING | Enables server profiling on http://localhost:6060 | 0 | `1` to enable, `0` to disable (default) |
351351
| YEETFILE_ALLOW_INVITES | Allows the YeetFile instance admin to send unique invite codes to email addresses -- must also set `YEETFILE_SERVER_PASSWORD` and setup outgoing email (see [Misc Environment Variables](#misc-environment-variables)) | 0 | `1` to enable, `0` to disable (default) |
352+
| YEETFILE_BANNER | Can be set to a string value that will appear as an info bannner for any users logged in on the web. | | Any string |
352353

353354
#### Backblaze Environment Variables
354355

backend/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var (
5252
IsLockedDown = utils.GetEnvVarBool("YEETFILE_LOCKDOWN", false)
5353
InstanceAdmin = utils.GetEnvVar("YEETFILE_INSTANCE_ADMIN", "")
5454
InvitesAllowed = utils.GetEnvVarBool("YEETFILE_ALLOW_INVITES", false)
55+
Banner = utils.GetEnvVar("YEETFILE_BANNER", "")
5556
)
5657

5758
// =============================================================================

backend/server/html/handlers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func FileVaultPageHandler(w http.ResponseWriter, _ *http.Request, userID string)
4343
CSS: []string{"vault.css"},
4444
Config: config.HTMLConfig,
4545
Endpoints: endpoints.HTMLPageEndpoints,
46+
Banner: config.Banner,
4647
},
4748
StorageUsed: userStorage.StorageUsed,
4849
StorageAvailable: userStorage.StorageAvailable,
@@ -77,6 +78,7 @@ func PassVaultPageHandler(w http.ResponseWriter, _ *http.Request, userID string)
7778
CSS: []string{"vault.css"},
7879
Config: config.HTMLConfig,
7980
Endpoints: endpoints.HTMLPageEndpoints,
81+
Banner: config.Banner,
8082
},
8183
StorageUsed: int64(passCount),
8284
StorageAvailable: int64(maxPassCount),
@@ -123,6 +125,7 @@ func SendPageHandler(w http.ResponseWriter, req *http.Request, _ string) {
123125
CSS: []string{"send.css"},
124126
Config: config.HTMLConfig,
125127
Endpoints: endpoints.HTMLPageEndpoints,
128+
Banner: config.Banner,
126129
},
127130
SendUsed: sendUsed,
128131
SendAvailable: sendAvailable,
@@ -223,6 +226,7 @@ func AccountPageHandler(w http.ResponseWriter, req *http.Request, userID string)
223226
CSS: []string{"account.css"},
224227
Config: config.HTMLConfig,
225228
Endpoints: endpoints.HTMLPageEndpoints,
229+
Banner: config.Banner,
226230
},
227231
Email: obscuredEmail,
228232
EmailConfigured: config.YeetFileConfig.Email.Configured,

backend/server/html/templates/account.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ <h4 class="no-margin">YeetFile Send</h4>
161161
<p id="success-message"></p>
162162
</div>
163163
{{ end }}
164+
165+
{{ if .Base.LoggedIn }}
166+
{{ template "banner.html" . }}
167+
{{ end }}
164168
</div>
165169

166170
{{ template "two-factor-dialog.html" }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{ if .Base.Banner }}
2+
<div id="yeetfile-banner" class="banner">
3+
<span id="banner-string">{{ .Base.Banner }}</span>
4+
<br><br>
5+
<button id="close-banner">Close</button>
6+
</div>
7+
<script type="module" src="/static/js/{{ .Base.Config.Version }}/banner.js"></script>
8+
{{ end }}

backend/server/html/templates/send.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ <h1>Send</h1>
142142
<a href="{{ .Base.Endpoints.Upgrade }}">Upgrade</a>
143143
{{ end }}
144144
{{ end }}
145+
146+
{{ if .Base.LoggedIn }}
147+
{{ template "banner.html" . }}
148+
{{ end }}
145149
</div>
146150
{{ template "footer.html" . }}
147151
</body>

backend/server/html/templates/templates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type BaseTemplate struct {
4545
Version string
4646
Config config.TemplateConfig
4747
Endpoints endpoints.HTMLEndpoints
48+
Banner string
4849
}
4950

5051
type Template struct {

backend/server/html/templates/vault.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ <h1>{{ .VaultName }}</h1>
5151
<progress max="{{ .StorageAvailable }}" value="{{ .StorageUsed }}" id="storage-bar"></progress>
5252
<progress id="item-bar"></progress>
5353
<span id="vault-message"></span>
54+
55+
{{ if .Base.LoggedIn }}
56+
{{ template "banner.html" . }}
57+
{{ end }}
5458
</div>
5559

5660
{{ template "vault-password-dialog.html" false }}

backend/static/css/main.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ fieldset {
3131
border: 0 !important;
3232
}
3333

34+
.banner {
35+
display: none;
36+
background-color: var(--card-bg-color);
37+
padding: 10px;
38+
color: var(--text-color);
39+
border: 2px solid var(--accent-color) !important;
40+
z-index: 100;
41+
}
42+
43+
.banner button {
44+
display: block;
45+
margin: auto;
46+
}
47+
3448
.auto-width {
3549
width: auto !important;
3650
}

cli/commands/download/download.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"yeetfile/cli/utils"
1212
"yeetfile/shared"
1313
"yeetfile/shared/constants"
14+
"yeetfile/shared/endpoints"
1415
)
1516

1617
var decryptError = errors.New("decryption error")
@@ -34,7 +35,7 @@ type PreparedDownload struct {
3435
}
3536

3637
func parseLink(link string) DownloadResource {
37-
link = strings.Replace(link, "/send/", "/", 1)
38+
link = strings.Replace(link, string(endpoints.HTMLSend), "/", 1)
3839
linkSegments := strings.Split(link, "/")
3940
server := strings.Join(linkSegments[0:len(linkSegments)-1], "/")
4041
resource := strings.Split(linkSegments[len(linkSegments)-1], "#")

0 commit comments

Comments
 (0)