From 14751fb370fd4bb2c97b7e6cfc029cc2dbfffe19 Mon Sep 17 00:00:00 2001
From: Mave <11227996+Ma-ve@users.noreply.github.com>
Date: Wed, 30 Apr 2025 18:55:10 +0200
Subject: [PATCH 1/3] fix: 64.0 MB -> 64 MB, but keep 64.1
---
src/helpers.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/helpers.ts b/src/helpers.ts
index 04348b7c..f97c94c8 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -9,7 +9,7 @@ function bytesToHuman(bytes: number): string {
{ thresh: 1024, unit: 'KiB' },
]) {
if (bytes > t.thresh) {
- return `${(bytes / t.thresh).toFixed(1)} ${t.unit}`
+ return `${parseFloat((bytes / t.thresh).toFixed(1))} ${t.unit}`
}
}
From 717688396f9f813946edda537f899c506f76cfc4 Mon Sep 17 00:00:00 2001
From: Mave <11227996+Ma-ve@users.noreply.github.com>
Date: Mon, 4 Aug 2025 11:48:26 +0200
Subject: [PATCH 2/3] feat: add expiryChoicesHuman, remove 'default expiry'
from dropdown
Focussing on front-end UI, 'default expiry' means nothing. Rather than relying on non-human readable, unix timestamps, introducing human readable options: (s)econds, (m)inutes, (h)ours, (d)ays. The defaultExpiryHuman should be any of the options for expiryChoicesHuman. If it's not, it'll fallback to `null`, which will fallback to the `defaultExpiry` as it is now
Save the selected option as a cookie, only after initially loaded. Load from cookie on page load. API is not changed, still accepts seconds
---
README.md | 4 +-
pkg/customization/customize.go | 6 +-
src/components/create.vue | 109 ++++++++++++++++++++++++++++++++-
src/helpers.ts | 25 ++++++++
4 files changed, 138 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 2df4c8db..249bdc3d 100644
--- a/README.md
+++ b/README.md
@@ -99,9 +99,9 @@ Requirements:
- Node v22+
- Tilt v0.33+
-Run `tilt up`, and see `http://localhost:10350/` for the Tilt dashboard.
+Run `tilt up`, and see http://localhost:10350/ for the Tilt dashboard.
-Front-end application is available at `http://localhost:15641/`.
+Front-end application is available at http://localhost:15641/.
## Localize to your own language
diff --git a/pkg/customization/customize.go b/pkg/customization/customize.go
index c22e6ac3..4ff0f252 100644
--- a/pkg/customization/customize.go
+++ b/pkg/customization/customize.go
@@ -30,8 +30,10 @@ type (
DisableQRSupport bool `json:"disableQRSupport,omitempty" yaml:"disableQRSupport"`
DisableThemeSwitcher bool `json:"disableThemeSwitcher,omitempty" yaml:"disableThemeSwitcher"`
- DisableExpiryOverride bool `json:"disableExpiryOverride,omitempty" yaml:"disableExpiryOverride"`
- ExpiryChoices []int64 `json:"expiryChoices,omitempty" yaml:"expiryChoices"`
+ DisableExpiryOverride bool `json:"disableExpiryOverride,omitempty" yaml:"disableExpiryOverride"`
+ ExpiryChoices []int64 `json:"expiryChoices,omitempty" yaml:"expiryChoices"`
+ ExpiryChoicesHuman []string `json:"expiryChoicesHuman,omitempty" yaml:"expiryChoicesHuman"`
+ DefaultExpiryHuman string `json:"defaultExpiryHuman,omitempty" yaml:"defaultExpiryHuman"`
AcceptedFileTypes string `json:"acceptedFileTypes" yaml:"acceptedFileTypes"`
DisableFileAttachment bool `json:"disableFileAttachment" yaml:"disableFileAttachment"`
diff --git a/src/components/create.vue b/src/components/create.vue
index 7532bcff..a48347e9 100644
--- a/src/components/create.vue
+++ b/src/components/create.vue
@@ -122,8 +122,11 @@
diff --git a/src/helpers.ts b/src/helpers.ts
index f97c94c8..886fb7ce 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -16,6 +16,31 @@ function bytesToHuman(bytes: number): string {
return `${bytes} B`
}
+function durationToSeconds(duration) {
+ const regex = /^(\d+)([smhd])$/
+ const match = typeof duration === 'string' && duration.match(regex)
+ if (!match) {
+ return duration
+ }
+
+ const value = parseInt(match[1], 10)
+ const unit = match[2]
+
+ switch (unit) {
+ case 's':
+ return value
+ case 'm':
+ return value * 60
+ case 'h':
+ return value * 3600
+ case 'd':
+ return value * 86400
+ }
+
+ return duration // Fallback: return as-is
+}
+
export {
bytesToHuman,
+ durationToSeconds,
}
From 7d0b5b993de9dbeb76d692a4c1daab0d36693ed6 Mon Sep 17 00:00:00 2001
From: Mave <11227996+Ma-ve@users.noreply.github.com>
Date: Mon, 4 Aug 2025 12:54:29 +0200
Subject: [PATCH 3/3] fix: merge expiry choices human with upstream main
---
src/components/create.vue | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/components/create.vue b/src/components/create.vue
index a48347e9..074fff87 100644
--- a/src/components/create.vue
+++ b/src/components/create.vue
@@ -185,7 +185,7 @@ export default defineComponent({
},
expiryChoices(): Record[] {
- if (this.$root.customize.expiryChoicesHuman) {
+ if (this.customize.expiryChoicesHuman) {
return this.expiryChoicesHuman
}
@@ -219,7 +219,7 @@ export default defineComponent({
choices.push({ text: this.$t('expire-default'), value: null })
}
- for (const choice of this.$root.customize.expiryChoicesHuman || defaultExpiryChoicesHuman) {
+ for (const choice of this.customize.expiryChoicesHuman || defaultExpiryChoicesHuman) {
const option = { value: choice }
const unit = choice.slice(-1)
@@ -277,15 +277,7 @@ export default defineComponent({
created(): void {
this.checkWriteAccess()
- this.$root.$watch(
- 'customize',
- newVal => {
- if (newVal) {
- this.initExpiry()
- }
- },
- { immediate: true },
- )
+ this.initExpiry()
},
data() {
@@ -308,13 +300,13 @@ export default defineComponent({
_getTextForAmount(unit, amount) {
switch (unit) {
case 'd':
- return this.$tc('expire-n-days', amount)
+ return this.$t('expire-n-days', amount)
case 'h':
- return this.$tc('expire-n-hours', amount)
+ return this.$t('expire-n-hours', amount)
case 'm':
- return this.$tc('expire-n-minutes', amount)
+ return this.$t('expire-n-minutes', amount)
case 's':
- return this.$tc('expire-n-seconds', amount)
+ return this.$t('expire-n-seconds', amount)
}
return amount
@@ -434,28 +426,29 @@ export default defineComponent({
},
hasValidDefaultExpiryHuman() {
- const defaultExpiry = this.$root.customize.defaultExpiryHuman || false
+ const defaultExpiry = this.customize.defaultExpiryHuman || false
if (defaultExpiry === false) {
return false
}
- if (!this.$root.customize.expiryChoicesHuman) {
+ if (!this.customize.expiryChoicesHuman) {
return false
}
- return this.$root.customize.expiryChoicesHuman.includes(defaultExpiry)
+ return this.customize.expiryChoicesHuman.includes(defaultExpiry)
},
initExpiry() {
const match = document.cookie.match(/(?:^|;\s*)selectedExpiry=([^;]*)/)
this.selectedExpiry = match
? decodeURIComponent(match[1])
- : this.$root.customize?.defaultExpiryHuman || null
+ : this.customize?.defaultExpiryHuman || null
- if (!this.$root.customize?.expiryChoicesHuman) {
+ if (!this.customize?.expiryChoicesHuman) {
return
}
- if (!this.$root.customize?.expiryChoicesHuman.includes(this.selectedExpiry)) {
+
+ if (!this.customize?.expiryChoicesHuman.includes(this.selectedExpiry)) {
this.selectedExpiry = null
}
},