Skip to content

Commit 18d9e55

Browse files
committed
Changed user and api key overview to local TZ, increased JS version
1 parent ab506a3 commit 18d9e55

File tree

10 files changed

+29
-27
lines changed

10 files changed

+29
-27
lines changed

build/go-generate/minifyStaticContent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ func fileExists(filename string) bool {
144144
// Auto-generated content below, do not modify
145145
// Version codes can be changed in updateVersionNumbers.go
146146

147-
const jsAdminVersion = 14
147+
const jsAdminVersion = 15
148148
const jsE2EVersion = 8
149149
const cssMainVersion = 5

build/go-generate/updateVersionNumbers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"strings"
1212
)
1313

14-
const versionJsAdmin = 14
14+
const versionJsAdmin = 15
1515
const versionJsDropzone = 5
1616
const versionJsE2EAdmin = 8
1717
const versionCssMain = 5

internal/models/ApiKey.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package models
33
import (
44
"errors"
55
"strings"
6-
"time"
76
)
87

98
const (
@@ -73,14 +72,6 @@ func ApiPermissionFromString(permString string) (ApiPermission, error) {
7372
}
7473
}
7574

76-
// GetReadableDate returns the date as YYYY-MM-DD HH:MM:SS
77-
func (key *ApiKey) GetReadableDate() string {
78-
if key.LastUsed == 0 {
79-
return "Never"
80-
}
81-
return time.Unix(key.LastUsed, 0).Format("2006-01-02 15:04:05")
82-
}
83-
8475
// GetRedactedId returns a redacted version of the API key
8576
func (key *ApiKey) GetRedactedId() string {
8677
return key.Id[0:2] + "**************************" + key.Id[len(key.Id)-2:]

internal/models/User.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package models
22

33
import (
44
"encoding/json"
5+
56
"github.com/forceu/gokapi/internal/helper"
6-
"time"
77
)
88

99
// UserPermission contains zero or more permissions as uint16
@@ -20,17 +20,6 @@ type User struct {
2020
ResetPassword bool `json:"resetPassword" redis:"ResetPassword"`
2121
}
2222

23-
// GetReadableDate returns the date as YYYY-MM-DD HH:MM
24-
func (u *User) GetReadableDate() string {
25-
if u.LastOnline == 0 {
26-
return "Never"
27-
}
28-
if time.Now().Unix()-u.LastOnline < 120 {
29-
return "Online"
30-
}
31-
return time.Unix(u.LastOnline, 0).Format("2006-01-02 15:04")
32-
}
33-
3423
// GetReadableUserLevel returns the userlevel as a group name
3524
func (u *User) GetReadableUserLevel() string {
3625
switch u.UserLevel {

internal/webserver/web/static/js/dateformat.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,23 @@ function formatUnixTimestamp(unixTimestamp) {
1414
function insertFormattedDate(unixTimestamp, id) {
1515
document.getElementById(id).innerText = formatUnixTimestamp(unixTimestamp);
1616
}
17+
18+
function insertLastOnlineDate(unixTimestamp, id) {
19+
if (unixTimestamp == 0) {
20+
document.getElementById(id).innerText = "Never";
21+
return;
22+
}
23+
if ((Date.now()/1000) - 120 < unixTimestamp) {
24+
document.getElementById(id).innerText = "Online";
25+
return;
26+
}
27+
insertFormattedDate(unixTimestamp, id);
28+
}
29+
30+
function insertLastUsed(unixTimestamp, id) {
31+
if (unixTimestamp == 0) {
32+
document.getElementById(id).innerText = "Never";
33+
return;
34+
}
35+
insertFormattedDate(unixTimestamp, id);
36+
}
File renamed without changes.

internal/webserver/web/static/js/min/dateformat.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/webserver/web/templates/html_api.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
<tr id="row-{{ .PublicId }}">
4141
<td id="friendlyname-{{ .PublicId }}" onClick="addFriendlyNameChange('{{ .PublicId }}')">{{ .FriendlyName }}</td>
4242
<td><div class="font-monospace">{{ .GetRedactedId }}</div></td>
43-
<td>{{ .GetReadableDate }}</td>
43+
<td><span id="cell-lastused-{{ .PublicId }}"></span></td>
44+
<script>insertLastUsed({{ .LastUsed }}, "cell-lastused-{{ .PublicId }}");</script>
4445
<td class="prevent-select">
4546
<i id="perm_view_{{ .PublicId }}" class="bi bi-eye {{if not .HasPermissionView}}perm-notgranted{{else}}perm-granted{{end}}" title="List Uploads" onclick='changeApiPermission("{{ .PublicId }}","PERM_VIEW", "perm_view_{{ .PublicId }}");'></i>
4647
<i id="perm_upload_{{ .PublicId }}" class="bi bi-file-earmark-arrow-up {{if not .HasPermissionUpload}}perm-notgranted{{else}}perm-granted{{end}}" title="Upload" onclick='changeApiPermission("{{ .PublicId }}","PERM_UPLOAD", "perm_upload_{{ .PublicId }}");'></i>

internal/webserver/web/templates/html_users.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
<tr id="row-{{ .User.Id }}">
3636
<td>{{ .User.Name }}</td>
3737
<td id="userlevel_{{ .User.Id }}">{{ .User.GetReadableUserLevel }}</td>
38-
<td>{{ .User.GetReadableDate }}</td>
38+
<td><span id="cell-lastonline-{{ .User.Id }}"></span></td>
39+
<script>insertLastOnlineDate({{ .User.LastOnline }}, "cell-lastonline-{{ .User.Id }}");</script>
3940
<td>{{ .UploadCount }}</td>
4041
<td class="prevent-select">
4142

internal/webserver/web/templates/string_constants.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// Specifies the version of JS files, so that the browser doesn't
55
// use a cached version, if the file has been updated
6-
{{define "js_admin_version"}}14{{end}}
6+
{{define "js_admin_version"}}15{{end}}
77
{{define "js_dropzone_version"}}5{{end}}
88
{{define "js_e2eversion"}}8{{end}}
99
{{define "css_main"}}5{{end}}

0 commit comments

Comments
 (0)