summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/utils/icon.js
blob: 661ebb6edfcf1cd89ee49ea8ced292a5448364a2 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const entryTypeIcons = {
  tree: 'folder',
  commit: 'archive',
};

const fileTypeIcons = [
  { extensions: ['pdf'], name: 'file-pdf-o' },
  {
    extensions: [
      'jpg',
      'jpeg',
      'jif',
      'jfif',
      'jp2',
      'jpx',
      'j2k',
      'j2c',
      'png',
      'gif',
      'tif',
      'tiff',
      'svg',
      'ico',
      'bmp',
    ],
    name: 'file-image-o',
  },
  {
    extensions: ['zip', 'zipx', 'tar', 'gz', 'bz', 'bzip', 'xz', 'rar', '7z'],
    name: 'file-archive-o',
  },
  { extensions: ['mp3', 'wma', 'ogg', 'oga', 'wav', 'flac', 'aac'], name: 'file-audio-o' },
  {
    extensions: [
      'mp4',
      'm4p',
      'm4v',
      'mpg',
      'mp2',
      'mpeg',
      'mpe',
      'mpv',
      'm2v',
      'avi',
      'mkv',
      'flv',
      'ogv',
      'mov',
      '3gp',
      '3g2',
    ],
    name: 'file-video-o',
  },
  { extensions: ['doc', 'dot', 'docx', 'docm', 'dotx', 'dotm', 'docb'], name: 'file-word-o' },
  {
    extensions: [
      'xls',
      'xlt',
      'xlm',
      'xlsx',
      'xlsm',
      'xltx',
      'xltm',
      'xlsb',
      'xla',
      'xlam',
      'xll',
      'xlw',
    ],
    name: 'file-excel-o',
  },
  {
    extensions: [
      'ppt',
      'pot',
      'pps',
      'pptx',
      'pptm',
      'potx',
      'potm',
      'ppam',
      'ppsx',
      'ppsm',
      'sldx',
      'sldm',
    ],
    name: 'file-powerpoint-o',
  },
];

// eslint-disable-next-line import/prefer-default-export
export const getIconName = (type, path) => {
  if (entryTypeIcons[type]) return entryTypeIcons[type];

  const extension = path.split('.').pop();
  const file = fileTypeIcons.find(t => t.extensions.some(ext => ext === extension));

  return file ? file.name : 'file-text-o';
};