Example #1
0
	function ensureNoPrevExec(code: string): string {
		return `(() => {
			if (window['${md5(code)}'] === true) {
				return;
			}
			window['${md5(code)}'] = true;
			
			${code}
		})()`;
	}
 const objs = contents.map((content, index) => ({
   objectID: index ? md5(`${href}${index}`) : md5(href),
   fileName,
   repo: repoName,
   categories: file
     .split('/')
     .filter(
       c => Number.isNaN(parseInt(c, 10)) && c.indexOf('.md') === -1
     ),
   href,
   desc,
   content
 }));
Example #3
0
 static async checkPasswordMd5() {
   console.log('  checkPasswordMd5')
   const users = await User.findAll()
   if (users.length === 0 || isMd5(users[0].password)) {
     console.log('  users empty or md5 check passed')
     return
   }
   for (const user of users) {
     if (!isMd5(user.password)) {
       user.password = md5(md5(user.password))
       await user.save()
       console.log(`handle user ${user.id}`)
     }
   }
 }
Example #4
0
export const getComponentScreenshot = (componentId: string, previewName: string, state: ApplicationState) => {
  const ss = state.componentScreenshots[state.componentScreenshots.length - 1];
  const clippingNamespace = getPreviewClippingNamespace(componentId, previewName);
  return ss && ss.clippings[clippingNamespace] && {
    previewName,
    uri: `http://localhost:${state.options.port}/screenshots/${md5(state.componentScreenshots[state.componentScreenshots.length - 1].uri)}`,
    clip: ss.clippings[clippingNamespace]
  };
};
Example #5
0
function* getIndex(req: Request, res: Response) {
  let state: ExtensionState = yield select();

  if (!state.childDevServerInfo) {
    yield put(startDevServerRequest());
    yield take(CHILD_DEV_SERVER_STARTED);
    state = yield select();
  }

  const { getEntryHTML } = require(getTandemDirectory(state));

  res.send(getEntryHTML({
    apiHost: `http://localhost:${state.childDevServerInfo.port}`,
    textEditorHost: `http://localhost:${state.port}`,
    storageNamespace: md5(state.rootPath),
    filePrefix: "/tandem"
  }));
}
function getGeneratedMetricHash(title: string, format: string, expression: string) {
    return md5(`${expression}#${title}#${format}`);
}
Example #7
0
export const getEmailHash = (email: string) => {
  return email && md5(email.trim().toLowerCase());
}
export function grapherUrlToFilekey(grapherUrl: string) {
    const url = parseUrl(grapherUrl)
    const slug = _.last(url.pathname.split('/')) as string
    const queryStr = url.query as any
    return `${slug}${queryStr ? "-"+md5(queryStr) : ""}`
}
Example #9
0
 return state.componentScreenshots.find((screenshot) => md5(screenshot.uri) === req.params.screenshotHash);
export async function buildLinkIndex(client) {
  const index = client.initIndex('link');

  // 设置相关性

  index.setSettings({
    searchableAttributes: ['title', 'fileName', 'categories', 'desc', 'href'],
    attributesForFaceting: ['year', 'type', 'categories']
  });

  const repoName = 'Awesome-Lists';

  // 获取仓库的配置信息
  const repo: ReposityConfig = repos[repoName];

  const files = walkSync(repo.localPath).filter(
    path =>
      path.endsWith('.md') &&
      path.indexOf('README') === -1 &&
      path.indexOf('ABOUT') === -1 &&
      path.indexOf('Weekly') === -1
  );

  // 待提交到 Algo 的对象
  let pendingObjs = [];

  for (let file of files) {
    // 封装出文件链接
    const fileHref = `${repo.sUrl}/blob/master/${file}`;
    const absoluteFile = `${repo.localPath}/${file}`;
    let fileName: string = file.split('/').reverse()[0];

    // 读取文件内容
    const content = await readFileAsync(absoluteFile, { encoding: 'utf-8' });

    if (!content) {
      continue;
    }

    let match;

    while ((match = LinkRegex.exec(content))) {
      const [raw, rawTitle, href, desc] = match;

      // 这里进行过滤,过滤掉 URL 重复的部分
      if (!href || bloom.has(href)) {
        continue;
      }

      const { year, title, type } = extractInfoFromTitle(rawTitle);

      bloom.add(href);
      count++;

      const obj: LinkItem = {
        objectID: md5(href),
        title,
        href,
        desc: desc ? desc.replace(':', '').trim() : '',
        raw,

        year,
        type,

        fileName: fileName.split('.')[0],
        fileHref,
        categories: file
          .split('/')
          .filter(c => Number.isNaN(parseInt(c, 10)) && c.indexOf('.md') === -1)
      };

      pendingObjs.push(obj);

      if (pendingObjs.length >= BatchNum) {
        try {
          await index.addObjects(pendingObjs);
          pendingObjs = [];
        } catch (e) {
          console.error(e);
        }
      }
    }

    // 提交剩余的
    if (pendingObjs.length > 0) {
      try {
        await index.addObjects(pendingObjs);
        pendingObjs = [];
      } catch (e) {
        console.error(e);
      }
    }
  }

  console.log(`${repoName} indexed finally. ${count} links`);
}