mirror of
https://github.com/lrsjng/h5ai
synced 2025-12-27 11:12:22 +01:00
Remove client-side sample request for img
* Down-sampling should only be requested by the backend. * For now remove the client-side logic entirely since it is both superfluous and vulnerable. This can be implemented again on the back-end if necessary.
This commit is contained in:
parent
ba6b01ab7c
commit
4a3dd108bd
2 changed files with 5 additions and 27 deletions
|
|
@ -234,11 +234,9 @@
|
|||
Show an image preview on click.
|
||||
|
||||
- types: array of strings
|
||||
- size: number, sample size, or false for original size
|
||||
*/
|
||||
"preview-img": {
|
||||
"enabled": true,
|
||||
"size": false,
|
||||
"types": ["img", "img-bmp", "img-gif", "img-ico", "img-jpg", "img-png", "img-raw", "img-svg"]
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
const {dom} = require('../../util');
|
||||
const server = require('../../server');
|
||||
const allsettings = require('../../core/settings');
|
||||
const preview = require('./preview');
|
||||
|
||||
const settings = Object.assign({
|
||||
enabled: false,
|
||||
size: null,
|
||||
types: []
|
||||
}, allsettings['preview-img']);
|
||||
const tpl = '<img id="pv-content-img"/>';
|
||||
|
|
@ -19,34 +17,16 @@ const updateGui = () => {
|
|||
const elW = el.offsetWidth;
|
||||
|
||||
const labels = [preview.item.label];
|
||||
if (!settings.size) {
|
||||
const elNW = el.naturalWidth;
|
||||
const elNH = el.naturalHeight;
|
||||
labels.push(String(elNW) + 'x' + String(elNH));
|
||||
labels.push(String((100 * elW / elNW).toFixed(0)) + '%');
|
||||
}
|
||||
preview.setLabels(labels);
|
||||
};
|
||||
const elNW = el.naturalWidth;
|
||||
const elNH = el.naturalHeight;
|
||||
labels.push(String(elNW) + 'x' + String(elNH));
|
||||
labels.push(String((100 * elW / elNW).toFixed(0)) + '%');
|
||||
|
||||
const requestSample = href => {
|
||||
return server.request({
|
||||
action: 'get',
|
||||
thumbs: [{
|
||||
type: 'img',
|
||||
href,
|
||||
width: settings.size,
|
||||
height: 0
|
||||
}]
|
||||
}).then(json => {
|
||||
return json && json.thumbs && json.thumbs[0] ? json.thumbs[0] : null;
|
||||
});
|
||||
preview.setLabels(labels);
|
||||
};
|
||||
|
||||
const load = item => {
|
||||
return Promise.resolve(item.absHref)
|
||||
.then(href => {
|
||||
return settings.size ? requestSample(href) : href;
|
||||
})
|
||||
.then(href => new Promise(resolve => {
|
||||
const $el = dom(tpl)
|
||||
.on('load', () => resolve($el))
|
||||
|
|
|
|||
Loading…
Reference in a new issue