How to use the clipboard.readImage function in clipboard

To help you get started, we’ve selected a few clipboard examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TevinLi / amWiki / lib / richPaste.js View on Github external
}
        //读取数据
        let imgbuffer = null;
        let ext = 'png';
        if (type === 'file') {
            filePath = filePath.substr(8);   //截去 file:/// 协议头
            try {
                imgbuffer = fs.readFileSync(filePath, 'binary');
                ext = filePath.split(/[?#]/)[0].match(/\.([^\.\/]*?)$/);
                ext = ext ? ext[1] : 'png';
            } catch (e) {
                callback && callback(false);
                return;
            }
        } else if (type === 'clip') {
            const img = clipboard.readImage();
            if (img.isEmpty()) {
                callback && callback(false);
                return;
            }
            imgbuffer = img.toPng();
        }
        //计算路径
        const [assetsDirPath, createDirPath, insertText] = this.getPastePaths();
        if (!assetsDirPath) {
            callback && callback(false);
            return;
        }
        //计算文件名
        let filename = '';
        //按天区分文件
        const date = new Date();