<commit_before>/* eslint no-console: 0 */

const http = require('http');
const express = require('express');
const compression = require('compression');

const config = require('./config');
const moedoo = require('./lib/moedoo')(process.env.DATABASE_URL || {
  DB_USER: config.DB_USER,
  DB_PASSWORD: config.DB_PASSWORD,
  DB_HOST: config.DB_HOST,
  DB_PORT: config.DB_PORT,
  DB_NAME: config.DB_NAME,
});
const a = require('./lib/a')(moedoo);
const posterCache = require('./lib/posterCache');

moedoo.query(`
  CREATE TABLE IF NOT EXISTS detail(
    detail character varying(1024) NOT NULL,
    video character varying(1024),
    CONSTRAINT detail_pk PRIMARY KEY (detail)
  );

  CREATE TABLE IF NOT EXISTS omdb(
    title character varying(128) NOT NULL,
    detail jsonb,
    CONSTRAINT movie_pk PRIMARY KEY (title)
  );

  CREATE TABLE IF NOT EXISTS poster(
    url character varying(1024) NOT NULL,
    poster text,
    CONSTRAINT poster_pk PRIMARY KEY (url)
  );`).then(() => {
    const app = express();
    app.set('port', process.env.PORT || config.APP_PORT);
    app.use(compression());

    // API...
    app.get('/api', (request, response) => {
      a().then((info) => {
        response.status(200).json(info).end();
      });
    });

    // Poster...
    app.get('/poster', (request, response) => {
      if (Object.prototype.hasOwnProperty.call(request.query, 'url')) {
        posterCache(moedoo, request.query.url)
          .then((base64) => {
            response
              .set('Content-Type', 'text/plain')<commit_msg>all entries are now deleted after 30 days<commit_after>/* eslint no-console: 0 */

const http = require('http');
const express = require('express');
const compression = require('compression');
const moment = require('moment');

const config = require('./config');
const moedoo = require('./lib/moedoo')(process.env.DATABASE_URL || {
  DB_USER: config.DB_USER,
  DB_PASSWORD: config.DB_PASSWORD,
  DB_HOST: config.DB_HOST,
  DB_PORT: config.DB_PORT,
  DB_NAME: config.DB_NAME,
});
const a = require('./lib/a')(moedoo);
const posterCache = require('./lib/posterCache');

moedoo.query(`
  CREATE TABLE IF NOT EXISTS detail(
    detail character varying(1024) NOT NULL,
    video character varying(1024),
    created_at Date DEFAULT now(),
    CONSTRAINT detail_pk PRIMARY KEY (detail)
  );

  CREATE TABLE IF NOT EXISTS omdb(
    title character varying(128) NOT NULL,
    detail jsonb,
    created_at Date DEFAULT now(),
    CONSTRAINT movie_pk PRIMARY KEY (title)
  );

  CREATE TABLE IF NOT EXISTS poster(
    url character varying(1024) NOT NULL,
    poster text,
    created_at Date DEFAULT now(),
    CONSTRAINT poster_pk PRIMARY KEY (url)
  );

  -- the following three can be one
  DELETE FROM detail WHERE created_at < '${moment().subtract(30, 'days').format('YYYY-MM-DD')}';
  DELETE FROM omdb WHERE created_at < '${moment().subtract(30, 'days').format('YYYY-MM-DD')}';
  DELETE FROM poster WHERE created_at < '${moment().subtract(30, 'days').format('YYYY-MM-DD')}';`).then(() => {
    const app = express();
    app.set('port', process.env.PORT || config.APP_PORT);
    app.use(compression());

    // API...
    app.get('/api', (request, response) => {
      a().then((info) => {
        response.status(200).json(info).end();
      });
    });

    // Poster...
    app.get('/poster', (request, response) => {
      if (Object.prototype.hasOwnProperty.call(request.query, 'url')) {
        posterCache(moedoo, request.query.url)
          .then((base64) => {
            response
              .set('Content-Type', 'text/plain')
{'fraction_non_alphanumeric': 0.15880547027630476, 'fraction_numerical': 0.013954786491766676, 'mean_word_length': 3.3180722891566266, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4448195', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1135, 'n_words': 283}