Raise hero upload soft-warning from 1 MB to 5 MB
The "may slow the page" prompt is only a client-side nudge — the server hard-limits uploads at 8 MB. 1 MB was arbitrarily low and nagged on perfectly normal hero images. Bump to 5 MB (still well under the hard cap) and pull the threshold + message into a single tooLargeToUpload() helper so the background, moon, and image upload paths stay in sync.
This commit is contained in:
@@ -12,6 +12,17 @@ const round2 = (v) => Math.round(v * 100) / 100
|
|||||||
const genId = () => (crypto.randomUUID ? crypto.randomUUID() : `el-${Date.now()}-${Math.random()}`)
|
const genId = () => (crypto.randomUUID ? crypto.randomUUID() : `el-${Date.now()}-${Math.random()}`)
|
||||||
const hexOf = (v) => (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(v || '') ? v : '#ffffff')
|
const hexOf = (v) => (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(v || '') ? v : '#ffffff')
|
||||||
|
|
||||||
|
// Soft page-weight warning shown before uploading a large hero image. This is
|
||||||
|
// only a nudge (hero images render on the public landing page); the server hard-
|
||||||
|
// limits uploads at 8 MB. Returns true when the caller should abort the upload.
|
||||||
|
const WARN_UPLOAD_MB = 5
|
||||||
|
function tooLargeToUpload(size) {
|
||||||
|
return (
|
||||||
|
size > WARN_UPLOAD_MB * 1024 * 1024 &&
|
||||||
|
!confirm(`This image is over ${WARN_UPLOAD_MB} MB and may slow the page. Upload anyway?`)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function newElement(type, z) {
|
function newElement(type, z) {
|
||||||
const base = { id: genId(), type, x: 50, y: 50, z, anchor: 'center' }
|
const base = { id: genId(), type, x: 50, y: 50, z, anchor: 'center' }
|
||||||
if (type === 'text_block') {
|
if (type === 'text_block') {
|
||||||
@@ -206,7 +217,7 @@ export default function HeroEditor() {
|
|||||||
const file = e.target.files?.[0]
|
const file = e.target.files?.[0]
|
||||||
e.target.value = ''
|
e.target.value = ''
|
||||||
if (!file) return
|
if (!file) return
|
||||||
if (file.size > 1024 * 1024 && !confirm('This image is over 1 MB and may slow the page. Upload anyway?')) return
|
if (tooLargeToUpload(file.size)) return
|
||||||
setUploading(true)
|
setUploading(true)
|
||||||
try {
|
try {
|
||||||
const { url } = await api.admin.upload(file)
|
const { url } = await api.admin.upload(file)
|
||||||
@@ -506,7 +517,7 @@ function MoonPanel({ element, onProps }) {
|
|||||||
const f = e.target.files?.[0]
|
const f = e.target.files?.[0]
|
||||||
e.target.value = ''
|
e.target.value = ''
|
||||||
if (!f) return
|
if (!f) return
|
||||||
if (f.size > 1024 * 1024 && !confirm('This image is over 1 MB and may slow the page. Upload anyway?')) return
|
if (tooLargeToUpload(f.size)) return
|
||||||
setUp(true)
|
setUp(true)
|
||||||
try {
|
try {
|
||||||
const { url } = await api.admin.upload(f)
|
const { url } = await api.admin.upload(f)
|
||||||
@@ -583,7 +594,7 @@ function ImagePanel({ element, onProps }) {
|
|||||||
const f = e.target.files?.[0]
|
const f = e.target.files?.[0]
|
||||||
e.target.value = ''
|
e.target.value = ''
|
||||||
if (!f) return
|
if (!f) return
|
||||||
if (f.size > 1024 * 1024 && !confirm('This image is over 1 MB and may slow the page. Upload anyway?')) return
|
if (tooLargeToUpload(f.size)) return
|
||||||
setUp(true)
|
setUp(true)
|
||||||
try {
|
try {
|
||||||
const { url } = await api.admin.upload(f)
|
const { url } = await api.admin.upload(f)
|
||||||
|
|||||||
Reference in New Issue
Block a user