Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getIconDataUrl() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const faviconSvg = (await jetpack.readAsync(paths.from.icon))!;
// http://codepen.io/jakob-e/pen/doMoML
return faviconSvg
.replace(/"/g, '\'')
.replace(/%/g, '%25')
.replace(/#/g, '%23')
.replace(/{/g, '%7B')
.replace(/}/g, '%7D')
.replace(//g, '%3E')
.replace(/\s+/g, ' ');
}
Seems we finally got the last part of a chunk upload
*/
const uploadsDir = path.join(__dirname, '..', '..', '..', '..', process.env.UPLOAD_FOLDER);
const chunkedFileDir = path.join(__dirname, '..', '..', '..', '..', process.env.UPLOAD_FOLDER, 'chunks', file.body.uuid);
const chunkFiles = await jetpack.findAsync(chunkedFileDir, { matching: '*' });
const originalname = Util.getFilenameFromPath(chunkFiles[0].substring(0, chunkFiles[0].lastIndexOf('.')));
const tempFile = {
filename: Util.getUniqueFilename(originalname),
originalname,
size: file.body.totalfilesize
};
for (const chunkFile of chunkFiles) {
try {
const data = await jetpack.readAsync(chunkFile, 'buffer'); // eslint-disable-line no-await-in-loop
await jetpack.appendAsync(path.join(uploadsDir, tempFile.filename), data); // eslint-disable-line no-await-in-loop
} catch (error) {
log.error(error);
}
}
try {
await jetpack.removeAsync(chunkedFileDir);
} catch (error) {
log.error(error);
}
upload = tempFile;
}
/*
async function serveICO (path, size = 16) {
// read the file
const data = await jetpack.readAsync(path, 'buffer')
// parse the ICO to get the 16x16
const images = await ICO.parse(data, 'image/png')
let image = images[0]
for (let i = 1; i < images.length; i++) {
if (Math.abs(images[i].width - size) < Math.abs(image.width - size)) {
image = images[i]
}
}
// serve
cb(200, 'OK', 'image/png', () => Buffer.from(image.buffer))
}
const htmlPromises = htmlPaths.map(async htmlPath => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const template = (await jetpack.readAsync(htmlPath))!;
const minified = htmlMinifier.minify(template, { collapseWhitespace: true });
return ``;
});
return (await Promise.all(htmlPromises)).join('\r\n');
const files = task('files', async () => {
await jetpack.copyAsync('./README.md', 'dist/README.md', { overwrite: true });
const packageJson = JSON.parse((await jetpack.readAsync('./package.json'))!);
// cannot be specified in current package.json due to https://github.com/TypeStrong/ts-node/issues/935
// which is fine, from perspective of the project itself it's TypeScript, so type=module is irrelevant
// only the output (dist) is JS modules
packageJson.type = 'module';
await jetpack.writeAsync('dist/package.json', JSON.stringify(packageJson, null, 4));
}, { watch: ['./README.md', './package.json'] });
static async getFileHash(filename) {
const file = await jetpack.readAsync(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, filename), 'buffer');
if (!file) {
log.error(`There was an error reading the file < ${filename} > for hashing`);
return null;
}
const hash = crypto.createHash('md5');
hash.update(file, 'utf8');
return hash.digest('hex');
}
export async function uploadFavicon () {
let favicon = dialog.showOpenDialog({
title: 'Upload Favicon...',
defaultPath: app.getPath('home'),
buttonLabel: 'Upload Favicon',
filters: [
{ name: 'Images', extensions: ['png', 'ico', 'jpg'] }
],
properties: ['openFile']
})
if (!favicon) return
let faviconBuffer = await jetpack.readAsync(favicon[0], 'buffer')
let extension = path.extname(favicon[0])
if (extension === '.png') {
return toIco(faviconBuffer, {resize: true})
}
if (extension === '.jpg') {
let imageToPng = nativeImage.createFromBuffer(faviconBuffer).toPNG()
return toIco(imageToPng, {resize: true})
}
if (extension === '.ico' && ICO.isICO(faviconBuffer)) {
return faviconBuffer
}
}
getToken () {
return fs.readAsync(this.storageFile)
}
async function readPingData () {
var data = await jetpack.readAsync(path.join(app.getPath('userData'), ANALYTICS_DATA_FILE), 'json')
return data || {lastPingTime: 0, id: crypto.randomBytes(32).toString('hex')}
}