Skip to content

Commit 225d213

Browse files
authored
Merge pull request #78 from drduh/wip-22nov25
refactor ui for mobile compatibility, versioned base64 file ids
2 parents bb4a7a7 + 1281300 commit 225d213

16 files changed

Lines changed: 97 additions & 50 deletions

File tree

.github/workflows/test-and-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
name: test
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v5
20+
- uses: actions/checkout@v6
2121
- uses: actions/setup-go@v6
2222
with:
2323
go-version: stable
@@ -30,7 +30,7 @@ jobs:
3030
name: lint
3131
runs-on: ubuntu-latest
3232
steps:
33-
- uses: actions/checkout@v5
33+
- uses: actions/checkout@v6
3434
- uses: actions/setup-go@v6
3535
with:
3636
go-version: stable

assets/style.css

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* style.css */
2+
23
* {
34
box-sizing: border-box;
45
font-family: "Open Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
56
}
67

78
body {
9+
align-items: center;
810
animation: var(--bg-animation);
911
background: var(--bg-gradient);
1012
background-size: var(--bg-size);
@@ -13,14 +15,8 @@ body {
1315
display: flex;
1416
flex-direction: column;
1517
font-size: 1em;
16-
margin: 0;
17-
padding: 0;
18-
}
19-
20-
.container {
21-
display: flex;
22-
justify-content: space-between;
23-
padding: 1em;
18+
margin: 1em auto;
19+
max-width: 80%;
2420
}
2521

2622
.box {
@@ -30,8 +26,8 @@ body {
3026
box-sizing: border-box;
3127
color: var(--fg-dark);
3228
flex: 1;
33-
margin: 10px;
34-
padding: 20px;
29+
margin: 1em;
30+
padding: 1em;
3531
text-align: center;
3632
}
3733

@@ -229,3 +225,20 @@ tr:hover,
229225
background-color: var(--bg-light);
230226
transition: background-color var(--animation) ease;
231227
}
228+
229+
details {
230+
padding: 1em;
231+
text-align: center;
232+
}
233+
234+
summary {
235+
border-bottom: 1px dotted var(--fg-light);
236+
color: var(--fg-light);
237+
cursor: pointer;
238+
display: inline;
239+
}
240+
241+
summary::marker {
242+
content: "";
243+
display: none;
244+
}

handlers/upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func Upload(app *config.App) http.HandlerFunc {
106106
},
107107
}
108108

109-
f.Scan(app.IdLength)
109+
f.Scan()
110110
app.Files[f.Name] = f
111111

112112
upload = storage.File{

settings/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ type Limit struct {
175175
// Wall character length
176176
CharsWall int `json:"charsWall,omitempty"`
177177

178-
// File identification string length
179-
IdLength int `json:"idLength,omitempty"`
180-
181178
// Maximum file size (in Megabytes)
182179
MaxSizeMb int64 `json:"maxSizeMb,omitempty"`
183180

settings/defaultSettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@
7070
"limit": {
7171
"charsMsg": 128,
7272
"charsWall": 1280,
73-
"idLength": 32,
74-
"maxSizeMb": 20,
73+
"maxSizeMb": 256,
7574
"perMinute": 30,
7675
"ticker": "30s"
7776
},

storage/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"time"
77
)
88

9+
const storageVersion = "1"
10+
911
// Storage represents content uploaded by users.
1012
type Storage struct {
1113

storage/scan.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
)
1010

1111
// Scan identifies and sets File attributes.
12-
func (f *File) Scan(idLength int) {
13-
f.setId(idLength)
12+
func (f *File) Scan() {
13+
f.setId()
1414
f.setSize()
1515
f.setSum()
1616
f.setType()
1717
}
1818

19-
// SetId sets the identifier with length.
20-
func (f *File) setId(length int) {
21-
f.Id = util.RandomHex(length)
19+
// SetId sets versioned File id with encoded entropy bytes.
20+
func (f *File) setId() {
21+
f.Id = storageVersion + util.RandomId()
2222
}
2323

2424
// SetSize sets the content length and readable file size.

storage/scan_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package storage
22

33
import (
4-
"regexp"
54
"strings"
65
"testing"
76
)
87

9-
// TestSetId tests File id is a valid hex string.
8+
// TestSetId tests File id is a valid string.
109
func TestSetId(t *testing.T) {
1110
f := &File{}
12-
f.setId(32)
11+
f.setId()
1312
if f.Id == "" {
14-
t.Fatalf("Id is empty; want hex string")
13+
t.Fatalf("Id is empty")
1514
}
16-
valid := regexp.MustCompile(`^[0-9a-fA-F]+$`)
17-
if !valid.MatchString(f.Id) {
18-
t.Fatalf("Id = %q; want hex characters", f.Id)
15+
if len(f.Id) != 44 {
16+
t.Fatalf("Id is wrong size: %v", len(f.Id))
1917
}
2018
}
2119

templates/data/config.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- config.tmpl -->
2+
{{ define "config" }}
3+
{{ if .Style.AllowPick }}
4+
<details><summary>config</summary>
5+
<div class="box">
6+
{{ template "selectTheme" . }}
7+
</div>
8+
</details>
9+
{{ end }}
10+
{{ end }}

templates/data/files.tmpl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<!-- files.tmpl -->
22
{{ define "files" }}
3-
{{ if .Paths.Upload }} {{- template "upload" . -}} {{ end }}
4-
{{ if .Paths.List }} {{- template "list" . -}} {{ end }}
3+
{{ if .Paths.Upload }}
4+
<details><summary>upload</summary>
5+
{{- template "upload" . -}}
6+
</details>
7+
{{ end }}
8+
{{ if .Paths.List }}
9+
<details><summary>download</summary>
10+
{{- template "list" . -}}
11+
</details>
12+
{{ end }}
513
{{ end }}

0 commit comments

Comments
 (0)