Commit fabade03 authored by Medicean's avatar Medicean

v2.0::Picture preview

parent dc237eae
......@@ -34,6 +34,10 @@ class Conf {
fs.readFileSync(_oldPath)
)
}
// 初始化目录
this.tmpPath;
this.cachePath;
this.plugPath;
}
/**
......
......@@ -283,13 +283,6 @@ class Files {
id.toLowerCase().endsWith(`.${e}`) ? isEdited = true : 0;
}
);
// 可预览文件后缀
let isPreviewed = false;
'jpg,png,gif,bmp,ico,mp4,mp3,wav,avi,rmvb'.split(',').map(
(e) => {
id.toLowerCase().endsWith(`.${e}`) ? isPreviewed = true : 0;
}
);
let menu = [
{ text: LANG['grid']['contextmenu']['refresh'], icon: 'fa fa-refresh', action: () => { self.refreshPath(); } },
......@@ -313,9 +306,9 @@ class Files {
} );
} },
{ text: LANG['grid']['contextmenu']['paste']['title'], icon: 'fa fa-paste', disabled: _Clipboard_num === 0, subMenu: _Clipboard },
// { text: LANG['grid']['contextmenu']['preview'], icon: 'fa fa-eye', disabled: !id || ids.length > 1 || !isPreviewed, action: () => {
// manager.previewFile(id);
// } },
{ text: LANG['grid']['contextmenu']['preview'], icon: 'fa fa-eye', disabled: !id || ids.length > 1 || !self.checkPreview(id), action: () => {
manager.previewFile(id, this.getRowAttribute(_ids[0], 'fsize'));
} },
{ divider: true },
{ text: LANG['grid']['contextmenu']['edit'], icon: 'fa fa-edit', disabled: /*!isEdited || */!id || ids.length > 1 || isFolder, action: () => {
manager.editFile(id);
......@@ -348,13 +341,20 @@ class Files {
});
// 双击文件
// :如果可预览并且小于 1MB,则进行预览
// :如果size < 100kb,则进行编辑,否则进行下载
grid.attachEvent('onRowDblClicked', (id, lid, event) => {
const fname = grid.getRowAttribute(id, 'fname');
const fsize = grid.getRowAttribute(id, 'fsize');
if (!fname.endsWith('/')) {
// 双击编辑size < 100kb 文件
fsize <= 100 * 1024 ? manager.editFile(fname) : manager.downloadFile(fname, fsize);
if(self.checkPreview(fname) && fsize <= 1000 * 1024){
manager.previewFile(fname, fsize);
}else if(fsize <= 100 * 1024){
// 双击编辑size < 100kb 文件
manager.editFile(fname);
}else{
manager.downloadFile(fname, fsize);
}
}else{
self.gotoPath(fname);
}
......@@ -388,6 +388,17 @@ class Files {
});
}
checkPreview(name) {
// 可预览文件后缀
let isPreviewed = false;
'jpg,png,gif,bmp,ico'.split(',').map(
(e) => {
name.toLowerCase().endsWith(`.${e}`) ? isPreviewed = true : 0;
}
);
return isPreviewed;
}
// 刷新当前目录
// 如果传递路径参数,则刷新该路径下的文件,不跳转,否则刷新&&跳转
refreshPath(p) {
......
......@@ -13,6 +13,8 @@ const ENCODES = require('../../base/encodes');
const fs = require('fs');
const iconv = require('iconv-lite');
const crypto = require('crypto');
const mime = require("mime");
const PATH = require("path");
const dialog = antSword.remote.dialog;
// 加载语言模板
......@@ -468,25 +470,45 @@ class FileManager {
}
// 预览文件(图片、视频)
previewFile(name) {
const path = this.path + name;
const win = this.createWin({
title: 'Preview File: ' + path
previewFile(name, size) {
let that = this;
const remote_path = this.path + name;
const win = that.createWin({
title: 'Loading File: ' + remote_path,
width: 800,
height: 600,
});
var filemime = mime.lookup(name);
let savepath = PATH.join(process.env.AS_WORKDIR,`antData/.temp/`,new Buffer(name).toString("hex"));
win.cell.lastChild['style']['overflow'] = 'scroll';
win.cell.lastChild['style']['textAlign'] = 'center';
let data = 'data:image/png;base64,';
let buff = '';
this.core.request(
this.core.filemanager.download_file()
, (chunk) => {
buff += chunk;
let imgData = data + new Buffer(buff).toString('base64');
let down_size = 0;
this.core.download(
savepath
,this.core.filemanager.read_file({path: remote_path})
, (_size) => {
down_size += _size;
let down_progress = parseInt(parseFloat(down_size / size).toFixed(2) * 100);
if (!(down_progress % 5)) {
win.setText(`Preview File: ${remote_path} ${down_progress}%`);
};
}
).then((_size) => {
if (_size === size) {
win.setText(`Preview File: ${remote_path}`);
let buff = fs.readFileSync(savepath);
switch (filemime){
default:
let data = new Buffer(buff).toString('base64');
win.attachHTMLString(`<img style="width:100%" src="data:/${filemime};base64,${data}"/>`);
break;
}
fs.unlink(savepath);
}else{
fs.unlink(savepath);
throw Error(`Load Error: downsize ${_size} != ${size}`);
}
).then((res) => {
let imgData = new Buffer(res['buff']).toString('base64');
win.attachHTMLString(`<img src="data:/image/png;base64,${imgData}"/>`);
}).catch((err) => {
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment