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
100
101
102
103
|
import {translate as t} from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import {generateUrl, imagePath} from '@nextcloud/router'
import $ from 'jquery'
export default class ChecksumTab {
/**
* Instantiate a new tab.
*/
constructor(el) {
this.$el = $(el)
}
/**
* Return associated file info object.
*/
getFileInfo() {
return this.fileInfo
}
/**
* Renders this details view.
*/
render(fileInfo) {
this.fileInfo = fileInfo
this._renderSelectList(this.$el)
}
_renderSelectList($el) {
$el.html('<div class="get-checksum">'
+ '<select id="choose-algorithm">'
+ '<option value="">' + t('checksum', 'Choose Algorithm') + '</option>'
+ '<option value="md5">MD5</option>'
+ '<option value="sha1">SHA1</option>'
+ '<option value="sha256">SHA256</option>'
+ '<option value="sha384">SHA384</option>'
+ '<option value="sha512">SHA512</option>'
+ '<option value="crc32">CRC32</option>'
+ '</select></div>'
)
$el.find('#choose-algorithm').change((e) => this._onChangeEvent(e))
}
/**
* Ajax callback for generating checksum hash.
*/
async check(fileInfo, algorithmType) {
// skip call if fileInfo is null
if(null == fileInfo) {
this.updateDisplay({
response: 'error',
msg: t('checksum', 'No fileinfo provided.')
})
return
}
const url = generateUrl('/apps/checksum/check')
const params = {source: fileInfo.path + fileInfo.name, type: algorithmType}
const {data} = await axios.get(url, {params})
this.updateDisplay(data, algorithmType)
}
/**
* Display message from ajax callback.
*/
updateDisplay(data, algorithmType) {
let msg = ''
if('success' == data.response) {
msg = algorithmType + ': ' + data.msg
}
if('error' == data.response) {
msg = data.msg
}
msg += '<br><br><a id="reload-checksum" class="icon icon-history" style="display:block" href=""></a>'
this.$el.find('.get-checksum').html(msg)
this.$el.find('#reload-checksum').click((e) => this._onReloadEvent(e))
}
/**
* Handle algorithm change.
*/
_onChangeEvent(ev) {
var algorithmType = $(ev.currentTarget).val()
if(algorithmType != '') {
this.$el.html('<div style="text-align:center word-wrap:break-word" class="get-checksum"><p><img src="'
+ imagePath('core','loading.gif')
+ '"><br><br></p><p>'
+ t('checksum', 'Creating Checksum ...')
+ '</p></div>')
this.check(this.getFileInfo(), algorithmType)
}
}
/**
* Handle form reset.
*/
_onReloadEvent(ev) {
ev.preventDefault()
this._renderSelectList(this.$el)
}
}
|