<commit_before>import React from 'react';
import Document, {
  Head,
  Main,
  NextScript,
  NextDocumentContext,
} from 'next/document';
import { ServerStyleSheet } from 'styled-components';
import crypto from 'crypto';

interface Props {
  styles: string;
  locale: string;
  localeDataScript: string;
}

const cspHashOf = (text: string) => {
  const hash = crypto.createHash('sha256');
  hash.update(text);
  return `'sha256-${hash.digest('base64')}'`;
};

class MyDocument extends Document<Props> {
  static async getInitialProps(context: NextDocumentContext) {
    // styled-components
    const sheet = new ServerStyleSheet();

    const originalRenderPage = context.renderPage;
    context.renderPage = () =>
      originalRenderPage({
        // @ts-ignore
        enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
      });

    const initialProps = await Document.getInitialProps(context);
    // react-intl

    const {
      // @ts-ignore
      req: { locale, localeDataScript },
    } = context;

    return {
      ...initialProps,
      locale,
      localeDataScript,
      // @ts-ignore
      styles: [...initialProps.styles, ...sheet.getStyleElement()],
    };
  }

  render() {
    const { locale, styles, localeDataScript } = this.props;
    const features = ['default', 'Intl', `Intl.~locale.${locale}`].join();
    const encodedFeatures = encodeURIComponent(features);
    const polyfill = `https://polyfill.io/v3/polyfill.min.js?flags=gated&features=${encodedFeatures}`;

    const cspSettings = [
      "default-src 'self'",
      "script-src 'self' https://polyfill.io/v3/polyfill.min.js 'unsafe-eval' 'unsafe-inline' https://www.google-analytics.com/analytics.js",
      "connect-src 'self' ws://localhost:*",
      "style-src 'self' 'unsafe-inline'",
      "img-src 'self' https://res.cloudinary.com/dof0zryca/",
    ];

    const csp = `${cspSettings.join(';')} ${cspHashOf(
      // @ts-ignore
      NextScript.getInlineScriptSource(this.props)
    )}`;
<commit_msg>add data: to img-src csp :skull:<commit_after>import React from 'react';
import Document, {
  Head,
  Main,
  NextScript,
  NextDocumentContext,
} from 'next/document';
import { ServerStyleSheet } from 'styled-components';
import crypto from 'crypto';

interface Props {
  styles: string;
  locale: string;
  localeDataScript: string;
}

const cspHashOf = (text: string) => {
  const hash = crypto.createHash('sha256');
  hash.update(text);
  return `'sha256-${hash.digest('base64')}'`;
};

class MyDocument extends Document<Props> {
  static async getInitialProps(context: NextDocumentContext) {
    // styled-components
    const sheet = new ServerStyleSheet();

    const originalRenderPage = context.renderPage;
    context.renderPage = () =>
      originalRenderPage({
        // @ts-ignore
        enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
      });

    const initialProps = await Document.getInitialProps(context);
    // react-intl

    const {
      // @ts-ignore
      req: { locale, localeDataScript },
    } = context;

    return {
      ...initialProps,
      locale,
      localeDataScript,
      // @ts-ignore
      styles: [...initialProps.styles, ...sheet.getStyleElement()],
    };
  }

  render() {
    const { locale, styles, localeDataScript } = this.props;
    const features = ['default', 'Intl', `Intl.~locale.${locale}`].join();
    const encodedFeatures = encodeURIComponent(features);
    const polyfill = `https://polyfill.io/v3/polyfill.min.js?flags=gated&features=${encodedFeatures}`;

    const cspSettings = [
      "default-src 'self'",
      "script-src 'self' https://polyfill.io/v3/polyfill.min.js 'unsafe-eval' 'unsafe-inline' https://www.google-analytics.com/analytics.js",
      "connect-src 'self' ws://localhost:*",
      "style-src 'self' 'unsafe-inline'",
      "img-src 'self' https://res.cloudinary.com/dof0zryca/ data:",
    ];

    const csp = `${cspSettings.join(';')} ${cspHashOf(
      // @ts-ignore
      NextScript.getInlineScriptSource(this.props)
    )}`;

{'fraction_non_alphanumeric': 0.15815445349124105, 'fraction_numerical': 0.00542807796693807, 'mean_word_length': 3.196687370600414, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3699345', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1277, 'n_words': 252}