From d01c37c59d2760e927efc7a354f0237317d70c11 Mon Sep 17 00:00:00 2001 From: Ribas160 Date: Thu, 26 Jun 2025 18:12:22 +0300 Subject: [PATCH] Show file name and size on download page --- CHANGELOG.md | 1 + CREDITS.md | 2 +- i18n/ar.json | 8 +++++++ i18n/bg.json | 8 +++++++ i18n/ca.json | 8 +++++++ i18n/co.json | 8 +++++++ i18n/cs.json | 8 +++++++ i18n/de.json | 8 +++++++ i18n/el.json | 8 +++++++ i18n/en.json | 8 +++++++ i18n/es.json | 8 +++++++ i18n/et.json | 8 +++++++ i18n/fi.json | 8 +++++++ i18n/fr.json | 8 +++++++ i18n/he.json | 8 +++++++ i18n/hi.json | 8 +++++++ i18n/hu.json | 8 +++++++ i18n/id.json | 8 +++++++ i18n/it.json | 8 +++++++ i18n/ja.json | 8 +++++++ i18n/jbo.json | 8 +++++++ i18n/ko.json | 8 +++++++ i18n/ku.json | 8 +++++++ i18n/la.json | 8 +++++++ i18n/lt.json | 8 +++++++ i18n/nl.json | 8 +++++++ i18n/no.json | 8 +++++++ i18n/oc.json | 8 +++++++ i18n/pl.json | 8 +++++++ i18n/pt.json | 8 +++++++ i18n/ro.json | 8 +++++++ i18n/ru.json | 8 +++++++ i18n/sk.json | 8 +++++++ i18n/sl.json | 8 +++++++ i18n/sv.json | 8 +++++++ i18n/th.json | 8 +++++++ i18n/tr.json | 8 +++++++ i18n/uk.json | 8 +++++++ i18n/zh.json | 8 +++++++ js/privatebin.js | 49 ++++++++++++++++++++++++++++++++++++++++++- js/test/Helper.js | 26 +++++++++++++++++++++++ lib/Configuration.php | 2 +- 42 files changed, 373 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2b405b1..36676179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.7.7 (not yet released) * ADDED: Switching templates using the web ui (#1501) +* ADDED: Show file name and size on download page (#603) * CHANGED: Passing large data structures by reference to reduce memory consumption (#858) * CHANGED: Removed use of ctype functions and polyfill library for ctype * CHANGED: Upgrading libraries to: DOMpurify 3.2.6, ip-lib 1.20.0 diff --git a/CREDITS.md b/CREDITS.md index 308a424a..37026898 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -5,6 +5,7 @@ * Simon Rupf - current developer and maintainer * rugk - security review, doc improvment, JS refactoring & various other stuff * R4SAS - python client, compression, blob URI to support larger attachments +* Mikhail Romanov - UI improvements, theme switching, clipboard support, multi-file upload, bugfixes, code refactoring ## Past contributions @@ -33,7 +34,6 @@ * Mounir Idrassi & J. Mozdzen - secure YOURLS integration * Felipe Nakandakari - enabled AWS SDK to use default credential provider chain in the S3 Storage backend * Aaron Sherber - cache control headers for API calls & use of `shortenviayourls` in query parameters -* Mikhail Romanov - UI improvements, theme switching, clipboard support, multi-file upload, bugfixes, code refactoring ## Translations * Hexalyse - French diff --git a/i18n/ar.json b/i18n/ar.json index cd116da0..b4a84fe9 100644 --- a/i18n/ar.json +++ b/i18n/ar.json @@ -164,6 +164,14 @@ "EiB": "إكسابايت", "ZiB": "زيتابايت", "YiB": "يوتابايت", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "التنسيق", "Plain Text": "نص عادي", "Source Code": "كود مصدر", diff --git a/i18n/bg.json b/i18n/bg.json index 353427bc..80557a97 100644 --- a/i18n/bg.json +++ b/i18n/bg.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Формат", "Plain Text": "Чист текст", "Source Code": "Изходен код", diff --git a/i18n/ca.json b/i18n/ca.json index d178e417..b08a27c9 100644 --- a/i18n/ca.json +++ b/i18n/ca.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Text sense format", "Source Code": "Codi font", diff --git a/i18n/co.json b/i18n/co.json index 38d763ba..b66d0843 100644 --- a/i18n/co.json +++ b/i18n/co.json @@ -164,6 +164,14 @@ "EiB": "Eo", "ZiB": "Zo", "YiB": "Yo", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Furmatu", "Plain Text": "Testu in chjaru", "Source Code": "Codice di fonte", diff --git a/i18n/cs.json b/i18n/cs.json index 6a8db622..54c0bb42 100644 --- a/i18n/cs.json +++ b/i18n/cs.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formát", "Plain Text": "Prostý text", "Source Code": "Zdrojový kód", diff --git a/i18n/de.json b/i18n/de.json index d653a614..3e53684f 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Nur Text", "Source Code": "Quellcode", diff --git a/i18n/el.json b/i18n/el.json index 57fbb2cd..f4f5060a 100644 --- a/i18n/el.json +++ b/i18n/el.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Μορφοποίηση", "Plain Text": "Απλό κείμενο", "Source Code": "Πηγαίος Κώδικας", diff --git a/i18n/en.json b/i18n/en.json index d1b2a46f..69bc9927 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Plain Text", "Source Code": "Source Code", diff --git a/i18n/es.json b/i18n/es.json index 45c838bd..2852f5ad 100644 --- a/i18n/es.json +++ b/i18n/es.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formato", "Plain Text": "Texto sin formato", "Source Code": "Código fuente", diff --git a/i18n/et.json b/i18n/et.json index 04d9af86..74990de0 100644 --- a/i18n/et.json +++ b/i18n/et.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formaat", "Plain Text": "Lihttekst", "Source Code": "Lähtekood", diff --git a/i18n/fi.json b/i18n/fi.json index 4f268308..9deaf7c1 100644 --- a/i18n/fi.json +++ b/i18n/fi.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formaatti", "Plain Text": "Perusteksti", "Source Code": "Lähdekoodi", diff --git a/i18n/fr.json b/i18n/fr.json index faafdc29..60a1062a 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -164,6 +164,14 @@ "EiB": "Eio", "ZiB": "Zio", "YiB": "Yio", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Texte brut", "Source Code": "Code source", diff --git a/i18n/he.json b/i18n/he.json index ae3279a8..dd35b47e 100644 --- a/i18n/he.json +++ b/i18n/he.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "פורמט", "Plain Text": "טקסט פשוט", "Source Code": "קוד מקור", diff --git a/i18n/hi.json b/i18n/hi.json index d1b2a46f..69bc9927 100644 --- a/i18n/hi.json +++ b/i18n/hi.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Plain Text", "Source Code": "Source Code", diff --git a/i18n/hu.json b/i18n/hu.json index 711ffa73..544876ea 100644 --- a/i18n/hu.json +++ b/i18n/hu.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formátum", "Plain Text": "Egyszerű szöveg", "Source Code": "Forráskód", diff --git a/i18n/id.json b/i18n/id.json index e0d16c1f..f40a8077 100644 --- a/i18n/id.json +++ b/i18n/id.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Teks Biasa", "Source Code": "Kode Sumber", diff --git a/i18n/it.json b/i18n/it.json index f358153e..0bb0c8a7 100644 --- a/i18n/it.json +++ b/i18n/it.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formato", "Plain Text": "Solo Testo", "Source Code": "Codice Sorgente", diff --git a/i18n/ja.json b/i18n/ja.json index f4cc44fc..c92d5330 100644 --- a/i18n/ja.json +++ b/i18n/ja.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "形式", "Plain Text": "プレーンテキスト", "Source Code": "ソースコード", diff --git a/i18n/jbo.json b/i18n/jbo.json index 9935a6c0..8362a5d1 100644 --- a/i18n/jbo.json +++ b/i18n/jbo.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Plain Text", "Source Code": "Source Code", diff --git a/i18n/ko.json b/i18n/ko.json index d1b2a46f..69bc9927 100644 --- a/i18n/ko.json +++ b/i18n/ko.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Plain Text", "Source Code": "Source Code", diff --git a/i18n/ku.json b/i18n/ku.json index 5b98497e..90581539 100644 --- a/i18n/ku.json +++ b/i18n/ku.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Plain Text", "Source Code": "Source Code", diff --git a/i18n/la.json b/i18n/la.json index 97eb2f96..644710ec 100644 --- a/i18n/la.json +++ b/i18n/la.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Plain Text", "Source Code": "Source Code", diff --git a/i18n/lt.json b/i18n/lt.json index e68669ca..a983f544 100644 --- a/i18n/lt.json +++ b/i18n/lt.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formatas", "Plain Text": "Grynasis tekstas", "Source Code": "Pirminis kodas", diff --git a/i18n/nl.json b/i18n/nl.json index 13da44a8..14955bea 100644 --- a/i18n/nl.json +++ b/i18n/nl.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formaat", "Plain Text": "Platte tekst", "Source Code": "Broncode", diff --git a/i18n/no.json b/i18n/no.json index eb866d85..d5599466 100644 --- a/i18n/no.json +++ b/i18n/no.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Ren Tekst", "Source Code": "Kildekode", diff --git a/i18n/oc.json b/i18n/oc.json index 6b3c567f..105aba90 100644 --- a/i18n/oc.json +++ b/i18n/oc.json @@ -164,6 +164,14 @@ "EiB": "Eio", "ZiB": "Zio", "YiB": "Yio", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Tèxte brut", "Source Code": "Còdi font", diff --git a/i18n/pl.json b/i18n/pl.json index d17bb5ca..a6a5e9ba 100644 --- a/i18n/pl.json +++ b/i18n/pl.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Czysty tekst", "Source Code": "Kod źródłowy", diff --git a/i18n/pt.json b/i18n/pt.json index 19e7e6c7..e0beee4d 100644 --- a/i18n/pt.json +++ b/i18n/pt.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formato", "Plain Text": "Texto sem formato", "Source Code": "Código fonte", diff --git a/i18n/ro.json b/i18n/ro.json index 4708ac19..2ca1f12e 100644 --- a/i18n/ro.json +++ b/i18n/ro.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formatare", "Plain Text": "Text neformatat", "Source Code": "Cod sursă", diff --git a/i18n/ru.json b/i18n/ru.json index ef681b45..f5c14ed1 100644 --- a/i18n/ru.json +++ b/i18n/ru.json @@ -164,6 +164,14 @@ "EiB": "Эбайт", "ZiB": "Збайт", "YiB": "Йбайт", + "KB": "КБ", + "MB": "МБ", + "GB": "ГБ", + "TB": "ТБ", + "PB": "ПБ", + "EB": "ЭБ", + "ZB": "ЗБ", + "YB": "ЙБ", "Format": "Формат", "Plain Text": "Обычный текст", "Source Code": "Исходный код", diff --git a/i18n/sk.json b/i18n/sk.json index 9dc57c1a..aa857389 100644 --- a/i18n/sk.json +++ b/i18n/sk.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Formát", "Plain Text": "Čistý text", "Source Code": "Zdrojový kód", diff --git a/i18n/sl.json b/i18n/sl.json index 571c2356..8e4d3654 100644 --- a/i18n/sl.json +++ b/i18n/sl.json @@ -164,6 +164,14 @@ "EiB": "EB", "ZiB": "ZB", "YiB": "YB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Surov tekst", "Source Code": "Odprta koda", diff --git a/i18n/sv.json b/i18n/sv.json index 3e2be511..5bd94ffa 100644 --- a/i18n/sv.json +++ b/i18n/sv.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Plain Text", "Source Code": "Source Code", diff --git a/i18n/th.json b/i18n/th.json index e2a58cdd..248b6ffd 100644 --- a/i18n/th.json +++ b/i18n/th.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "รูปแบบ", "Plain Text": "ข้อความล้วน", "Source Code": "ซอร์สโค้ด", diff --git a/i18n/tr.json b/i18n/tr.json index 8eb47712..6d067827 100644 --- a/i18n/tr.json +++ b/i18n/tr.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Format", "Plain Text": "Düz Yazı", "Source Code": "Kaynak Kodu", diff --git a/i18n/uk.json b/i18n/uk.json index 1110c23f..458c5bd4 100644 --- a/i18n/uk.json +++ b/i18n/uk.json @@ -164,6 +164,14 @@ "EiB": "Ебайт", "ZiB": "Збайт", "YiB": "Йбайт", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "Формат", "Plain Text": "Звичайний текст", "Source Code": "Вихідний код", diff --git a/i18n/zh.json b/i18n/zh.json index c6d80717..0b7ca6c4 100644 --- a/i18n/zh.json +++ b/i18n/zh.json @@ -164,6 +164,14 @@ "EiB": "EiB", "ZiB": "ZiB", "YiB": "YiB", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB", + "PB": "PB", + "EB": "EB", + "ZB": "ZB", + "YB": "YB", "Format": "格式", "Plain Text": "纯文本", "Source Code": "源代码", diff --git a/js/privatebin.js b/js/privatebin.js index cfe1e4c6..53a6adbc 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -591,6 +591,32 @@ jQuery.PrivateBin = (function($, RawDeflate) { return expirationDate; }; + /** + * Convert Bytes to KB/MB/GB + * + * @name Helper.formatBytes + * @function + * + * @param {number} bytes + * @return {string} + */ + me.formatBytes = function (bytes) + { + let result = ''; + const kilobyte = 1000; + const decimalPoint = 2; + const sizes = [I18n._('B'), I18n._('KB'), I18n._('MB'), I18n._('GB')]; + const index = Math.floor(Math.log(bytes) / Math.log(kilobyte)); + + if (bytes > 0) { + result = parseFloat((bytes / Math.pow(kilobyte, index)).toFixed(decimalPoint)) + ' ' + sizes[index]; + } else { + result = `0 ${I18n._('B')}`; + } + + return result; + } + /** * resets state, used for unit testing * @@ -3000,7 +3026,9 @@ jQuery.PrivateBin = (function($, RawDeflate) { if (typeof fileName !== 'undefined') { attachmentLink.attr('download', fileName); - template.append(fileName); + + const fileSize = me.getAttachmentSize(attachmentData); + template.append(`(${fileName}, ${fileSize})`); } // sanitize SVG preview @@ -3202,6 +3230,25 @@ jQuery.PrivateBin = (function($, RawDeflate) { return attachmentData.substring(5, mimeTypeEnd); } + /** + * Get attachment size in B/KB/MB/GB + * + * @name AttachmentViewer.getAttachmentSize + * @function + * @param {string} attachmentData - Base64 string + */ + me.getAttachmentSize = function(attachmentData) + { + const base64Start = attachmentData.indexOf(',') + 1; + const rawData = attachmentData.substring(base64Start); + const decodedData = rawData.length > 0 ? atob(rawData) : ''; + + const buf = new Uint8Array(decodedData.length); + const bytes = new Blob([buf]).size; + + return Helper.formatBytes(bytes); + } + /** * moves the attachment link to another element * diff --git a/js/test/Helper.js b/js/test/Helper.js index ab72a6ad..4f751897 100644 --- a/js/test/Helper.js +++ b/js/test/Helper.js @@ -290,5 +290,31 @@ describe('Helper', function () { } ); }); + + describe('formatBytes', function () { + jsc.property('returns 0 B for 0 bytes', function () { + return $.PrivateBin.Helper.formatBytes(0) === '0 B'; + }); + + jsc.property('formats bytes < 1000 as B', function () { + return $.PrivateBin.Helper.formatBytes(500) === '500 B'; + }); + + jsc.property('formats kilobytes correctly', function () { + return $.PrivateBin.Helper.formatBytes(1500) === '1.5 KB'; + }); + + jsc.property('formats megabytes correctly', function () { + return $.PrivateBin.Helper.formatBytes(2 * 1000 * 1000) === '2 MB'; + }); + + jsc.property('formats gigabytes correctly', function () { + return $.PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.45 GB'; + }); + + jsc.property('rounds to two decimal places', function () { + return $.PrivateBin.Helper.formatBytes(1234567) === '1.23 MB'; + }); + }); }); diff --git a/lib/Configuration.php b/lib/Configuration.php index c39f71f5..f097e288 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -119,7 +119,7 @@ class Configuration 'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==', 'js/legacy.js' => 'sha512-UxW/TOZKon83n6dk/09GsYKIyeO5LeBHokxyIq+r7KFS5KMBeIB/EM7NrkVYIezwZBaovnyNtY2d9tKFicRlXg==', 'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==', - 'js/privatebin.js' => 'sha512-m6RrsOsz4RgIWXDzgRghQDx6aegFCpkpqURwhfXwE/rNWhe/1rPJaLR+FXII82iTWo0n9JCzSbqrDqkYVPI50w==', + 'js/privatebin.js' => 'sha512-rRy19m1V347H457Vcvy0IpbuohAuvIPgVY4s+FgoSn9avqFj3lYA4W/Ewz3DS+BekCUvVm9I8/YMbW82PzgFmQ==', 'js/purify-3.2.6.js' => 'sha512-zqwL4OoBLFx89QPewkz4Lz5CSA2ktU+f31fuECkF0iK3Id5qd3Zpq5dMby8KwHjIEpsUgOqwF58cnmcaNem0EA==', 'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==', 'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',