<commit_before>const only = require('only')
const fse = require('fs-extra')
const path = require('path')
const config = require('../config')
const Problem = require('../models/Problem')
const Solution = require('../models/Solution')
const logger = require('../utils/logger')
const { isLogined, isAdmin } = require('../utils/helper')

const preload = async (ctx, next) => {
  const pid = parseInt(ctx.params.pid)
  if (isNaN(pid)) ctx.throw(400, 'Pid has to be a number')
  const problem = await Problem.findOne({ pid }).exec()
  if (problem == null) ctx.throw(400, 'No such a problem')
  if (!isAdmin(ctx.session.profile) && problem.status === config.status.Reserve) {
    ctx.throw(400, 'You do not have permission to enter this problem!')
  }
  ctx.state.problem = problem
  return next()
}

// 返回题目列表
const find = async (ctx) => {
  const opt = ctx.request.query
  const filter = {}
  const page = parseInt(opt.page) || 1
  const pageSize = parseInt(opt.pageSize) || 30<commit_msg>fix: ordinary users can't see hidden problem in contest<commit_after>const only = require('only')
const fse = require('fs-extra')
const path = require('path')
const config = require('../config')
const Problem = require('../models/Problem')
const Solution = require('../models/Solution')
const Contest = require('../models/Contest')
const logger = require('../utils/logger')
const { isLogined, isAdmin } = require('../utils/helper')

const preload = async (ctx, next) => {
  const opt = ctx.request.query
  const pid = parseInt(opt.pid)
  const cid = parseInt(opt.cid) || 0
  if (isNaN(pid)) ctx.throw(400, 'Pid has to be a number')
  const problem = await Problem.findOne({ pid }).exec()
  if (problem == null) ctx.throw(400, 'No such a problem')
  if (isAdmin(ctx.session.profile)) {
    return next()
  }
  if (cid > 0) {
    const contest = await Contest.findOne({ cid }).exec()
    if (contest.start > Date.now() || (contest.encrypt !== config.encrypt.Public && ctx.session.profile.verifyContest.indexOf(contest.cid) === -1)) {
      ctx.throw(400, 'You do not have permission to enter this problem!')
    }
    if (contest.encrypt === config.encrypt.Public && ctx.session.profile.verifyContest.indexOf(contest.cid) === -1) {
      ctx.session.profile.verifyContest.push(contest.cid)
    }
    ctx.state.problem = problem
    return next()
  }
  if (problem.status === config.status.Reserve) {
    ctx.throw(400, 'You do not have permission to enter this problem!')
  }
  ctx.state.problem = problem
  return next()
}

// 返回题目列表
const find = async (ctx) => {
  const opt = ctx.request.query
  const filter = {}
  const page = parseInt(opt.page) || 1
  const pageSize = parseInt(opt.pageSize) || 30
{'fraction_non_alphanumeric': 0.16238361266294227, 'fraction_numerical': 0.01154562383612663, 'mean_word_length': 3.7964285714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '199123', 'n_tokens_mistral': 886, 'n_tokens_neox': 864, 'n_words': 240}