summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/components/blob_viewers/download_viewer.vue
blob: be5e9685ccd02da3a91bcce42e36e5b1feba4cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<script>
import { GlIcon, GlLink } from '@gitlab/ui';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { sprintf, __ } from '~/locale';

export default {
  components: {
    GlIcon,
    GlLink,
  },
  props: {
    blob: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      fileName: this.blob.name,
      filePath: this.blob.externalStorageUrl || this.blob.rawPath,
      fileSize: this.blob.rawSize || 0,
    };
  },
  computed: {
    downloadFileSize() {
      return numberToHumanSize(this.fileSize);
    },
    downloadText() {
      if (this.fileSize > 0) {
        return sprintf(__('Download (%{fileSizeReadable})'), {
          fileSizeReadable: this.downloadFileSize,
        });
      }
      return __('Download');
    },
  },
};
</script>

<template>
  <div class="gl-text-center gl-py-13 gl-bg-gray-50">
    <gl-link :href="filePath" rel="nofollow" :download="fileName" target="_blank">
      <div>
        <gl-icon :size="16" name="download" class="gl-text-gray-900" />
      </div>
      <h4>{{ downloadText }}</h4>
    </gl-link>
  </div>
</template>