INNER CODE UNIT · JavaScript

processFile

wangshengithub/staticshield · encrypt.js:63

async function processFile(file, password, args) {
  if (!fs.existsSync(file)) throw new Error('文件不存在: ' + file);
  const baseDir = path.dirname(path.resolve(file));
  let html = fs.readFileSync(file, 'utf8');
  const stats = {};
  if (args.bundle) {
    html = bundleHtml(html, baseDir, stats);
    const total = stats.css + stats.js + stats.img + stats.icon + stats.import;
    console.log('  打包:内联 ' + total + ' 个资源(css ' + stats.css + ' / js ' + stats.js + ' / 图片 ' + stats.img + ' / favicon ' + stats.icon + ' / @import ' + stats.import + ')');
  }
  const title = extractTitle(html);
  let logo = '';
  if (args.logo) { if (!fs.existsSync(args.logo)) throw new Error('Logo 文件不存在: ' + args.logo); logo = fileToDataUri(args.logo); }
  else logo = await extractLogo(html, baseDir);
  const meta = await crypto.encryptHtml(html, password, { useSha512: args.sha512 });
  meta.hint = args.hint || ''; meta.title = title || ''; meta.logo = logo || '';
  if (args.remember !== null && args.remember !== undefined) meta.rememberDays = args.remember;
  return meta;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…