<commit_before>const express = require('express');
const router = express.Router();
const fs = require('fs');
const path = require('path');
const Log = require('../controls/judgelog');
const UserLog = require('../controls/userlog');

const submitPath = path.join(process.cwd(), 'data', 'submit');

const rateLimiter = require('../controls/rate-limiter')({
	// Allow 3 submits, then slows down
	freeRetries: 30,
	minWait: 2 * 60 * 60,
	maxWait: 2 * 60 * 60,
	lifetime: 60 * 60
});

router.post('/', rateLimiter.prevent, (req, res, next) => {
	if (!req.user) {
		let err = new Error('You have to login first');
		err.code = 403;
		return next(err);
	}
	let q = req.body;
	if (!q.problem || !q.ext || !q.content) {
		return next(new Error('Invalid request'));
	}
	// Clean logs before writing
	Log.setLog(req.user.username, q.problem, q.ext, {
		created: new Date(),
		content: {
			verdict: '',
			details: []
		}
	});
	UserLog.addScore(req.user.username, q.problem, { });
	UserLog.addSubmit(req.user.username, `0[${req.user.username}][${q.problem}]${q.ext}`, q.content);
	fs.writeFile(path.join(submitPath, `0[${req.user.username}][${q.problem}]${q.ext}`), q.content, err => {
		if (err) return next(err);
		res.json(true);<commit_msg>Avoid confusion of problem name<commit_after>const express = require('express');
const router = express.Router();
const fs = require('fs');
const path = require('path');
const Log = require('../controls/judgelog');
const UserLog = require('../controls/userlog');

const submitPath = path.join(process.cwd(), 'data', 'submit');

const rateLimiter = require('../controls/rate-limiter')({
	// Allow 3 submits, then slows down
	freeRetries: 30,
	minWait: 2 * 60 * 60,
	maxWait: 2 * 60 * 60,
	lifetime: 60 * 60
});

router.post('/', rateLimiter.prevent, (req, res, next) => {
	if (!req.user) {
		let err = new Error('You have to login first');
		err.code = 403;
		return next(err);
	}
	let q = req.body;
	if (!q.problem || !q.ext || !q.content) {
		return next(new Error('Invalid request'));
	}
	q.ext = q.ext.toLowerCase();
	q.problem = q.problem.toUpperCase();
	// Clean logs before writing
	Log.setLog(req.user.username, q.problem, q.ext, {
		created: new Date(),
		content: {
			verdict: '',
			details: []
		}
	});
	UserLog.addScore(req.user.username, q.problem, { });
	UserLog.addSubmit(req.user.username, `0[${req.user.username}][${q.problem}]${q.ext}`, q.content);
	fs.writeFile(path.join(submitPath, `0[${req.user.username}][${q.problem}]${q.ext}`), q.content, err => {
		if (err) return next(err);
		res.json(true);
{'fraction_non_alphanumeric': 0.20516836335160532, 'fraction_numerical': 0.017227877838684416, 'mean_word_length': 4.224948875255624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3575663', 'n_tokens_mistral': 992, 'n_tokens_neox': 917, 'n_words': 211}