Show DCC send filesize

This commit is contained in:
Ken-Håvard Lieng 2020-06-24 08:09:05 +02:00
parent 45f8795fad
commit 02e9df865e
5 changed files with 65 additions and 59 deletions

File diff suppressed because one or more lines are too long

View File

@ -147,12 +147,12 @@ export default function handleSocket({
}
},
dcc_send({ network, from, filename, url }) {
dcc_send({ network, from, filename, size, url }) {
const networkName = getState().networks[network]?.name || network;
dispatch(
openModal('confirm', {
question: `${from} on ${networkName} is sending you: ${filename}`,
question: `${from} on ${networkName} is sending you (${size}): ${filename}`,
confirmation: 'Download',
onConfirm: () => {
const a = document.createElement('a');

View File

@ -112,10 +112,10 @@ func (pack *DCCSend) Download(w io.Writer, progress chan DownloadProgress) error
percentage := 100 * (float64(totalBytes) / float64(pack.Length))
progress <- DownloadProgress{
Speed: humanReadableByteCount(averageSpeed, true),
Speed: formatByteCount(averageSpeed, true),
PercCompletion: percentage,
BytesRemaining: humanReadableByteCount(bytesRemaining, false),
BytesCompleted: humanReadableByteCount(float64(totalBytes), false),
BytesRemaining: formatByteCount(bytesRemaining, false),
BytesCompleted: formatByteCount(float64(totalBytes), false),
SecondsElapsed: secondsSince(start),
SecondsToGo: bytesRemaining / averageSpeed,
File: pack.File,
@ -127,7 +127,7 @@ func (pack *DCCSend) Download(w io.Writer, progress chan DownloadProgress) error
if progress != nil {
progress <- DownloadProgress{
PercCompletion: 100,
BytesCompleted: humanReadableByteCount(float64(totalBytes), false),
BytesCompleted: formatByteCount(float64(totalBytes), false),
SecondsElapsed: secondsSince(start),
File: pack.File,
}
@ -136,6 +136,10 @@ func (pack *DCCSend) Download(w io.Writer, progress chan DownloadProgress) error
return nil
}
func (pack *DCCSend) Size() string {
return formatByteCount(float64(pack.Length), false)
}
type DownloadProgress struct {
File string `json:"file"`
Error error `json:"error"`
@ -172,7 +176,7 @@ const (
gibibyte
)
func humanReadableByteCount(b float64, speed bool) string {
func formatByteCount(b float64, speed bool) string {
unit := ""
value := b

View File

@ -496,6 +496,7 @@ func (i *ircHandler) receiveDCCSend(pack *irc.DCCSend, msg *irc.Message) {
Network: i.client.Host(),
From: msg.Sender,
Filename: pack.File,
Size: pack.Size(),
URL: fmt.Sprintf("%s://%s/downloads/%s/%s",
i.state.String("scheme"), i.state.String("host"), i.state.user.Username, pack.File),
})

View File

@ -218,6 +218,7 @@ type DCCSend struct {
Network string
From string
Filename string
Size string
URL string
}