diff --git a/.gitignore b/.gitignore index 40879a0..e912ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ config.json *.db .git.* package-lock.json -models-built # Logs logs diff --git a/models-built/article-comment.js b/models-built/article-comment.js new file mode 100644 index 0000000..70b6b62 --- /dev/null +++ b/models-built/article-comment.js @@ -0,0 +1,129 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var user_1 = require("./user"); +var article_1 = require("./article"); +var ArticleComment = /** @class */ (function (_super) { + __extends(ArticleComment, _super); + function ArticleComment() { + return _super !== null && _super.apply(this, arguments) || this; + } + ArticleComment.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + _a = this; + return [4 /*yield*/, user_1["default"].findById(this.user_id)]; + case 1: + _a.user = _c.sent(); + _b = this; + return [4 /*yield*/, article_1["default"].findById(this.article_id)]; + case 2: + _b.article = _c.sent(); + return [2 /*return*/]; + } + }); + }); + }; + ArticleComment.prototype.isAllowedEditBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.loadRelationships()]; + case 1: + _a.sent(); + return [2 /*return*/, user && (user.is_admin || this.user_id === user.id || user.id === this.article.user_id)]; + } + }); + }); + }; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], ArticleComment.prototype, "id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], ArticleComment.prototype, "content"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], ArticleComment.prototype, "article_id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], ArticleComment.prototype, "user_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], ArticleComment.prototype, "public_time"); + ArticleComment = __decorate([ + TypeORM.Entity() + ], ArticleComment); + return ArticleComment; +}(common_1["default"])); +exports["default"] = ArticleComment; +; +//# sourceMappingURL=article-comment.js.map \ No newline at end of file diff --git a/models-built/article-comment.js.map b/models-built/article-comment.js.map new file mode 100644 index 0000000..2bdbe36 --- /dev/null +++ b/models-built/article-comment.js.map @@ -0,0 +1 @@ +{"version":3,"file":"article-comment.js","sourceRoot":"","sources":["../models/article-comment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAE7B,+BAA0B;AAC1B,qCAAgC;AAGhC;IAA4C,kCAAK;IAAjD;;IA8BA,CAAC;IATO,0CAAiB,GAAvB;;;;;;wBACE,KAAA,IAAI,CAAA;wBAAQ,qBAAM,iBAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAA;;wBAA7C,GAAK,IAAI,GAAG,SAAiC,CAAC;wBAC9C,KAAA,IAAI,CAAA;wBAAW,qBAAM,oBAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAA;;wBAAtD,GAAK,OAAO,GAAG,SAAuC,CAAC;;;;;KACxD;IAEK,wCAAe,GAArB,UAAsB,IAAI;;;;4BACxB,qBAAM,IAAI,CAAC,iBAAiB,EAAE,EAAA;;wBAA9B,SAA8B,CAAC;wBAC/B,sBAAO,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAC;;;;KAChG;IA3BD;QADC,OAAO,CAAC,sBAAsB,EAAE;;sCACtB;IAGX;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;2CACjC;IAIhB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;8CACjC;IAInB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;2CACpC;IAGhB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;+CAChC;IAhBD,cAAc;QADlC,OAAO,CAAC,MAAM,EAAE;OACI,cAAc,CA8BlC;IAAD,qBAAC;CAAA,AA9BD,CAA4C,mBAAK,GA8BhD;qBA9BoB,cAAc;AA8BlC,CAAC"} \ No newline at end of file diff --git a/models-built/article.js b/models-built/article.js new file mode 100644 index 0000000..8406171 --- /dev/null +++ b/models-built/article.js @@ -0,0 +1,194 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var user_1 = require("./user"); +var article_comment_1 = require("./article-comment"); +var Article = /** @class */ (function (_super) { + __extends(Article, _super); + function Article() { + return _super !== null && _super.apply(this, arguments) || this; + } + Article.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = this; + return [4 /*yield*/, user_1["default"].findById(this.user_id)]; + case 1: + _a.user = _b.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Article.prototype.isAllowedEditBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, user && (user.is_admin || this.user_id === user.id)]; + }); + }); + }; + Article.prototype.isAllowedCommentBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, user && (this.allow_comment || user.is_admin || this.user_id === user.id)]; + }); + }); + }; + Article.prototype.resetReplyCountAndTime = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['Article::resetReplyCountAndTime', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + _a = this; + return [4 /*yield*/, article_comment_1["default"].count({ article_id: this.id })]; + case 1: + _a.comments_num = _c.sent(); + if (!(this.comments_num === 0)) return [3 /*break*/, 2]; + this.sort_time = this.public_time; + return [3 /*break*/, 4]; + case 2: + _b = this; + return [4 /*yield*/, article_comment_1["default"].findOne({ + where: { article_id: this.id }, + order: { public_time: "DESC" } + })]; + case 3: + _b.sort_time = (_c.sent()).public_time; + _c.label = 4; + case 4: return [4 /*yield*/, this.save()]; + case 5: + _c.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Article.cache = false; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], Article.prototype, "id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 80 }), + __metadata("design:type", String) + ], Article.prototype, "title"); + __decorate([ + TypeORM.Column({ nullable: true, type: "mediumtext" }), + __metadata("design:type", String) + ], Article.prototype, "content"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Article.prototype, "user_id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Article.prototype, "problem_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Article.prototype, "public_time"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Article.prototype, "update_time"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Article.prototype, "sort_time"); + __decorate([ + TypeORM.Column({ "default": 0, type: "integer" }), + __metadata("design:type", Number) + ], Article.prototype, "comments_num"); + __decorate([ + TypeORM.Column({ "default": true, type: "boolean" }), + __metadata("design:type", Boolean) + ], Article.prototype, "allow_comment"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], Article.prototype, "is_notice"); + Article = __decorate([ + TypeORM.Entity() + ], Article); + return Article; +}(common_1["default"])); +exports["default"] = Article; +; +//# sourceMappingURL=article.js.map \ No newline at end of file diff --git a/models-built/article.js.map b/models-built/article.js.map new file mode 100644 index 0000000..eb10fdf --- /dev/null +++ b/models-built/article.js.map @@ -0,0 +1 @@ +{"version":3,"file":"article.js","sourceRoot":"","sources":["../models/article.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAE7B,+BAA0B;AAE1B,qDAA+C;AAK/C;IAAqC,2BAAK;IAA1C;;IAqEA,CAAC;IA1BO,mCAAiB,GAAvB;;;;;;wBACE,KAAA,IAAI,CAAA;wBAAQ,qBAAM,iBAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAA;;wBAA7C,GAAK,IAAI,GAAG,SAAiC,CAAC;;;;;KAC/C;IAEK,iCAAe,GAArB,UAAsB,IAAI;;;gBACxB,sBAAO,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,EAAE,CAAC,EAAC;;;KAC5D;IAEK,oCAAkB,GAAxB,UAAyB,IAAI;;;gBAC3B,sBAAO,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,EAAE,CAAC,EAAC;;;KAClF;IAEK,wCAAsB,GAA5B;;;;;4BACE,qBAAM,KAAK,CAAC,KAAK,CAAC,IAAI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,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;uCACjC;IAGnB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCAChC;IAGpB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCAChC;IAIpB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;sCAClC;IAGlB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,SAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;yCAC3B;IAGrB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,SAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;0CAC5B;IAIvB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;sCACjC;IAtCA,OAAO;QAD3B,OAAO,CAAC,MAAM,EAAE;OACI,OAAO,CAqE3B;IAAD,cAAC;CAAA,AArED,CAAqC,mBAAK,GAqEzC;qBArEoB,OAAO;AAqE3B,CAAC"} \ No newline at end of file diff --git a/models-built/common.js b/models-built/common.js new file mode 100644 index 0000000..5c4c690 --- /dev/null +++ b/models-built/common.js @@ -0,0 +1,353 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var LRUCache = require("lru-cache"); +var DeepCopy = require("deepcopy"); +var PaginationType; +(function (PaginationType) { + PaginationType[PaginationType["PREV"] = -1] = "PREV"; + PaginationType[PaginationType["NEXT"] = 1] = "NEXT"; +})(PaginationType || (PaginationType = {})); +var PaginationIDOrder; +(function (PaginationIDOrder) { + PaginationIDOrder[PaginationIDOrder["ASC"] = 1] = "ASC"; + PaginationIDOrder[PaginationIDOrder["DESC"] = -1] = "DESC"; +})(PaginationIDOrder || (PaginationIDOrder = {})); +var caches = new Map(); +function ensureCache(modelName) { + if (!caches.has(modelName)) { + caches.set(modelName, new LRUCache({ + max: syzoj.config.db.cache_size + })); + } + return caches.get(modelName); +} +function cacheGet(modelName, id) { + return ensureCache(modelName).get(parseInt(id)); +} +function cacheSet(modelName, id, data) { + if (data == null) { + ensureCache(modelName).del(id); + } + else { + ensureCache(modelName).set(parseInt(id), data); + } +} +var Model = /** @class */ (function (_super) { + __extends(Model, _super); + function Model() { + return _super !== null && _super.apply(this, arguments) || this; + } + Model.findById = function (id) { + return __awaiter(this, void 0, void 0, function () { + var doQuery, resultObject, result; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + doQuery = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.findOne(parseInt(id) || 0)]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); }); }; + if (!this.cache) return [3 /*break*/, 2]; + resultObject = cacheGet(this.name, id); + if (resultObject) { + return [2 /*return*/, this.create(resultObject)]; + } + return [4 /*yield*/, doQuery()]; + case 1: + result = _a.sent(); + if (result) { + cacheSet(this.name, id, result.toPlain()); + } + return [2 /*return*/, result]; + case 2: return [4 /*yield*/, doQuery()]; + case 3: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Model.prototype.toPlain = function () { + var _this = this; + var object = {}; + TypeORM.getConnection().getMetadata(this.constructor).ownColumns.map(function (column) { return column.propertyName; }).forEach(function (key) { + object[key] = DeepCopy(_this[key]); + }); + return object; + }; + Model.prototype.destroy = function () { + return __awaiter(this, void 0, void 0, function () { + var id; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + id = this.id; + return [4 /*yield*/, TypeORM.getManager().remove(this)]; + case 1: + _a.sent(); + return [4 /*yield*/, this.constructor.deleteFromCache(id)]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Model.deleteFromCache = function (id) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + if (this.cache) { + cacheSet(this.name, id, null); + } + return [2 /*return*/]; + }); + }); + }; + Model.prototype.saveHook = function () { + return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/]; + }); }); + }; + Model.prototype.save = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.saveHook()]; + case 1: + _a.sent(); + return [4 /*yield*/, _super.prototype.save.call(this)]; + case 2: + _a.sent(); + if (this.constructor.cache) { + cacheSet(this.constructor.name, this.id, this); + } + return [2 /*return*/, this]; + } + }); + }); + }; + Model.countQuery = function (query) { + return __awaiter(this, void 0, void 0, function () { + var parameters, _a; + var _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + parameters = null; + if (typeof query !== 'string') { + _b = query.getQueryAndParameters(), query = _b[0], parameters = _b[1]; + } + _a = parseInt; + return [4 /*yield*/, TypeORM.getManager().query("SELECT COUNT(*) FROM (" + query + ") AS `__tmp_table`", parameters)]; + case 1: return [2 /*return*/, _a.apply(void 0, [(_c.sent())[0]['COUNT(*)']])]; + } + }); + }); + }; + Model.countForPagination = function (where) { + return __awaiter(this, void 0, void 0, function () { + var queryBuilder; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + queryBuilder = where instanceof TypeORM.SelectQueryBuilder + ? where + : this.createQueryBuilder().where(where); + return [4 /*yield*/, queryBuilder.getCount()]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Model.queryAll = function (queryBuilder) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, queryBuilder.getMany()]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Model.queryPage = function (paginater, where, order, largeData) { + if (largeData === void 0) { largeData = false; } + return __awaiter(this, void 0, void 0, function () { + var queryBuilder, rawResult; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!paginater.pageCnt) + return [2 /*return*/, []]; + queryBuilder = where instanceof TypeORM.SelectQueryBuilder + ? where + : this.createQueryBuilder().where(where); + if (order) + queryBuilder.orderBy(order); + queryBuilder.skip((paginater.currPage - 1) * paginater.perPage) + .take(paginater.perPage); + if (!largeData) return [3 /*break*/, 3]; + return [4 /*yield*/, queryBuilder.select('id').getRawMany()]; + case 1: + rawResult = _a.sent(); + return [4 /*yield*/, Promise.all(rawResult.map(function (result) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + return [2 /*return*/, this.findById(result.id)]; + }); }); }))]; + case 2: return [2 /*return*/, _a.sent()]; + case 3: return [2 /*return*/, queryBuilder.getMany()]; + } + }); + }); + }; + Model.queryPageFast = function (queryBuilder, _a, idOrder, pageType) { + var currPageTop = _a.currPageTop, currPageBottom = _a.currPageBottom, perPage = _a.perPage; + return __awaiter(this, void 0, void 0, function () { + var queryBuilderBak, result, _b, queryBuilderHasPrev, queryBuilderHasNext; + var _this = this; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + queryBuilderBak = queryBuilder.clone(); + result = { + meta: { + hasPrevPage: false, + hasNextPage: false, + top: 0, + bottom: 0 + }, + data: [] + }; + queryBuilder.take(perPage); + if (pageType === PaginationType.PREV) { + if (currPageTop != null) { + queryBuilder.andWhere("id " + (idOrder === PaginationIDOrder.DESC ? '>' : '<') + " :currPageTop", { currPageTop: currPageTop }); + queryBuilder.orderBy('id', idOrder === PaginationIDOrder.DESC ? 'ASC' : 'DESC'); + } + } + else if (pageType === PaginationType.NEXT) { + if (currPageBottom != null) { + queryBuilder.andWhere("id " + (idOrder === PaginationIDOrder.DESC ? '<' : '>') + " :currPageBottom", { currPageBottom: currPageBottom }); + queryBuilder.orderBy('id', idOrder === PaginationIDOrder.DESC ? 'DESC' : 'ASC'); + } + } + else + queryBuilder.orderBy('id', idOrder === PaginationIDOrder.DESC ? 'DESC' : 'ASC'); + _b = result; + return [4 /*yield*/, queryBuilder.getMany()]; + case 1: + _b.data = _c.sent(); + result.data.sort(function (a, b) { return (a.id - b.id) * idOrder; }); + if (result.data.length === 0) + return [2 /*return*/, result]; + queryBuilderHasPrev = queryBuilderBak.clone(), queryBuilderHasNext = queryBuilderBak; + result.meta.top = result.data[0].id; + result.meta.bottom = result.data[result.data.length - 1].id; + // Run two queries in parallel. + return [4 /*yield*/, Promise.all(([ + function () { return __awaiter(_this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = result.meta; + return [4 /*yield*/, queryBuilderHasPrev.andWhere("id " + (idOrder === PaginationIDOrder.DESC ? '>' : '<') + " :id", { + id: result.meta.top + }).take(1).getOne()]; + case 1: return [2 /*return*/, _a.hasPrevPage = !!(_b.sent())]; + } + }); + }); }, + function () { return __awaiter(_this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = result.meta; + return [4 /*yield*/, queryBuilderHasNext.andWhere("id " + (idOrder === PaginationIDOrder.DESC ? '<' : '>') + " :id", { + id: result.meta.bottom + }).take(1).getOne()]; + case 1: return [2 /*return*/, _a.hasNextPage = !!(_b.sent())]; + } + }); + }); } + ]).map(function (f) { return f(); }))]; + case 2: + // Run two queries in parallel. + _c.sent(); + return [2 /*return*/, result]; + } + }); + }); + }; + Model.queryRange = function (range, where, order) { + return __awaiter(this, void 0, void 0, function () { + var queryBuilder; + return __generator(this, function (_a) { + range[0] = parseInt(range[0]); + range[1] = parseInt(range[1]); + queryBuilder = where instanceof TypeORM.SelectQueryBuilder + ? where + : this.createQueryBuilder().where(where); + if (order) + queryBuilder.orderBy(order); + queryBuilder.skip(range[0] - 1) + .take(range[1] - range[0] + 1); + return [2 /*return*/, queryBuilder.getMany()]; + }); + }); + }; + Model.cache = false; + return Model; +}(TypeORM.BaseEntity)); +exports["default"] = Model; +//# sourceMappingURL=common.js.map \ No newline at end of file diff --git a/models-built/common.js.map b/models-built/common.js.map new file mode 100644 index 0000000..3e36df6 --- /dev/null +++ b/models-built/common.js.map @@ -0,0 +1 @@ +{"version":3,"file":"common.js","sourceRoot":"","sources":["../models/common.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,oCAAsC;AACtC,mCAAqC;AAUrC,IAAK,cAGJ;AAHD,WAAK,cAAc;IACjB,oDAAS,CAAA;IACT,mDAAQ,CAAA;AACV,CAAC,EAHI,cAAc,KAAd,cAAc,QAGlB;AAED,IAAK,iBAGJ;AAHD,WAAK,iBAAiB;IACpB,uDAAO,CAAA;IACP,0DAAS,CAAA;AACX,CAAC,EAHI,iBAAiB,KAAjB,iBAAiB,QAGrB;AAED,IAAM,MAAM,GAAyC,IAAI,GAAG,EAAE,CAAC;AAE/D,SAAS,WAAW,CAAC,SAAS;IAC5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QAC1B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,QAAQ,CAAC;YACjC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU;SAChC,CAAC,CAAC,CAAC;KACL;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,QAAQ,CAAC,SAAS,EAAE,EAAE;IAC7B,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC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AAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAE5D,IAAI,KAAK;oBAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAEvC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;qBAClB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAE3C,sBAAO,YAAY,CAAC,OAAO,EAAE,EAAC;;;KAC/B;IAlKM,WAAK,GAAG,KAAK,CAAC;IAmKvB,YAAC;CAAA,AApKD,CAAmC,OAAO,CAAC,UAAU,GAoKpD;qBApKoB,KAAK"} \ No newline at end of file diff --git a/models-built/contest.js b/models-built/contest.js new file mode 100644 index 0000000..b4c0dc4 --- /dev/null +++ b/models-built/contest.js @@ -0,0 +1,306 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var user_1 = require("./user"); +var problem_1 = require("./problem"); +var contest_ranklist_1 = require("./contest_ranklist"); +var contest_player_1 = require("./contest_player"); +var ContestType; +(function (ContestType) { + ContestType["NOI"] = "noi"; + ContestType["IOI"] = "ioi"; + ContestType["ICPC"] = "acm"; +})(ContestType || (ContestType = {})); +var Contest = /** @class */ (function (_super) { + __extends(Contest, _super); + function Contest() { + return _super !== null && _super.apply(this, arguments) || this; + } + Contest.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + _a = this; + return [4 /*yield*/, user_1["default"].findById(this.holder_id)]; + case 1: + _a.holder = _c.sent(); + _b = this; + return [4 /*yield*/, contest_ranklist_1["default"].findById(this.ranklist_id)]; + case 2: + _b.ranklist = _c.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Contest.prototype.isSupervisior = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, user && (user.is_admin || this.holder_id === user.id || this.admins.split('|').includes(user.id.toString()))]; + }); + }); + }; + Contest.prototype.allowedSeeingOthers = function () { + if (this.type === 'acm') + return true; + else + return false; + }; + Contest.prototype.allowedSeeingScore = function () { + if (this.type === 'ioi') + return true; + else + return false; + }; + Contest.prototype.allowedSeeingResult = function () { + if (this.type === 'ioi' || this.type === 'acm') + return true; + else + return false; + }; + Contest.prototype.allowedSeeingTestcase = function () { + if (this.type === 'ioi') + return true; + return false; + }; + Contest.prototype.getProblems = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + if (!this.problems) + return [2 /*return*/, []]; + return [2 /*return*/, this.problems.split('|').map(function (x) { return parseInt(x); })]; + }); + }); + }; + Contest.prototype.setProblemsNoCheck = function (problemIDs) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + this.problems = problemIDs.join('|'); + return [2 /*return*/]; + }); + }); + }; + Contest.prototype.setProblems = function (s) { + return __awaiter(this, void 0, void 0, function () { + var a; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + a = []; + return [4 /*yield*/, s.split('|').forEachAsync(function (x) { return __awaiter(_this, void 0, void 0, function () { + var problem; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, problem_1["default"].findById(x)]; + case 1: + problem = _a.sent(); + if (!problem) + return [2 /*return*/]; + a.push(x); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + this.problems = a.join('|'); + return [2 /*return*/]; + } + }); + }); + }; + Contest.prototype.newSubmission = function (judge_state) { + return __awaiter(this, void 0, void 0, function () { + var problems; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(judge_state.submit_time >= this.start_time && judge_state.submit_time <= this.end_time)) { + return [2 /*return*/]; + } + return [4 /*yield*/, this.getProblems()]; + case 1: + problems = _a.sent(); + if (!problems.includes(judge_state.problem_id)) + throw new ErrorMessage('当前比赛中无此题目。'); + return [4 /*yield*/, syzoj.utils.lock(['Contest::newSubmission', judge_state.user_id], function () { return __awaiter(_this, void 0, void 0, function () { + var player; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, contest_player_1["default"].findInContest({ + contest_id: this.id, + user_id: judge_state.user_id + })]; + case 1: + player = _a.sent(); + if (!!player) return [3 /*break*/, 4]; + return [4 /*yield*/, contest_player_1["default"].create({ + contest_id: this.id, + user_id: judge_state.user_id + })]; + case 2: + player = _a.sent(); + return [4 /*yield*/, player.save()]; + case 3: + _a.sent(); + _a.label = 4; + case 4: return [4 /*yield*/, player.updateScore(judge_state)]; + case 5: + _a.sent(); + return [4 /*yield*/, player.save()]; + case 6: + _a.sent(); + return [4 /*yield*/, this.loadRelationships()]; + case 7: + _a.sent(); + return [4 /*yield*/, this.ranklist.updatePlayer(this, player)]; + case 8: + _a.sent(); + return [4 /*yield*/, this.ranklist.save()]; + case 9: + _a.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Contest.prototype.isRunning = function (now) { + if (!now) + now = syzoj.utils.getCurrentDate(); + return now >= this.start_time && now < this.end_time; + }; + Contest.prototype.isEnded = function (now) { + if (!now) + now = syzoj.utils.getCurrentDate(); + return now >= this.end_time; + }; + Contest.cache = true; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], Contest.prototype, "id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 80 }), + __metadata("design:type", String) + ], Contest.prototype, "title"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Contest.prototype, "subtitle"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Contest.prototype, "start_time"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Contest.prototype, "end_time"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Contest.prototype, "holder_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "enum", "enum": ContestType }), + __metadata("design:type", String) + ], Contest.prototype, "type"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Contest.prototype, "information"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Contest.prototype, "problems"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Contest.prototype, "admins"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Contest.prototype, "ranklist_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], Contest.prototype, "is_public"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], Contest.prototype, "hide_statistics"); + Contest = __decorate([ + TypeORM.Entity() + ], Contest); + return Contest; +}(common_1["default"])); +exports["default"] = Contest; +//# sourceMappingURL=contest.js.map \ No newline at end of file diff --git a/models-built/contest.js.map b/models-built/contest.js.map new file mode 100644 index 0000000..962bcf6 --- /dev/null +++ b/models-built/contest.js.map @@ -0,0 +1 @@ +{"version":3,"file":"contest.js","sourceRoot":"","sources":["../models/contest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAI7B,+BAA0B;AAC1B,qCAAgC;AAChC,uDAAiD;AACjD,mDAA6C;AAE7C,IAAK,WAIJ;AAJD,WAAK,WAAW;IACd,0BAAW,CAAA;IACX,0BAAW,CAAA;IACX,2BAAY,CAAA;AACd,CAAC,EAJI,WAAW,KAAX,WAAW,QAIf;AAGD;IAAqC,2BAAK;IAA1C;;IAuIA,CAAC;IAvFO,mCAAiB,GAAvB;;;;;;wBACE,KAAA,IAAI,CAAA;wBAAU,qBAAM,iBAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAA;;wBAAjD,GAAK,MAAM,GAAG,SAAmC,CAAC;wBAClD,KAAA,IAAI,CAAA;wBAAY,qBAAM,6BAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,EAAA;;wBAAhE,GAAK,QAAQ,GAAG,SAAgD,CAAC;;;;;KAClE;IAEK,+BAAa,GAAnB,UAAoB,IAAI;;;gBACtB,sBAAO,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAC;;;KACrH;IAED,qCAAmB,GAAnB;QACE,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK;YAAE,OAAO,IAAI,CAAC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ClC;IAIlB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAI,EAAE,WAAW,EAAE,CAAC;;iCAClD;IAGlB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wCAC7B;IAGpB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qCAChC;IAGjB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mCAClC;IAIf;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCAChC;IAGpB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;sCACjC;IAGnB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;4CAC3B;IA3CN,OAAO;QAD3B,OAAO,CAAC,MAAM,EAAE;OACI,OAAO,CAuI3B;IAAD,cAAC;CAAA,AAvID,CAAqC,mBAAK,GAuIzC;qBAvIoB,OAAO"} \ No newline at end of file diff --git a/models-built/contest_player.js b/models-built/contest_player.js new file mode 100644 index 0000000..1482cb0 --- /dev/null +++ b/models-built/contest_player.js @@ -0,0 +1,233 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var user_1 = require("./user"); +var contest_1 = require("./contest"); +var ContestPlayer = /** @class */ (function (_super) { + __extends(ContestPlayer, _super); + function ContestPlayer() { + return _super !== null && _super.apply(this, arguments) || this; + } + ContestPlayer_1 = ContestPlayer; + ContestPlayer.findInContest = function (where) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, ContestPlayer_1.findOne({ where: where })]; + }); + }); + }; + ContestPlayer.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + _a = this; + return [4 /*yield*/, user_1["default"].findById(this.user_id)]; + case 1: + _a.user = _c.sent(); + _b = this; + return [4 /*yield*/, contest_1["default"].findById(this.contest_id)]; + case 2: + _b.contest = _c.sent(); + return [2 /*return*/]; + } + }); + }); + }; + ContestPlayer.prototype.updateScore = function (judge_state) { + return __awaiter(this, void 0, void 0, function () { + var arr, maxScoreSubmission, _i, arr_1, x, x, x, arr, _a, arr_2, x, x; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, this.loadRelationships()]; + case 1: + _b.sent(); + if (this.contest.type === 'ioi') { + if (!judge_state.pending) { + if (!this.score_details[judge_state.problem_id]) { + this.score_details[judge_state.problem_id] = { + score: judge_state.score, + judge_id: judge_state.id, + submissions: {} + }; + } + this.score_details[judge_state.problem_id].submissions[judge_state.id] = { + judge_id: judge_state.id, + score: judge_state.score, + time: judge_state.submit_time + }; + arr = Object.values(this.score_details[judge_state.problem_id].submissions); + arr.sort(function (a, b) { return a.time - b.time; }); + maxScoreSubmission = null; + for (_i = 0, arr_1 = arr; _i < arr_1.length; _i++) { + x = arr_1[_i]; + if (!maxScoreSubmission || x.score >= maxScoreSubmission.score && maxScoreSubmission.score < 100) { + maxScoreSubmission = x; + } + } + this.score_details[judge_state.problem_id].judge_id = maxScoreSubmission.judge_id; + this.score_details[judge_state.problem_id].score = maxScoreSubmission.score; + this.score_details[judge_state.problem_id].time = maxScoreSubmission.time; + this.score = 0; + for (x in this.score_details) { + if (this.score != null) + this.score += this.score_details[x].score; + } + } + } + else if (this.contest.type === 'noi') { + if (this.score_details[judge_state.problem_id] && this.score_details[judge_state.problem_id].judge_id > judge_state.id) + return [2 /*return*/]; + this.score_details[judge_state.problem_id] = { + score: judge_state.score, + judge_id: judge_state.id + }; + this.score = 0; + for (x in this.score_details) { + if (this.score != null) + this.score += this.score_details[x].score; + } + } + else if (this.contest.type === 'acm') { + if (!judge_state.pending) { + if (!this.score_details[judge_state.problem_id]) { + this.score_details[judge_state.problem_id] = { + accepted: false, + unacceptedCount: 0, + acceptedTime: 0, + judge_id: 0, + submissions: {} + }; + } + this.score_details[judge_state.problem_id].submissions[judge_state.id] = { + judge_id: judge_state.id, + accepted: judge_state.status === 'Accepted', + compiled: judge_state.score != null, + time: judge_state.submit_time + }; + arr = Object.values(this.score_details[judge_state.problem_id].submissions); + arr.sort(function (a, b) { return a.time - b.time; }); + this.score_details[judge_state.problem_id].unacceptedCount = 0; + this.score_details[judge_state.problem_id].judge_id = 0; + this.score_details[judge_state.problem_id].accepted = 0; + for (_a = 0, arr_2 = arr; _a < arr_2.length; _a++) { + x = arr_2[_a]; + if (x.accepted) { + this.score_details[judge_state.problem_id].accepted = true; + this.score_details[judge_state.problem_id].acceptedTime = x.time; + this.score_details[judge_state.problem_id].judge_id = x.judge_id; + break; + } + else if (x.compiled) { + this.score_details[judge_state.problem_id].unacceptedCount++; + } + } + if (!this.score_details[judge_state.problem_id].accepted) { + this.score_details[judge_state.problem_id].judge_id = arr[arr.length - 1].judge_id; + } + this.score = 0; + for (x in this.score_details) { + if (this.score_details[x].accepted) + this.score++; + } + } + } + return [2 /*return*/]; + } + }); + }); + }; + var ContestPlayer_1; + ContestPlayer.cache = true; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], ContestPlayer.prototype, "id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], ContestPlayer.prototype, "contest_id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], ContestPlayer.prototype, "user_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], ContestPlayer.prototype, "score"); + __decorate([ + TypeORM.Column({ "default": JSON.stringify({}), type: "json" }), + __metadata("design:type", Object) + ], ContestPlayer.prototype, "score_details"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], ContestPlayer.prototype, "time_spent"); + ContestPlayer = ContestPlayer_1 = __decorate([ + TypeORM.Entity() + ], ContestPlayer); + return ContestPlayer; +}(common_1["default"])); +exports["default"] = ContestPlayer; +//# sourceMappingURL=contest_player.js.map \ No newline at end of file diff --git a/models-built/contest_player.js.map b/models-built/contest_player.js.map new file mode 100644 index 0000000..bcace30 --- /dev/null +++ b/models-built/contest_player.js.map @@ -0,0 +1 @@ +{"version":3,"file":"contest_player.js","sourceRoot":"","sources":["../models/contest_player.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAm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AAK,GAAG,CAAC,CAAC;gCACf,KAAS,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE;oCAChC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ;wCAAE,IAAI,CAAC,KAAK,EAAE,CAAC;iCAClD;6BACF;yBACF;;;;;KACF;;IAnIM,mBAAK,GAAG,IAAI,CAAC;IAGpB;QADC,OAAO,CAAC,sBAAsB,EAAE;;qCACtB;IAIX;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;6CACjC;IAInB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;0CACpC;IAGhB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACtC;IAGd;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,SAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDACxC;IAGtB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;6CACjC;IArBA,aAAa;QADjC,OAAO,CAAC,MAAM,EAAE;OACI,aAAa,CAqIjC;IAAD,oBAAC;CAAA,AArID,CAA2C,mBAAK,GAqI/C;qBArIoB,aAAa"} \ No newline at end of file diff --git a/models-built/contest_ranklist.js b/models-built/contest_ranklist.js new file mode 100644 index 0000000..3e99ed2 --- /dev/null +++ b/models-built/contest_ranklist.js @@ -0,0 +1,207 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var contest_player_1 = require("./contest_player"); +var judge_state_1 = require("./judge_state"); +var ContestRanklist = /** @class */ (function (_super) { + __extends(ContestRanklist, _super); + function ContestRanklist() { + return _super !== null && _super.apply(this, arguments) || this; + } + ContestRanklist.prototype.getPlayers = function () { + return __awaiter(this, void 0, void 0, function () { + var a, i, _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + a = []; + i = 1; + _c.label = 1; + case 1: + if (!(i <= this.ranklist.player_num)) return [3 /*break*/, 4]; + _b = (_a = a).push; + return [4 /*yield*/, contest_player_1["default"].findById(this.ranklist[i])]; + case 2: + _b.apply(_a, [_c.sent()]); + _c.label = 3; + case 3: + i++; + return [3 /*break*/, 1]; + case 4: return [2 /*return*/, a]; + } + }); + }); + }; + ContestRanklist.prototype.updatePlayer = function (contest, player) { + return __awaiter(this, void 0, void 0, function () { + var players, newPlayer, _i, players_1, x, _a, players_2, player_1, _b, _c, _d, i, judge_state, multiplier, _e, players_3, player_2, i, i; + return __generator(this, function (_f) { + switch (_f.label) { + case 0: return [4 /*yield*/, this.getPlayers()]; + case 1: + players = _f.sent(), newPlayer = true; + for (_i = 0, players_1 = players; _i < players_1.length; _i++) { + x = players_1[_i]; + if (x.user_id === player.user_id) { + newPlayer = false; + break; + } + } + if (newPlayer) { + players.push(player); + } + if (!(contest.type === 'noi' || contest.type === 'ioi')) return [3 /*break*/, 8]; + _a = 0, players_2 = players; + _f.label = 2; + case 2: + if (!(_a < players_2.length)) return [3 /*break*/, 7]; + player_1 = players_2[_a]; + player_1.latest = 0; + player_1.score = 0; + _b = []; + for (_c in player_1.score_details) + _b.push(_c); + _d = 0; + _f.label = 3; + case 3: + if (!(_d < _b.length)) return [3 /*break*/, 6]; + i = _b[_d]; + return [4 /*yield*/, judge_state_1["default"].findById(player_1.score_details[i].judge_id)]; + case 4: + judge_state = _f.sent(); + if (!judge_state) + return [3 /*break*/, 5]; + player_1.latest = Math.max(player_1.latest, judge_state.submit_time); + if (player_1.score_details[i].score != null) { + multiplier = this.ranking_params[i] || 1.0; + player_1.score_details[i].weighted_score = Math.round(player_1.score_details[i].score * multiplier); + player_1.score += player_1.score_details[i].weighted_score; + } + _f.label = 5; + case 5: + _d++; + return [3 /*break*/, 3]; + case 6: + _a++; + return [3 /*break*/, 2]; + case 7: + players.sort(function (a, b) { + if (a.score > b.score) + return -1; + if (b.score > a.score) + return 1; + if (a.latest < b.latest) + return -1; + if (a.latest > b.latest) + return 1; + return 0; + }); + return [3 /*break*/, 9]; + case 8: + for (_e = 0, players_3 = players; _e < players_3.length; _e++) { + player_2 = players_3[_e]; + player_2.timeSum = 0; + for (i in player_2.score_details) { + if (player_2.score_details[i].accepted) { + player_2.timeSum += (player_2.score_details[i].acceptedTime - contest.start_time) + (player_2.score_details[i].unacceptedCount * 20 * 60); + } + } + } + players.sort(function (a, b) { + if (a.score > b.score) + return -1; + if (b.score > a.score) + return 1; + if (a.timeSum < b.timeSum) + return -1; + if (a.timeSum > b.timeSum) + return 1; + return 0; + }); + _f.label = 9; + case 9: + this.ranklist = { player_num: players.length }; + for (i = 0; i < players.length; i++) + this.ranklist[i + 1] = players[i].id; + return [2 /*return*/]; + } + }); + }); + }; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], ContestRanklist.prototype, "id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "json" }), + __metadata("design:type", Object) + ], ContestRanklist.prototype, "ranking_params"); + __decorate([ + TypeORM.Column({ "default": JSON.stringify({ player_num: 0 }), type: "json" }), + __metadata("design:type", Object) + ], ContestRanklist.prototype, "ranklist"); + ContestRanklist = __decorate([ + TypeORM.Entity() + ], ContestRanklist); + return ContestRanklist; +}(common_1["default"])); +exports["default"] = ContestRanklist; +//# sourceMappingURL=contest_ranklist.js.map \ No newline at end of file diff --git a/models-built/contest_ranklist.js.map b/models-built/contest_ranklist.js.map new file mode 100644 index 0000000..22e987b --- /dev/null +++ b/models-built/contest_ranklist.js.map @@ -0,0 +1 @@ +{"version":3,"file":"contest_ranklist.js","sourceRoot":"","sources":["../models/contest_ranklist.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAI7B,mDAA6C;AAC7C,6CAAuC;AAGvC;IAA6C,mCAAK;IAAlD;;IA+EA,CAAC;IArEO,oCAAU,GAAhB;;;;;;wBACM,CAAC,GAAG,EAAE,CAAC;wBACF,CAAC,GAAG,CAAC;;;6BAAE,CAAA,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAA;wBAC3C,KAAA,CAAA,KAAA,CAAC,CAAA,CAAC,IAAI,CAAA;wBAAC,qBAAM,2BAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAA;;wBAArD,cAAO,SAA8C,EAAC,CAAC;;;wBADV,CAAC,EAAE,CAAA;;4BAGlD,sBAAO,CAAC,EAAC;;;;KACV;IAEK,sCAAY,GAAlB,UAAmB,OAAO,EAA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AAK;gCAAE,OAAO,CAAC,CAAC;4BAChC,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;gCAAE,OAAO,CAAC,CAAC,CAAC;4BACrC,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;gCAAE,OAAO,CAAC,CAAC;4BACpC,OAAO,CAAC,CAAC;wBACX,CAAC,CAAC,CAAC;;;wBAGL,IAAI,CAAC,QAAQ,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;wBAC/C,KAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE;4BAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;;;;;KAC/E;IA5ED;QADC,OAAO,CAAC,sBAAsB,EAAE;;uCACtB;IAGX;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDAC7B;IAGpB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,SAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;6CAC/D;IARK,eAAe;QADnC,OAAO,CAAC,MAAM,EAAE;OACI,eAAe,CA+EnC;IAAD,sBAAC;CAAA,AA/ED,CAA6C,mBAAK,GA+EjD;qBA/EoB,eAAe"} \ No newline at end of file diff --git a/models-built/file.js b/models-built/file.js new file mode 100644 index 0000000..c75205c --- /dev/null +++ b/models-built/file.js @@ -0,0 +1,207 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var fs = require("fs-extra"); +var File = /** @class */ (function (_super) { + __extends(File, _super); + function File() { + return _super !== null && _super.apply(this, arguments) || this; + } + File_1 = File; + File.prototype.getPath = function () { + return File_1.resolvePath(this.type, this.md5); + }; + File.resolvePath = function (type, md5) { + return syzoj.utils.resolvePath(syzoj.config.upload_dir, type, md5); + }; + // data: Array of { filename: string, data: buffer or string } + File.zipFiles = function (files) { + return __awaiter(this, void 0, void 0, function () { + var tmp, dir, path, fs, filenames, p7zip, zipFile; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + tmp = require('tmp-promise'); + return [4 /*yield*/, tmp.dir()]; + case 1: + dir = _a.sent(), path = require('path'), fs = require('fs-extra'); + return [4 /*yield*/, files.mapAsync(function (file) { return __awaiter(_this, void 0, void 0, function () { + var fullPath; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + fullPath = path.join(dir.path, file.filename); + return [4 /*yield*/, fs.writeFileAsync(fullPath, file.data)]; + case 1: + _a.sent(); + return [2 /*return*/, fullPath]; + } + }); + }); })]; + case 2: + filenames = _a.sent(); + p7zip = new (require('node-7z')); + return [4 /*yield*/, tmp.tmpName()]; + case 3: + zipFile = (_a.sent()) + '.zip'; + return [4 /*yield*/, p7zip.add(zipFile, filenames)]; + case 4: + _a.sent(); + return [4 /*yield*/, fs.removeAsync(dir.path)]; + case 5: + _a.sent(); + return [2 /*return*/, zipFile]; + } + }); + }); + }; + File.upload = function (path, type, noLimit) { + return __awaiter(this, void 0, void 0, function () { + var buf, key, file; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, fs.readFile(path)]; + case 1: + buf = _a.sent(); + if (!noLimit && buf.length > syzoj.config.limit.data_size) + throw new ErrorMessage('数据包太大。'); + key = syzoj.utils.md5(buf); + return [4 /*yield*/, fs.move(path, File_1.resolvePath(type, key), { overwrite: true })]; + case 2: + _a.sent(); + return [4 /*yield*/, File_1.findOne({ where: { md5: key } })]; + case 3: + file = _a.sent(); + if (!!file) return [3 /*break*/, 6]; + return [4 /*yield*/, File_1.create({ + type: type, + md5: key + })]; + case 4: + file = _a.sent(); + return [4 /*yield*/, file.save()]; + case 5: + _a.sent(); + _a.label = 6; + case 6: return [2 /*return*/, file]; + } + }); + }); + }; + File.prototype.getUnzipSize = function () { + return __awaiter(this, void 0, void 0, function () { + var p7zip, e_1; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.unzipSize === undefined)) return [3 /*break*/, 4]; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + p7zip = new (require('node-7z')); + this.unzipSize = 0; + return [4 /*yield*/, p7zip.list(this.getPath()).progress(function (files) { + for (var _i = 0, files_1 = files; _i < files_1.length; _i++) { + var file = files_1[_i]; + _this.unzipSize += file.size; + } + })]; + case 2: + _a.sent(); + return [3 /*break*/, 4]; + case 3: + e_1 = _a.sent(); + this.unzipSize = null; + return [3 /*break*/, 4]; + case 4: + if (this.unzipSize === null) + throw new ErrorMessage('无效的 ZIP 文件。'); + else + return [2 /*return*/, this.unzipSize]; + return [2 /*return*/]; + } + }); + }); + }; + var File_1; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], File.prototype, "id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "varchar", length: 80 }), + __metadata("design:type", String) + ], File.prototype, "type"); + __decorate([ + TypeORM.Index({ unique: true }), + TypeORM.Column({ nullable: true, type: "varchar", length: 80 }), + __metadata("design:type", String) + ], File.prototype, "md5"); + File = File_1 = __decorate([ + TypeORM.Entity() + ], File); + return File; +}(common_1["default"])); +exports["default"] = File; +//# sourceMappingURL=file.js.map \ No newline at end of file diff --git a/models-built/file.js.map b/models-built/file.js.map new file mode 100644 index 0000000..e8ec9cf --- /dev/null +++ b/models-built/file.js.map @@ -0,0 +1 @@ +{"version":3,"file":"file.js","sourceRoot":"","sources":["../models/file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAE7B,6BAA+B;AAK/B;IAAkC,wBAAK;IAAvC;;IA4EA,CAAC;aA5EoB,IAAI;IAcvB,sBAAO,GAAP;QACE,OAAO,MAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;IAEM,gBAAW,GAAlB,UAAmB,IAAI,EAAE,GAAG;QAC1B,OAAO,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IACrE,CAAC;IAED,8DAA8D;IACjD,aAAQ,GAArB,UAAsB,KAAK;;;;;;;wBACrB,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;wBACvB,qBAAM,GAAG,CAAC,GAAG,EAAE,EAAA;;wBAArB,GAAG,GAAG,SAAe,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;wBAC3D,qBAAM,KAAK,CAAC,QAAQ,CAAC,UAAM,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E,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;;8BACnD;IAIb;QAFC,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC/B,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;;6BACpD;IAVO,IAAI;QADxB,OAAO,CAAC,MAAM,EAAE;OACI,IAAI,CA4ExB;IAAD,WAAC;CAAA,AA5ED,CAAkC,mBAAK,GA4EtC;qBA5EoB,IAAI"} \ No newline at end of file diff --git a/models-built/formatted_code.js b/models-built/formatted_code.js new file mode 100644 index 0000000..185d3f6 --- /dev/null +++ b/models-built/formatted_code.js @@ -0,0 +1,46 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var FormattedCode = /** @class */ (function (_super) { + __extends(FormattedCode, _super); + function FormattedCode() { + return _super !== null && _super.apply(this, arguments) || this; + } + __decorate([ + TypeORM.PrimaryColumn({ type: "varchar", length: 50 }), + __metadata("design:type", String) + ], FormattedCode.prototype, "key"); + __decorate([ + TypeORM.Column({ nullable: true, type: "mediumtext" }), + __metadata("design:type", String) + ], FormattedCode.prototype, "code"); + FormattedCode = __decorate([ + TypeORM.Entity() + ], FormattedCode); + return FormattedCode; +}(common_1["default"])); +exports["default"] = FormattedCode; +//# sourceMappingURL=formatted_code.js.map \ No newline at end of file diff --git a/models-built/formatted_code.js.map b/models-built/formatted_code.js.map new file mode 100644 index 0000000..7262b50 --- /dev/null +++ b/models-built/formatted_code.js.map @@ -0,0 +1 @@ +{"version":3,"file":"formatted_code.js","sourceRoot":"","sources":["../models/formatted_code.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAG7B;IAA2C,iCAAK;IAAhD;;IAMA,CAAC;IAJC;QADC,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;;sCAC3C;IAGZ;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;;uCAC1C;IALM,aAAa;QADjC,OAAO,CAAC,MAAM,EAAE;OACI,aAAa,CAMjC;IAAD,oBAAC;CAAA,AAND,CAA2C,mBAAK,GAM/C;qBANoB,aAAa"} \ No newline at end of file diff --git a/models-built/judge_state.js b/models-built/judge_state.js new file mode 100644 index 0000000..fee52a0 --- /dev/null +++ b/models-built/judge_state.js @@ -0,0 +1,382 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var user_1 = require("./user"); +var problem_1 = require("./problem"); +var contest_1 = require("./contest"); +var Judger = syzoj.lib('judger'); +var Status; +(function (Status) { + Status["ACCEPTED"] = "Accepted"; + Status["COMPILE_ERROR"] = "Compile Error"; + Status["FILE_ERROR"] = "File Error"; + Status["INVALID_INTERACTION"] = "Invalid Interaction"; + Status["JUDGEMENT_FAILED"] = "Judgement Failed"; + Status["MEMORY_LIMIT_EXCEEDED"] = "Memory Limit Exceeded"; + Status["NO_TESTDATA"] = "No Testdata"; + Status["OUTPUT_LIMIT_EXCEEDED"] = "Output Limit Exceeded"; + Status["PARTIALLY_CORRECT"] = "Partially Correct"; + Status["RUNTIME_ERROR"] = "Runtime Error"; + Status["SYSTEM_ERROR"] = "System Error"; + Status["TIME_LIMIT_EXCEEDED"] = "Time Limit Exceeded"; + Status["UNKNOWN"] = "Unknown"; + Status["WRONG_ANSWER"] = "Wrong Answer"; + Status["WAITING"] = "Waiting"; +})(Status || (Status = {})); +var JudgeState = /** @class */ (function (_super) { + __extends(JudgeState, _super); + function JudgeState() { + return _super !== null && _super.apply(this, arguments) || this; + } + JudgeState.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + if (!!this.user) return [3 /*break*/, 2]; + _a = this; + return [4 /*yield*/, user_1["default"].findById(this.user_id)]; + case 1: + _a.user = _c.sent(); + _c.label = 2; + case 2: + if (!!this.problem) return [3 /*break*/, 4]; + if (!this.problem_id) return [3 /*break*/, 4]; + _b = this; + return [4 /*yield*/, problem_1["default"].findById(this.problem_id)]; + case 3: + _b.problem = _c.sent(); + _c.label = 4; + case 4: return [2 /*return*/]; + } + }); + }); + }; + JudgeState.prototype.saveHook = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + if (this.score === null) + this.score = 0; + return [2 /*return*/]; + }); + }); + }; + JudgeState.prototype.isAllowedVisitBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + var _a, _b, contest, _c; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: return [4 /*yield*/, this.loadRelationships()]; + case 1: + _d.sent(); + if (!(user && user.id === this.problem.user_id)) return [3 /*break*/, 2]; + return [2 /*return*/, true]; + case 2: + if (!(this.type === 0)) return [3 /*break*/, 6]; + _a = this.problem.is_public; + if (_a) return [3 /*break*/, 5]; + _b = user; + if (!_b) return [3 /*break*/, 4]; + return [4 /*yield*/, user.hasPrivilege('manage_problem')]; + case 3: + _b = (_d.sent()); + _d.label = 4; + case 4: + _a = (_b); + _d.label = 5; + case 5: return [2 /*return*/, _a]; + case 6: + if (!(this.type === 1)) return [3 /*break*/, 11]; + return [4 /*yield*/, contest_1["default"].findById(this.type_info)]; + case 7: + contest = _d.sent(); + if (!contest.isRunning()) return [3 /*break*/, 10]; + _c = user; + if (!_c) return [3 /*break*/, 9]; + return [4 /*yield*/, contest.isSupervisior(user)]; + case 8: + _c = (_d.sent()); + _d.label = 9; + case 9: return [2 /*return*/, _c]; + case 10: return [2 /*return*/, true]; + case 11: return [2 /*return*/]; + } + }); + }); + }; + JudgeState.prototype.updateRelatedInfo = function (newSubmission) { + return __awaiter(this, void 0, void 0, function () { + var promises, contest; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.type === 0)) return [3 /*break*/, 3]; + return [4 /*yield*/, this.loadRelationships()]; + case 1: + _a.sent(); + promises = []; + promises.push(this.user.refreshSubmitInfo()); + promises.push(this.problem.resetSubmissionCount()); + if (!newSubmission) { + promises.push(this.problem.updateStatistics(this.user_id)); + } + return [4 /*yield*/, Promise.all(promises)]; + case 2: + _a.sent(); + return [3 /*break*/, 6]; + case 3: + if (!(this.type === 1)) return [3 /*break*/, 6]; + return [4 /*yield*/, contest_1["default"].findById(this.type_info)]; + case 4: + contest = _a.sent(); + return [4 /*yield*/, contest.newSubmission(this)]; + case 5: + _a.sent(); + _a.label = 6; + case 6: return [2 /*return*/]; + } + }); + }); + }; + JudgeState.prototype.rejudge = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['JudgeState::rejudge', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + var oldStatus, err_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.loadRelationships()]; + case 1: + _a.sent(); + oldStatus = this.status; + this.status = Status.UNKNOWN; + this.pending = false; + this.score = null; + if (this.language) { + // language is empty if it's a submit-answer problem + this.total_time = null; + this.max_memory = null; + } + this.result = {}; + this.task_id = require('randomstring').generate(10); + return [4 /*yield*/, this.save()]; + case 2: + _a.sent(); + return [4 /*yield*/, this.updateRelatedInfo(false)]; + case 3: + _a.sent(); + _a.label = 4; + case 4: + _a.trys.push([4, 7, , 8]); + return [4 /*yield*/, Judger.judge(this, this.problem, 1)]; + case 5: + _a.sent(); + this.pending = true; + this.status = Status.WAITING; + return [4 /*yield*/, this.save()]; + case 6: + _a.sent(); + return [3 /*break*/, 8]; + case 7: + err_1 = _a.sent(); + console.log("Error while connecting to judge frontend: " + err_1.toString()); + throw new ErrorMessage("无法开始评测。"); + case 8: return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + JudgeState.prototype.getProblemType = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.loadRelationships()]; + case 1: + _a.sent(); + return [2 /*return*/, this.problem.type]; + } + }); + }); + }; + JudgeState.prototype.share = function () { + return __awaiter(this, void 0, void 0, function () { + var err_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.is_public = true; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, this.save()]; + case 2: + _a.sent(); + return [3 /*break*/, 4]; + case 3: + err_2 = _a.sent(); + console.log("Error while share this judge:" + err_2.toString()); + throw new ErrorMessage("分享失败。"); + case 4: return [2 /*return*/]; + } + }); + }); + }; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], JudgeState.prototype, "id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "mediumtext" }), + __metadata("design:type", String) + ], JudgeState.prototype, "code"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 20 }), + __metadata("design:type", String) + ], JudgeState.prototype, "language"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "enum", "enum": Status }), + __metadata("design:type", String) + ], JudgeState.prototype, "status"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "varchar", length: 50 }), + __metadata("design:type", String) + ], JudgeState.prototype, "task_id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer", "default": 0 }), + __metadata("design:type", Number) + ], JudgeState.prototype, "score"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer", "default": 0 }), + __metadata("design:type", Number) + ], JudgeState.prototype, "total_time"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer", "default": 0 }), + __metadata("design:type", Number) + ], JudgeState.prototype, "code_length"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean", "default": 0 }), + __metadata("design:type", Boolean) + ], JudgeState.prototype, "pending"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer", "default": 0 }), + __metadata("design:type", Number) + ], JudgeState.prototype, "max_memory"); + __decorate([ + TypeORM.Column({ nullable: true, type: "json" }), + __metadata("design:type", Object) + ], JudgeState.prototype, "compilation"); + __decorate([ + TypeORM.Column({ nullable: true, type: "json" }), + __metadata("design:type", Object) + ], JudgeState.prototype, "result"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], JudgeState.prototype, "user_id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], JudgeState.prototype, "problem_id"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], JudgeState.prototype, "submit_time"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], JudgeState.prototype, "type"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], JudgeState.prototype, "type_info"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], JudgeState.prototype, "is_public"); + JudgeState = __decorate([ + TypeORM.Entity(), + TypeORM.Index(['type', 'type_info']), + TypeORM.Index(['type', 'is_public', 'language', 'status', 'problem_id']), + TypeORM.Index(['type', 'is_public', 'status', 'problem_id']), + TypeORM.Index(['type', 'is_public', 'problem_id']), + TypeORM.Index(['type', 'is_public', 'language', 'problem_id']), + TypeORM.Index(['problem_id', 'type', 'pending', 'score']) + ], JudgeState); + return JudgeState; +}(common_1["default"])); +exports["default"] = JudgeState; +//# sourceMappingURL=judge_state.js.map \ No newline at end of file diff --git a/models-built/judge_state.js.map b/models-built/judge_state.js.map new file mode 100644 index 0000000..584a5fd --- /dev/null +++ b/models-built/judge_state.js.map @@ -0,0 +1 @@ +{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C,KAAK,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;QAClD,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;QAC9D,OAAO,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;OACrC,UAAU,CAoK9B;IAAD,iBAAC;CAAA,AApKD,CAAwC,mBAAK,GAoK5C;qBApKoB,UAAU"} \ No newline at end of file diff --git a/models-built/problem.js b/models-built/problem.js new file mode 100644 index 0000000..637edcb --- /dev/null +++ b/models-built/problem.js @@ -0,0 +1,1079 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var user_1 = require("./user"); +var file_1 = require("./file"); +var judge_state_1 = require("./judge_state"); +var contest_1 = require("./contest"); +var problem_tag_1 = require("./problem_tag"); +var problem_tag_map_1 = require("./problem_tag_map"); +var submission_statistics_1 = require("./submission_statistics"); +var fs = require("fs-extra"); +var path = require("path"); +var util = require("util"); +var LRUCache = require("lru-cache"); +var DeepCopy = require("deepcopy"); +var problemTagCache = new LRUCache({ + max: syzoj.config.db.cache_size +}); +var ProblemType; +(function (ProblemType) { + ProblemType["Traditional"] = "traditional"; + ProblemType["SubmitAnswer"] = "submit-answer"; + ProblemType["Interaction"] = "interaction"; +})(ProblemType || (ProblemType = {})); +var statisticsTypes = { + fastest: ['total_time', 'ASC'], + slowest: ['total_time', 'DESC'], + shortest: ['code_length', 'ASC'], + longest: ['code_length', 'DESC'], + min: ['max_memory', 'ASC'], + max: ['max_memory', 'DESC'], + earliest: ['submit_time', 'ASC'] +}; +var statisticsCodeOnly = ["fastest", "slowest", "min", "max"]; +var Problem = /** @class */ (function (_super) { + __extends(Problem, _super); + function Problem() { + return _super !== null && _super.apply(this, arguments) || this; + } + Problem_1 = Problem; + Problem.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a, _b, _c; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + _a = this; + return [4 /*yield*/, user_1["default"].findById(this.user_id)]; + case 1: + _a.user = _d.sent(); + _b = this; + return [4 /*yield*/, user_1["default"].findById(this.publicizer_id)]; + case 2: + _b.publicizer = _d.sent(); + _c = this; + return [4 /*yield*/, file_1["default"].findById(this.additional_file_id)]; + case 3: + _c.additional_file = _d.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.isAllowedEditBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!user) + return [2 /*return*/, false]; + return [4 /*yield*/, user.hasPrivilege('manage_problem')]; + case 1: + if (_a.sent()) + return [2 /*return*/, true]; + return [2 /*return*/, this.user_id === user.id]; + } + }); + }); + }; + Problem.prototype.isAllowedUseBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (this.is_public) + return [2 /*return*/, true]; + if (!user) + return [2 /*return*/, false]; + return [4 /*yield*/, user.hasPrivilege('manage_problem')]; + case 1: + if (_a.sent()) + return [2 /*return*/, true]; + return [2 /*return*/, this.user_id === user.id]; + } + }); + }); + }; + Problem.prototype.isAllowedManageBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!user) + return [2 /*return*/, false]; + return [4 /*yield*/, user.hasPrivilege('manage_problem')]; + case 1: + if (_a.sent()) + return [2 /*return*/, true]; + return [2 /*return*/, user.is_admin]; + } + }); + }); + }; + Problem.prototype.getTestdataPath = function () { + return syzoj.utils.resolvePath(syzoj.config.upload_dir, 'testdata', this.id.toString()); + }; + Problem.prototype.getTestdataArchivePath = function () { + return syzoj.utils.resolvePath(syzoj.config.upload_dir, 'testdata-archive', this.id.toString() + '.zip'); + }; + Problem.prototype.updateTestdata = function (path, noLimit) { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['Problem::Testdata', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + var p7zip, unzipSize, unzipCount, dir, execFileAsync; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + p7zip = new (require('node-7z')); + unzipSize = 0; + return [4 /*yield*/, p7zip.list(path).progress(function (files) { + unzipCount = files.length; + for (var _i = 0, files_1 = files; _i < files_1.length; _i++) { + var file = files_1[_i]; + unzipSize += file.size; + } + })]; + case 1: + _a.sent(); + if (!noLimit && unzipCount > syzoj.config.limit.testdata_filecount) + throw new ErrorMessage('数据包中的文件太多。'); + if (!noLimit && unzipSize > syzoj.config.limit.testdata) + throw new ErrorMessage('数据包太大。'); + dir = this.getTestdataPath(); + return [4 /*yield*/, fs.remove(dir)]; + case 2: + _a.sent(); + return [4 /*yield*/, fs.ensureDir(dir)]; + case 3: + _a.sent(); + execFileAsync = util.promisify(require('child_process').execFile); + return [4 /*yield*/, execFileAsync(__dirname + '/../bin/unzip', ['-j', '-o', '-d', dir, path])]; + case 4: + _a.sent(); + return [4 /*yield*/, fs.move(path, this.getTestdataArchivePath(), { overwrite: true })]; + case 5: + _a.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.uploadTestdataSingleFile = function (filename, filepath, size, noLimit) { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['Promise::Testdata', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + var dir, oldSize, list, replace, oldCount, _i, _a, file, execFileAsync, e_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + dir = this.getTestdataPath(); + return [4 /*yield*/, fs.ensureDir(dir)]; + case 1: + _b.sent(); + oldSize = 0; + return [4 /*yield*/, this.listTestdata()]; + case 2: + list = _b.sent(), replace = false, oldCount = 0; + if (list) { + oldCount = list.files.length; + for (_i = 0, _a = list.files; _i < _a.length; _i++) { + file = _a[_i]; + if (file.filename !== filename) + oldSize += file.size; + else + replace = true; + } + } + if (!noLimit && oldSize + size > syzoj.config.limit.testdata) + throw new ErrorMessage('数据包太大。'); + if (!noLimit && oldCount + !replace > syzoj.config.limit.testdata_filecount) + throw new ErrorMessage('数据包中的文件太多。'); + return [4 /*yield*/, fs.move(filepath, path.join(dir, filename), { overwrite: true })]; + case 3: + _b.sent(); + execFileAsync = util.promisify(require('child_process').execFile); + _b.label = 4; + case 4: + _b.trys.push([4, 6, , 7]); + return [4 /*yield*/, execFileAsync('dos2unix', [path.join(dir, filename)])]; + case 5: + _b.sent(); + return [3 /*break*/, 7]; + case 6: + e_1 = _b.sent(); + return [3 /*break*/, 7]; + case 7: return [4 /*yield*/, fs.remove(this.getTestdataArchivePath())]; + case 8: + _b.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.deleteTestdataSingleFile = function (filename) { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['Promise::Testdata', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, fs.remove(path.join(this.getTestdataPath(), filename))]; + case 1: + _a.sent(); + return [4 /*yield*/, fs.remove(this.getTestdataArchivePath())]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.makeTestdataZip = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['Promise::Testdata', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + var dir, p7zip, list, pathlist; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + dir = this.getTestdataPath(); + return [4 /*yield*/, syzoj.utils.isDir(dir)]; + case 1: + if (!(_a.sent())) + throw new ErrorMessage('无测试数据。'); + p7zip = new (require('node-7z')); + return [4 /*yield*/, this.listTestdata()]; + case 2: + list = _a.sent(), pathlist = list.files.map(function (file) { return path.join(dir, file.filename); }); + if (!pathlist.length) + throw new ErrorMessage('无测试数据。'); + return [4 /*yield*/, fs.ensureDir(path.resolve(this.getTestdataArchivePath(), '..'))]; + case 3: + _a.sent(); + return [4 /*yield*/, p7zip.add(this.getTestdataArchivePath(), pathlist)]; + case 4: + _a.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.hasSpecialJudge = function () { + return __awaiter(this, void 0, void 0, function () { + var dir, list, e_2; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + dir = this.getTestdataPath(); + return [4 /*yield*/, fs.readdir(dir)]; + case 1: + list = _a.sent(); + return [2 /*return*/, list.includes('spj.js') || list.find(function (x) { return x.startsWith('spj_'); }) !== undefined]; + case 2: + e_2 = _a.sent(); + return [2 /*return*/, false]; + case 3: return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.listTestdata = function () { + return __awaiter(this, void 0, void 0, function () { + var dir_1, filenameList, list, res, stat, e_3, e_4; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 7, , 8]); + dir_1 = this.getTestdataPath(); + return [4 /*yield*/, fs.readdir(dir_1)]; + case 1: + filenameList = _a.sent(); + return [4 /*yield*/, Promise.all(filenameList.map(function (x) { return __awaiter(_this, void 0, void 0, function () { + var stat; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, fs.stat(path.join(dir_1, x))]; + case 1: + stat = _a.sent(); + if (!stat.isFile()) + return [2 /*return*/, undefined]; + return [2 /*return*/, { + filename: x, + size: stat.size + }]; + } + }); + }); }))]; + case 2: + list = _a.sent(); + list = list.filter(function (x) { return x; }); + res = { + files: list, + zip: null + }; + _a.label = 3; + case 3: + _a.trys.push([3, 5, , 6]); + return [4 /*yield*/, fs.stat(this.getTestdataArchivePath())]; + case 4: + stat = _a.sent(); + if (stat.isFile()) { + res.zip = { + size: stat.size + }; + } + return [3 /*break*/, 6]; + case 5: + e_3 = _a.sent(); + if (list) { + res.zip = { + size: null + }; + } + return [3 /*break*/, 6]; + case 6: return [2 /*return*/, res]; + case 7: + e_4 = _a.sent(); + return [2 /*return*/, null]; + case 8: return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.updateFile = function (path, type, noLimit) { + return __awaiter(this, void 0, void 0, function () { + var file; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, file_1["default"].upload(path, type, noLimit)]; + case 1: + file = _a.sent(); + if (type === 'additional_file') { + this.additional_file_id = file.id; + } + return [4 /*yield*/, this.save()]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.validate = function () { + return __awaiter(this, void 0, void 0, function () { + var filenameRE; + return __generator(this, function (_a) { + if (this.time_limit <= 0) + return [2 /*return*/, 'Invalid time limit']; + if (this.time_limit > syzoj.config.limit.time_limit) + return [2 /*return*/, 'Time limit too large']; + if (this.memory_limit <= 0) + return [2 /*return*/, 'Invalid memory limit']; + if (this.memory_limit > syzoj.config.limit.memory_limit) + return [2 /*return*/, 'Memory limit too large']; + if (!['traditional', 'submit-answer', 'interaction'].includes(this.type)) + return [2 /*return*/, 'Invalid problem type']; + if (this.type === 'traditional') { + filenameRE = /^[\w \-\+\.]*$/; + if (this.file_io_input_name && !filenameRE.test(this.file_io_input_name)) + return [2 /*return*/, 'Invalid input file name']; + if (this.file_io_output_name && !filenameRE.test(this.file_io_output_name)) + return [2 /*return*/, 'Invalid output file name']; + if (this.file_io) { + if (!this.file_io_input_name) + return [2 /*return*/, 'No input file name']; + if (!this.file_io_output_name) + return [2 /*return*/, 'No output file name']; + } + } + return [2 /*return*/, null]; + }); + }); + }; + Problem.prototype.getJudgeState = function (user, acFirst) { + return __awaiter(this, void 0, void 0, function () { + var where, state; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!user) + return [2 /*return*/, null]; + where = { + user_id: user.id, + problem_id: this.id + }; + if (!acFirst) return [3 /*break*/, 2]; + where.status = 'Accepted'; + return [4 /*yield*/, judge_state_1["default"].findOne({ + where: where, + order: { + submit_time: 'DESC' + } + })]; + case 1: + state = _a.sent(); + if (state) + return [2 /*return*/, state]; + _a.label = 2; + case 2: + if (where.status) + delete where.status; + return [4 /*yield*/, judge_state_1["default"].findOne({ + where: where, + order: { + submit_time: 'DESC' + } + })]; + case 3: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Problem.prototype.resetSubmissionCount = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['Problem::resetSubmissionCount', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + _a = this; + return [4 /*yield*/, judge_state_1["default"].count({ problem_id: this.id, type: TypeORM.Not(1) })]; + case 1: + _a.submit_num = _c.sent(); + _b = this; + return [4 /*yield*/, judge_state_1["default"].count({ score: 100, problem_id: this.id, type: TypeORM.Not(1) })]; + case 2: + _b.ac_num = _c.sent(); + return [4 /*yield*/, this.save()]; + case 3: + _c.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.updateStatistics = function (user_id) { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, Promise.all(Object.keys(statisticsTypes).map(function (type) { return __awaiter(_this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (this.type === ProblemType.SubmitAnswer && statisticsCodeOnly.includes(type)) + return [2 /*return*/]; + return [4 /*yield*/, syzoj.utils.lock(['Problem::UpdateStatistics', this.id, type], function () { return __awaiter(_this, void 0, void 0, function () { + var _a, column, order, result, resultRow, toDelete, baseColumns, record; + var _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + _a = statisticsTypes[type], column = _a[0], order = _a[1]; + return [4 /*yield*/, judge_state_1["default"].createQueryBuilder() + .select([column, "id"]) + .where("user_id = :user_id", { user_id: user_id }) + .andWhere("status = :status", { status: "Accepted" }) + .andWhere("problem_id = :problem_id", { problem_id: this.id }) + .orderBy((_b = {}, _b[column] = order, _b)) + .take(1) + .getRawMany()]; + case 1: + result = _c.sent(); + resultRow = result[0]; + toDelete = false; + if (!resultRow || resultRow[column] == null) { + toDelete = true; + } + baseColumns = { + user_id: user_id, + problem_id: this.id, + type: type + }; + return [4 /*yield*/, submission_statistics_1["default"].findOne(baseColumns)]; + case 2: + record = _c.sent(); + if (!toDelete) return [3 /*break*/, 5]; + if (!record) return [3 /*break*/, 4]; + return [4 /*yield*/, record.destroy()]; + case 3: + _c.sent(); + _c.label = 4; + case 4: return [2 /*return*/]; + case 5: + if (!record) { + record = submission_statistics_1["default"].create(baseColumns); + } + record.key = resultRow[column]; + record.submission_id = resultRow["id"]; + return [4 /*yield*/, record.save()]; + case 6: + _c.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); }))]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.countStatistics = function (type) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!statisticsTypes[type] || this.type === ProblemType.SubmitAnswer && statisticsCodeOnly.includes(type)) { + return [2 /*return*/, null]; + } + return [4 /*yield*/, submission_statistics_1["default"].count({ + problem_id: this.id, + type: type + })]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + Problem.prototype.getStatistics = function (type, paginate) { + return __awaiter(this, void 0, void 0, function () { + var statistics, order, ids, _a, _b, a, scoreCount, _i, a_1, score, i, i, i; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + if (!statisticsTypes[type] || this.type === ProblemType.SubmitAnswer && statisticsCodeOnly.includes(type)) { + return [2 /*return*/, null]; + } + statistics = { + type: type, + judge_state: null, + scoreDistribution: null, + prefixSum: null, + suffixSum: null + }; + order = statisticsTypes[type][1]; + return [4 /*yield*/, submission_statistics_1["default"].queryPage(paginate, { + problem_id: this.id, + type: type + }, { + '`key`': order + })]; + case 1: + ids = (_c.sent()).map(function (x) { return x.submission_id; }); + _a = statistics; + if (!ids.length) return [3 /*break*/, 3]; + return [4 /*yield*/, judge_state_1["default"].createQueryBuilder() + .whereInIds(ids) + .orderBy("FIELD(id," + ids.join(',') + ")") + .getMany()]; + case 2: + _b = _c.sent(); + return [3 /*break*/, 4]; + case 3: + _b = []; + _c.label = 4; + case 4: + _a.judge_state = _b; + return [4 /*yield*/, judge_state_1["default"].createQueryBuilder() + .select('score') + .addSelect('COUNT(*)', 'count') + .where('problem_id = :problem_id', { problem_id: this.id }) + .andWhere('type = 0') + .andWhere('pending = false') + .groupBy('score') + .getRawMany()]; + case 5: + a = _c.sent(); + scoreCount = []; + for (_i = 0, a_1 = a; _i < a_1.length; _i++) { + score = a_1[_i]; + score.score = Math.min(Math.round(score.score), 100); + scoreCount[score.score] = score.count; + } + if (scoreCount[0] === undefined) + scoreCount[0] = 0; + if (scoreCount[100] === undefined) + scoreCount[100] = 0; + if (a[null]) { + a[0] += a[null]; + delete a[null]; + } + statistics.scoreDistribution = []; + for (i = 0; i < scoreCount.length; i++) { + if (scoreCount[i] !== undefined) + statistics.scoreDistribution.push({ score: i, count: parseInt(scoreCount[i]) }); + } + statistics.prefixSum = DeepCopy(statistics.scoreDistribution); + statistics.suffixSum = DeepCopy(statistics.scoreDistribution); + for (i = 1; i < statistics.prefixSum.length; i++) { + statistics.prefixSum[i].count += statistics.prefixSum[i - 1].count; + } + for (i = statistics.prefixSum.length - 1; i >= 1; i--) { + statistics.suffixSum[i - 1].count += statistics.suffixSum[i].count; + } + return [2 /*return*/, statistics]; + } + }); + }); + }; + Problem.prototype.getTags = function () { + return __awaiter(this, void 0, void 0, function () { + var tagIDs, maps, res; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!problemTagCache.has(this.id)) return [3 /*break*/, 1]; + tagIDs = problemTagCache.get(this.id); + return [3 /*break*/, 3]; + case 1: return [4 /*yield*/, problem_tag_map_1["default"].find({ + where: { + problem_id: this.id + } + })]; + case 2: + maps = _a.sent(); + tagIDs = maps.map(function (x) { return x.tag_id; }); + problemTagCache.set(this.id, tagIDs); + _a.label = 3; + case 3: return [4 /*yield*/, tagIDs.mapAsync(function (tagID) { return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, problem_tag_1["default"].findById(tagID)]; + }); + }); })]; + case 4: + res = _a.sent(); + res.sort(function (a, b) { + return a.color > b.color ? 1 : -1; + }); + return [2 /*return*/, res]; + } + }); + }); + }; + Problem.prototype.setTags = function (newTagIDs) { + return __awaiter(this, void 0, void 0, function () { + var oldTagIDs, delTagIDs, addTagIDs, _i, delTagIDs_1, tagID, map, _a, addTagIDs_1, tagID, map; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, this.getTags()]; + case 1: + oldTagIDs = (_b.sent()).map(function (x) { return x.id; }); + delTagIDs = oldTagIDs.filter(function (x) { return !newTagIDs.includes(x); }); + addTagIDs = newTagIDs.filter(function (x) { return !oldTagIDs.includes(x); }); + _i = 0, delTagIDs_1 = delTagIDs; + _b.label = 2; + case 2: + if (!(_i < delTagIDs_1.length)) return [3 /*break*/, 6]; + tagID = delTagIDs_1[_i]; + return [4 /*yield*/, problem_tag_map_1["default"].findOne({ + where: { + problem_id: this.id, + tag_id: tagID + } + })]; + case 3: + map = _b.sent(); + return [4 /*yield*/, map.destroy()]; + case 4: + _b.sent(); + _b.label = 5; + case 5: + _i++; + return [3 /*break*/, 2]; + case 6: + _a = 0, addTagIDs_1 = addTagIDs; + _b.label = 7; + case 7: + if (!(_a < addTagIDs_1.length)) return [3 /*break*/, 11]; + tagID = addTagIDs_1[_a]; + return [4 /*yield*/, problem_tag_map_1["default"].create({ + problem_id: this.id, + tag_id: tagID + })]; + case 8: + map = _b.sent(); + return [4 /*yield*/, map.save()]; + case 9: + _b.sent(); + _b.label = 10; + case 10: + _a++; + return [3 /*break*/, 7]; + case 11: + problemTagCache.set(this.id, newTagIDs); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype.changeID = function (id) { + return __awaiter(this, void 0, void 0, function () { + var entityManager, contests, _i, contests_1, contest, problemIDs, flag, i, oldTestdataDir, oldTestdataZip, oldID, newTestdataDir, newTestdataZip; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + entityManager = TypeORM.getManager(); + id = parseInt(id); + return [4 /*yield*/, entityManager.query('UPDATE `problem` SET `id` = ' + id + ' WHERE `id` = ' + this.id)]; + case 1: + _a.sent(); + return [4 /*yield*/, entityManager.query('UPDATE `judge_state` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id)]; + case 2: + _a.sent(); + return [4 /*yield*/, entityManager.query('UPDATE `problem_tag_map` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id)]; + case 3: + _a.sent(); + return [4 /*yield*/, entityManager.query('UPDATE `article` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id)]; + case 4: + _a.sent(); + return [4 /*yield*/, entityManager.query('UPDATE `submission_statistics` SET `problem_id` = ' + id + ' WHERE `problem_id` = ' + this.id)]; + case 5: + _a.sent(); + return [4 /*yield*/, contest_1["default"].find()]; + case 6: + contests = _a.sent(); + _i = 0, contests_1 = contests; + _a.label = 7; + case 7: + if (!(_i < contests_1.length)) return [3 /*break*/, 12]; + contest = contests_1[_i]; + return [4 /*yield*/, contest.getProblems()]; + case 8: + problemIDs = _a.sent(); + flag = false; + for (i in problemIDs) { + if (problemIDs[i] === this.id) { + problemIDs[i] = id; + flag = true; + } + } + if (!flag) return [3 /*break*/, 11]; + return [4 /*yield*/, contest.setProblemsNoCheck(problemIDs)]; + case 9: + _a.sent(); + return [4 /*yield*/, contest.save()]; + case 10: + _a.sent(); + _a.label = 11; + case 11: + _i++; + return [3 /*break*/, 7]; + case 12: + oldTestdataDir = this.getTestdataPath(), oldTestdataZip = this.getTestdataArchivePath(); + oldID = this.id; + this.id = id; + newTestdataDir = this.getTestdataPath(), newTestdataZip = this.getTestdataArchivePath(); + return [4 /*yield*/, syzoj.utils.isDir(oldTestdataDir)]; + case 13: + if (!_a.sent()) return [3 /*break*/, 15]; + return [4 /*yield*/, fs.move(oldTestdataDir, newTestdataDir)]; + case 14: + _a.sent(); + _a.label = 15; + case 15: return [4 /*yield*/, syzoj.utils.isFile(oldTestdataZip)]; + case 16: + if (!_a.sent()) return [3 /*break*/, 18]; + return [4 /*yield*/, fs.move(oldTestdataZip, newTestdataZip)]; + case 17: + _a.sent(); + _a.label = 18; + case 18: return [4 /*yield*/, this.save()]; + case 19: + _a.sent(); + return [4 /*yield*/, Problem_1.deleteFromCache(oldID)]; + case 20: + _a.sent(); + return [4 /*yield*/, problemTagCache.del(oldID)]; + case 21: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + Problem.prototype["delete"] = function () { + return __awaiter(this, void 0, void 0, function () { + var entityManager, oldTestdataDir, oldTestdataZip, submissions, submitCnt, acUsers, _i, submissions_1, sm, _a, _b, _c, u, user; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + entityManager = TypeORM.getManager(); + oldTestdataDir = this.getTestdataPath(), oldTestdataZip = this.getTestdataPath(); + return [4 /*yield*/, fs.remove(oldTestdataDir)]; + case 1: + _d.sent(); + return [4 /*yield*/, fs.remove(oldTestdataZip)]; + case 2: + _d.sent(); + return [4 /*yield*/, judge_state_1["default"].find({ + where: { + problem_id: this.id + } + })]; + case 3: + submissions = _d.sent(), submitCnt = {}, acUsers = new Set(); + for (_i = 0, submissions_1 = submissions; _i < submissions_1.length; _i++) { + sm = submissions_1[_i]; + if (sm.status === 'Accepted') + acUsers.add(sm.user_id); + if (!submitCnt[sm.user_id]) { + submitCnt[sm.user_id] = 1; + } + else { + submitCnt[sm.user_id]++; + } + } + _a = []; + for (_b in submitCnt) + _a.push(_b); + _c = 0; + _d.label = 4; + case 4: + if (!(_c < _a.length)) return [3 /*break*/, 8]; + u = _a[_c]; + return [4 /*yield*/, user_1["default"].findById(parseInt(u))]; + case 5: + user = _d.sent(); + user.submit_num -= submitCnt[u]; + if (acUsers.has(parseInt(u))) + user.ac_num--; + return [4 /*yield*/, user.save()]; + case 6: + _d.sent(); + _d.label = 7; + case 7: + _c++; + return [3 /*break*/, 4]; + case 8: + problemTagCache.del(this.id); + return [4 /*yield*/, entityManager.query('DELETE FROM `judge_state` WHERE `problem_id` = ' + this.id)]; + case 9: + _d.sent(); + return [4 /*yield*/, entityManager.query('DELETE FROM `problem_tag_map` WHERE `problem_id` = ' + this.id)]; + case 10: + _d.sent(); + return [4 /*yield*/, entityManager.query('DELETE FROM `article` WHERE `problem_id` = ' + this.id)]; + case 11: + _d.sent(); + return [4 /*yield*/, entityManager.query('DELETE FROM `submission_statistics` WHERE `problem_id` = ' + this.id)]; + case 12: + _d.sent(); + return [4 /*yield*/, this.destroy()]; + case 13: + _d.sent(); + return [2 /*return*/]; + } + }); + }); + }; + var Problem_1; + Problem.cache = true; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], Problem.prototype, "id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 80 }), + __metadata("design:type", String) + ], Problem.prototype, "title"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Problem.prototype, "user_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Problem.prototype, "publicizer_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], Problem.prototype, "is_anonymous"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Problem.prototype, "description"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Problem.prototype, "input_format"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Problem.prototype, "output_format"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Problem.prototype, "example"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Problem.prototype, "limit_and_hint"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Problem.prototype, "time_limit"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Problem.prototype, "memory_limit"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Problem.prototype, "additional_file_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Problem.prototype, "ac_num"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], Problem.prototype, "submit_num"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], Problem.prototype, "is_public"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], Problem.prototype, "file_io"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Problem.prototype, "file_io_input_name"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], Problem.prototype, "file_io_output_name"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "datetime" }), + __metadata("design:type", Date) + ], Problem.prototype, "publicize_time"); + __decorate([ + TypeORM.Column({ nullable: true, + type: "enum", + "enum": ProblemType, + "default": ProblemType.Traditional + }), + __metadata("design:type", String) + ], Problem.prototype, "type"); + Problem = Problem_1 = __decorate([ + TypeORM.Entity() + ], Problem); + return Problem; +}(common_1["default"])); +exports["default"] = Problem; +//# sourceMappingURL=problem.js.map \ No newline at end of file diff --git a/models-built/problem.js.map b/models-built/problem.js.map new file mode 100644 index 0000000..fada6a4 --- /dev/null +++ b/models-built/problem.js.map @@ -0,0 +1 @@ +{"version":3,"file":"problem.js","sourceRoot":"","sources":["../models/problem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAI7B,+BAA0B;AAC1B,+BAA0B;AAC1B,6CAAuC;AACvC,qCAAgC;AAChC,6CAAuC;AACvC,qDAA8C;AAC9C,iEAA+E;AAE/E,6BAA+B;AAC/B,2BAA6B;AAC7B,2BAA6B;AAC7B,oCAA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AAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;mCACrC;IAGf;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;uCACjC;IAInB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;sCACjC;IAGnB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;oCACnC;IAGjB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;+CACtB;IAG3B;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;gDACrB;IAI5B;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;kCACrC,IAAI;2CAAC;IAOrB;QALC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI;YAC5B,IAAI,EAAE,MAAM;YACZ,MAAI,EAAE,WAAW;YACjB,SAAO,EAAE,WAAW,CAAC,WAAW;SACnC,CAAC;;iCACgB;IAvEC,OAAO;QAD3B,OAAO,CAAC,MAAM,EAAE;OACI,OAAO,CAyjB3B;IAAD,cAAC;CAAA,AAzjBD,CAAqC,mBAAK,GAyjBzC;qBAzjBoB,OAAO"} \ No newline at end of file diff --git a/models-built/problem_tag.js b/models-built/problem_tag.js new file mode 100644 index 0000000..ce3cbf7 --- /dev/null +++ b/models-built/problem_tag.js @@ -0,0 +1,52 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var ProblemTag = /** @class */ (function (_super) { + __extends(ProblemTag, _super); + function ProblemTag() { + return _super !== null && _super.apply(this, arguments) || this; + } + ProblemTag.cache = true; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], ProblemTag.prototype, "id"); + __decorate([ + TypeORM.Index({ unique: true }), + TypeORM.Column({ nullable: true, type: "varchar", length: 255 }), + __metadata("design:type", String) + ], ProblemTag.prototype, "name"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 255 }), + __metadata("design:type", String) + ], ProblemTag.prototype, "color"); + ProblemTag = __decorate([ + TypeORM.Entity() + ], ProblemTag); + return ProblemTag; +}(common_1["default"])); +exports["default"] = ProblemTag; +//# sourceMappingURL=problem_tag.js.map \ No newline at end of file diff --git a/models-built/problem_tag.js.map b/models-built/problem_tag.js.map new file mode 100644 index 0000000..e18249a --- /dev/null +++ b/models-built/problem_tag.js.map @@ -0,0 +1 @@ +{"version":3,"file":"problem_tag.js","sourceRoot":"","sources":["../models/problem_tag.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAG7B;IAAwC,8BAAK;IAA7C;;IAYA,CAAC;IAXQ,gBAAK,GAAG,IAAI,CAAC;IAGpB;QADC,OAAO,CAAC,sBAAsB,EAAE;;kCACtB;IAIX;QAFC,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC/B,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;oCACpD;IAGb;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;qCACnD;IAXK,UAAU;QAD9B,OAAO,CAAC,MAAM,EAAE;OACI,UAAU,CAY9B;IAAD,iBAAC;CAAA,AAZD,CAAwC,mBAAK,GAY5C;qBAZoB,UAAU"} \ No newline at end of file diff --git a/models-built/problem_tag_map.js b/models-built/problem_tag_map.js new file mode 100644 index 0000000..2aab8c5 --- /dev/null +++ b/models-built/problem_tag_map.js @@ -0,0 +1,48 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var ProblemTagMap = /** @class */ (function (_super) { + __extends(ProblemTagMap, _super); + function ProblemTagMap() { + return _super !== null && _super.apply(this, arguments) || this; + } + __decorate([ + TypeORM.Index(), + TypeORM.PrimaryColumn({ type: "integer" }), + __metadata("design:type", Number) + ], ProblemTagMap.prototype, "problem_id"); + __decorate([ + TypeORM.Index(), + TypeORM.PrimaryColumn({ type: "integer" }), + __metadata("design:type", Number) + ], ProblemTagMap.prototype, "tag_id"); + ProblemTagMap = __decorate([ + TypeORM.Entity() + ], ProblemTagMap); + return ProblemTagMap; +}(common_1["default"])); +exports["default"] = ProblemTagMap; +//# sourceMappingURL=problem_tag_map.js.map \ No newline at end of file diff --git a/models-built/problem_tag_map.js.map b/models-built/problem_tag_map.js.map new file mode 100644 index 0000000..405e799 --- /dev/null +++ b/models-built/problem_tag_map.js.map @@ -0,0 +1 @@ +{"version":3,"file":"problem_tag_map.js","sourceRoot":"","sources":["../models/problem_tag_map.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAG7B;IAA2C,iCAAK;IAAhD;;IAQA,CAAC;IALC;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;6CACxB;IAInB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;yCAC5B;IAPI,aAAa;QADjC,OAAO,CAAC,MAAM,EAAE;OACI,aAAa,CAQjC;IAAD,oBAAC;CAAA,AARD,CAA2C,mBAAK,GAQ/C;qBARoB,aAAa"} \ No newline at end of file diff --git a/models-built/rating_calculation.js b/models-built/rating_calculation.js new file mode 100644 index 0000000..f6d53d5 --- /dev/null +++ b/models-built/rating_calculation.js @@ -0,0 +1,149 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var contest_1 = require("./contest"); +var rating_history_1 = require("./rating_history"); +var RatingCalculation = /** @class */ (function (_super) { + __extends(RatingCalculation, _super); + function RatingCalculation() { + return _super !== null && _super.apply(this, arguments) || this; + } + RatingCalculation.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = this; + return [4 /*yield*/, contest_1["default"].findById(this.contest_id)]; + case 1: + _a.contest = _b.sent(); + return [2 /*return*/]; + } + }); + }); + }; + RatingCalculation.prototype["delete"] = function () { + return __awaiter(this, void 0, void 0, function () { + var histories, _i, histories_1, history_1, user, ratingItem; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, rating_history_1["default"].find({ + where: { + rating_calculation_id: this.id + } + })]; + case 1: + histories = _a.sent(); + _i = 0, histories_1 = histories; + _a.label = 2; + case 2: + if (!(_i < histories_1.length)) return [3 /*break*/, 8]; + history_1 = histories_1[_i]; + return [4 /*yield*/, history_1.loadRelationships()]; + case 3: + _a.sent(); + user = history_1.user; + return [4 /*yield*/, history_1.destroy()]; + case 4: + _a.sent(); + return [4 /*yield*/, rating_history_1["default"].findOne({ + where: { + user_id: user.id + }, + order: { + rating_calculation_id: 'DESC' + } + })]; + case 5: + ratingItem = (_a.sent()); + user.rating = ratingItem ? ratingItem.rating_after : syzoj.config["default"].user.rating; + return [4 /*yield*/, user.save()]; + case 6: + _a.sent(); + _a.label = 7; + case 7: + _i++; + return [3 /*break*/, 2]; + case 8: return [4 /*yield*/, this.destroy()]; + case 9: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], RatingCalculation.prototype, "id"); + __decorate([ + TypeORM.Index({}), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], RatingCalculation.prototype, "contest_id"); + RatingCalculation = __decorate([ + TypeORM.Entity() + ], RatingCalculation); + return RatingCalculation; +}(common_1["default"])); +exports["default"] = RatingCalculation; +//# sourceMappingURL=rating_calculation.js.map \ No newline at end of file diff --git a/models-built/rating_calculation.js.map b/models-built/rating_calculation.js.map new file mode 100644 index 0000000..055e7dd --- /dev/null +++ b/models-built/rating_calculation.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rating_calculation.js","sourceRoot":"","sources":["../models/rating_calculation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAC;;;;;KACtB;IAlCD;QADC,OAAO,CAAC,sBAAsB,EAAE;;yCACtB;IAIX;QAFC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;iDACjC;IANA,iBAAiB;QADrC,OAAO,CAAC,MAAM,EAAE;OACI,iBAAiB,CAqCrC;IAAD,wBAAC;CAAA,AArCD,CAA+C,mBAAK,GAqCnD;qBArCoB,iBAAiB"} \ No newline at end of file diff --git a/models-built/rating_history.js b/models-built/rating_history.js new file mode 100644 index 0000000..5144b4c --- /dev/null +++ b/models-built/rating_history.js @@ -0,0 +1,105 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var user_1 = require("./user"); +var RatingHistory = /** @class */ (function (_super) { + __extends(RatingHistory, _super); + function RatingHistory() { + return _super !== null && _super.apply(this, arguments) || this; + } + RatingHistory.prototype.loadRelationships = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = this; + return [4 /*yield*/, user_1["default"].findById(this.user_id)]; + case 1: + _a.user = _b.sent(); + return [2 /*return*/]; + } + }); + }); + }; + __decorate([ + TypeORM.PrimaryColumn({ type: "integer" }), + __metadata("design:type", Number) + ], RatingHistory.prototype, "rating_calculation_id"); + __decorate([ + TypeORM.PrimaryColumn({ type: "integer" }), + __metadata("design:type", Number) + ], RatingHistory.prototype, "user_id"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], RatingHistory.prototype, "rating_after"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], RatingHistory.prototype, "rank"); + RatingHistory = __decorate([ + TypeORM.Entity() + ], RatingHistory); + return RatingHistory; +}(common_1["default"])); +exports["default"] = RatingHistory; +//# sourceMappingURL=rating_history.js.map \ No newline at end of file diff --git a/models-built/rating_history.js.map b/models-built/rating_history.js.map new file mode 100644 index 0000000..f043415 --- /dev/null +++ b/models-built/rating_history.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rating_history.js","sourceRoot":"","sources":["../models/rating_history.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAI7B,+BAA0B;AAG1B;IAA2C,iCAAK;IAAhD;;IAkBA,CAAC;IAHO,yCAAiB,GAAvB;;;;;;wBACE,KAAA,IAAI,CAAA;wBAAQ,qBAAM,iBAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAA;;wBAA7C,GAAK,IAAI,GAAG,SAAiC,CAAC;;;;;KAC/C;IAfD;QADC,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wDACb;IAG9B;QADC,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;0CAC3B;IAGhB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;+CAC/B;IAGrB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;uCACvC;IAXM,aAAa;QADjC,OAAO,CAAC,MAAM,EAAE;OACI,aAAa,CAkBjC;IAAD,oBAAC;CAAA,AAlBD,CAA2C,mBAAK,GAkB/C;qBAlBoB,aAAa"} \ No newline at end of file diff --git a/models-built/submission_statistics.js b/models-built/submission_statistics.js new file mode 100644 index 0000000..8bba513 --- /dev/null +++ b/models-built/submission_statistics.js @@ -0,0 +1,71 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var StatisticsType; +(function (StatisticsType) { + StatisticsType["FASTEST"] = "fastest"; + StatisticsType["SLOWEST"] = "slowest"; + StatisticsType["SHORTEST"] = "shortest"; + StatisticsType["LONGEST"] = "longest"; + StatisticsType["MEMORY_MIN"] = "min"; + StatisticsType["MEMORY_MAX"] = "max"; + StatisticsType["EARLIEST"] = "earliest"; +})(StatisticsType = exports.StatisticsType || (exports.StatisticsType = {})); +var SubmissionStatistics = /** @class */ (function (_super) { + __extends(SubmissionStatistics, _super); + function SubmissionStatistics() { + return _super !== null && _super.apply(this, arguments) || this; + } + SubmissionStatistics.cache = false; + __decorate([ + TypeORM.PrimaryColumn({ type: "integer" }), + __metadata("design:type", Number) + ], SubmissionStatistics.prototype, "problem_id"); + __decorate([ + TypeORM.PrimaryColumn({ type: "integer" }), + __metadata("design:type", Number) + ], SubmissionStatistics.prototype, "user_id"); + __decorate([ + TypeORM.PrimaryColumn({ type: "enum", "enum": StatisticsType }), + __metadata("design:type", String) + ], SubmissionStatistics.prototype, "type"); + __decorate([ + TypeORM.Column({ type: "integer" }), + __metadata("design:type", Number) + ], SubmissionStatistics.prototype, "key"); + __decorate([ + TypeORM.Column({ type: "integer" }), + __metadata("design:type", Number) + ], SubmissionStatistics.prototype, "submission_id"); + SubmissionStatistics = __decorate([ + TypeORM.Entity(), + TypeORM.Index(['problem_id', 'type', 'key']) + ], SubmissionStatistics); + return SubmissionStatistics; +}(common_1["default"])); +exports["default"] = SubmissionStatistics; +; +//# sourceMappingURL=submission_statistics.js.map \ No newline at end of file diff --git a/models-built/submission_statistics.js.map b/models-built/submission_statistics.js.map new file mode 100644 index 0000000..520154b --- /dev/null +++ b/models-built/submission_statistics.js.map @@ -0,0 +1 @@ +{"version":3,"file":"submission_statistics.js","sourceRoot":"","sources":["../models/submission_statistics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAE7B,IAAY,cAQX;AARD,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;IACnB,uCAAqB,CAAA;IACrB,qCAAmB,CAAA;IACnB,oCAAkB,CAAA;IAClB,oCAAkB,CAAA;IAClB,uCAAqB,CAAA;AACvB,CAAC,EARW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAQzB;AAID;IAAkD,wCAAK;IAAvD;;IAiBA,CAAC;IAhBQ,0BAAK,GAAG,KAAK,CAAC;IAGrB;QADC,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;oDACxB;IAGnB;QADC,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;iDAC3B;IAGhB;QADC,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAI,EAAE,cAAc,EAAE,CAAC;;8CACzC;IAGrB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;6CACxB;IAGZ;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;uDACd;IAhBH,oBAAoB;QAFxC,OAAO,CAAC,MAAM,EAAE;QAChB,OAAO,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;OACxB,oBAAoB,CAiBxC;IAAD,2BAAC;CAAA,AAjBD,CAAkD,mBAAK,GAiBtD;qBAjBoB,oBAAoB;AAiBxC,CAAC"} \ No newline at end of file diff --git a/models-built/user.js b/models-built/user.js new file mode 100644 index 0000000..c8713fd --- /dev/null +++ b/models-built/user.js @@ -0,0 +1,428 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var judge_state_1 = require("./judge_state"); +var user_privilege_1 = require("./user_privilege"); +var article_1 = require("./article"); +var User = /** @class */ (function (_super) { + __extends(User, _super); + function User() { + return _super !== null && _super.apply(this, arguments) || this; + } + User_1 = User; + User.fromEmail = function (email) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, User_1.findOne({ + where: { + email: email + } + })]; + }); + }); + }; + User.fromName = function (name) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, User_1.findOne({ + where: { + username: name + } + })]; + }); + }); + }; + User.prototype.isAllowedEditBy = function (user) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!user) + return [2 /*return*/, false]; + return [4 /*yield*/, user.hasPrivilege('manage_user')]; + case 1: + if (_a.sent()) + return [2 /*return*/, true]; + return [2 /*return*/, user && (user.is_admin || this.id === user.id)]; + } + }); + }); + }; + User.prototype.getQueryBuilderForACProblems = function () { + return judge_state_1["default"].createQueryBuilder() + .select("DISTINCT(problem_id)") + .where('user_id = :user_id', { user_id: this.id }) + .andWhere('status = :status', { status: 'Accepted' }) + .andWhere('type != 1') + .orderBy({ problem_id: 'ASC' }); + }; + User.prototype.refreshSubmitInfo = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, syzoj.utils.lock(['User::refreshSubmitInfo', this.id], function () { return __awaiter(_this, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + _a = this; + return [4 /*yield*/, judge_state_1["default"].countQuery(this.getQueryBuilderForACProblems())]; + case 1: + _a.ac_num = _c.sent(); + _b = this; + return [4 /*yield*/, judge_state_1["default"].count({ + user_id: this.id, + type: TypeORM.Not(1) // Not a contest submission + })]; + case 2: + _b.submit_num = _c.sent(); + return [4 /*yield*/, this.save()]; + case 3: + _c.sent(); + return [2 /*return*/]; + } + }); + }); })]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + }; + User.prototype.getACProblems = function () { + return __awaiter(this, void 0, void 0, function () { + var queryResult; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.getQueryBuilderForACProblems().getRawMany()]; + case 1: + queryResult = _a.sent(); + return [2 /*return*/, queryResult.map(function (record) { return record['problem_id']; })]; + } + }); + }); + }; + User.prototype.getArticles = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, article_1["default"].find({ + where: { + user_id: this.id + } + })]; + case 1: return [2 /*return*/, _a.sent()]; + } + }); + }); + }; + User.prototype.getStatistics = function () { + return __awaiter(this, void 0, void 0, function () { + var statuses, res, _a, _b, _i, status_1, _c, _d, s, _e, _f, _g; + return __generator(this, function (_h) { + switch (_h.label) { + case 0: + statuses = { + "Accepted": ["Accepted"], + "Wrong Answer": ["Wrong Answer", "File Error", "Output Limit Exceeded"], + "Runtime Error": ["Runtime Error"], + "Time Limit Exceeded": ["Time Limit Exceeded"], + "Memory Limit Exceeded": ["Memory Limit Exceeded"], + "Compile Error": ["Compile Error"] + }; + res = {}; + _a = []; + for (_b in statuses) + _a.push(_b); + _i = 0; + _h.label = 1; + case 1: + if (!(_i < _a.length)) return [3 /*break*/, 6]; + status_1 = _a[_i]; + res[status_1] = 0; + _c = 0, _d = statuses[status_1]; + _h.label = 2; + case 2: + if (!(_c < _d.length)) return [3 /*break*/, 5]; + s = _d[_c]; + _e = res; + _f = status_1; + _g = _e[_f]; + return [4 /*yield*/, judge_state_1["default"].count({ + user_id: this.id, + type: 0, + status: s + })]; + case 3: + _e[_f] = _g + _h.sent(); + _h.label = 4; + case 4: + _c++; + return [3 /*break*/, 2]; + case 5: + _i++; + return [3 /*break*/, 1]; + case 6: return [2 /*return*/, res]; + } + }); + }); + }; + User.prototype.renderInformation = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = this; + return [4 /*yield*/, syzoj.utils.markdown(this.information)]; + case 1: + _a.information = _b.sent(); + return [2 /*return*/]; + } + }); + }); + }; + User.prototype.getPrivileges = function () { + return __awaiter(this, void 0, void 0, function () { + var privileges; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, user_privilege_1["default"].find({ + where: { + user_id: this.id + } + })]; + case 1: + privileges = _a.sent(); + return [2 /*return*/, privileges.map(function (x) { return x.privilege; })]; + } + }); + }); + }; + User.prototype.setPrivileges = function (newPrivileges) { + return __awaiter(this, void 0, void 0, function () { + var oldPrivileges, delPrivileges, addPrivileges, _i, delPrivileges_1, privilege, obj, _a, addPrivileges_1, privilege, obj; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: return [4 /*yield*/, this.getPrivileges()]; + case 1: + oldPrivileges = _b.sent(); + delPrivileges = oldPrivileges.filter(function (x) { return !newPrivileges.includes(x); }); + addPrivileges = newPrivileges.filter(function (x) { return !oldPrivileges.includes(x); }); + _i = 0, delPrivileges_1 = delPrivileges; + _b.label = 2; + case 2: + if (!(_i < delPrivileges_1.length)) return [3 /*break*/, 6]; + privilege = delPrivileges_1[_i]; + return [4 /*yield*/, user_privilege_1["default"].findOne({ where: { + user_id: this.id, + privilege: privilege + } })]; + case 3: + obj = _b.sent(); + return [4 /*yield*/, obj.destroy()]; + case 4: + _b.sent(); + _b.label = 5; + case 5: + _i++; + return [3 /*break*/, 2]; + case 6: + _a = 0, addPrivileges_1 = addPrivileges; + _b.label = 7; + case 7: + if (!(_a < addPrivileges_1.length)) return [3 /*break*/, 11]; + privilege = addPrivileges_1[_a]; + return [4 /*yield*/, user_privilege_1["default"].create({ + user_id: this.id, + privilege: privilege + })]; + case 8: + obj = _b.sent(); + return [4 /*yield*/, obj.save()]; + case 9: + _b.sent(); + _b.label = 10; + case 10: + _a++; + return [3 /*break*/, 7]; + case 11: return [2 /*return*/]; + } + }); + }); + }; + User.prototype.hasPrivilege = function (privilege) { + return __awaiter(this, void 0, void 0, function () { + var x; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (this.is_admin) + return [2 /*return*/, true]; + return [4 /*yield*/, user_privilege_1["default"].findOne({ where: { user_id: this.id, privilege: privilege } })]; + case 1: + x = _a.sent(); + return [2 /*return*/, !!x]; + } + }); + }); + }; + User.prototype.getLastSubmitLanguage = function () { + return __awaiter(this, void 0, void 0, function () { + var a; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, judge_state_1["default"].findOne({ + where: { + user_id: this.id + }, + order: { + submit_time: 'DESC' + } + })]; + case 1: + a = _a.sent(); + if (a) + return [2 /*return*/, a.language]; + return [2 /*return*/, null]; + } + }); + }); + }; + var User_1; + User.cache = true; + __decorate([ + TypeORM.PrimaryGeneratedColumn(), + __metadata("design:type", Number) + ], User.prototype, "id"); + __decorate([ + TypeORM.Index({ unique: true }), + TypeORM.Column({ nullable: true, type: "varchar", length: 80 }), + __metadata("design:type", String) + ], User.prototype, "username"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 120 }), + __metadata("design:type", String) + ], User.prototype, "email"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 120 }), + __metadata("design:type", String) + ], User.prototype, "password"); + __decorate([ + TypeORM.Column({ nullable: true, type: "varchar", length: 80 }), + __metadata("design:type", String) + ], User.prototype, "nickname"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], User.prototype, "nameplate"); + __decorate([ + TypeORM.Column({ nullable: true, type: "text" }), + __metadata("design:type", String) + ], User.prototype, "information"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], User.prototype, "ac_num"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], User.prototype, "submit_num"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], User.prototype, "is_admin"); + __decorate([ + TypeORM.Index(), + TypeORM.Column({ nullable: true, type: "boolean" }), + __metadata("design:type", Boolean) + ], User.prototype, "is_show"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean", "default": true }), + __metadata("design:type", Boolean) + ], User.prototype, "public_email"); + __decorate([ + TypeORM.Column({ nullable: true, type: "boolean", "default": true }), + __metadata("design:type", Boolean) + ], User.prototype, "prefer_formatted_code"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], User.prototype, "sex"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], User.prototype, "rating"); + __decorate([ + TypeORM.Column({ nullable: true, type: "integer" }), + __metadata("design:type", Number) + ], User.prototype, "register_time"); + User = User_1 = __decorate([ + TypeORM.Entity() + ], User); + return User; +}(common_1["default"])); +exports["default"] = User; +//# sourceMappingURL=user.js.map \ No newline at end of file diff --git a/models-built/user.js.map b/models-built/user.js.map new file mode 100644 index 0000000..6eea32f --- /dev/null +++ b/models-built/user.js.map @@ -0,0 +1 @@ +{"version":3,"file":"user.js","sourceRoot":"","sources":["../models/user.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;oCACjC;IAGnB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;kCAClC;IAIlB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;iCACnC;IAGjB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAO,EAAE,IAAI,EAAE,CAAC;;sCAC7C;IAGtB;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAO,EAAE,IAAI,EAAE,CAAC;;+CACpC;IAG/B;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;6BACxC;IAGZ;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;gCACrC;IAGf;QADC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;uCAC9B;IArDH,IAAI;QADxB,OAAO,CAAC,MAAM,EAAE;OACI,IAAI,CAoMxB;IAAD,WAAC;CAAA,AApMD,CAAkC,mBAAK,GAoMtC;qBApMoB,IAAI"} \ No newline at end of file diff --git a/models-built/user_privilege.js b/models-built/user_privilege.js new file mode 100644 index 0000000..bfef9da --- /dev/null +++ b/models-built/user_privilege.js @@ -0,0 +1,48 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +exports.__esModule = true; +var TypeORM = require("typeorm"); +var common_1 = require("./common"); +var UserPrivilege = /** @class */ (function (_super) { + __extends(UserPrivilege, _super); + function UserPrivilege() { + return _super !== null && _super.apply(this, arguments) || this; + } + __decorate([ + TypeORM.Index(), + TypeORM.PrimaryColumn({ type: "integer" }), + __metadata("design:type", Number) + ], UserPrivilege.prototype, "user_id"); + __decorate([ + TypeORM.Index(), + TypeORM.PrimaryColumn({ type: "varchar", length: 80 }), + __metadata("design:type", String) + ], UserPrivilege.prototype, "privilege"); + UserPrivilege = __decorate([ + TypeORM.Entity() + ], UserPrivilege); + return UserPrivilege; +}(common_1["default"])); +exports["default"] = UserPrivilege; +//# sourceMappingURL=user_privilege.js.map \ No newline at end of file diff --git a/models-built/user_privilege.js.map b/models-built/user_privilege.js.map new file mode 100644 index 0000000..3765145 --- /dev/null +++ b/models-built/user_privilege.js.map @@ -0,0 +1 @@ +{"version":3,"file":"user_privilege.js","sourceRoot":"","sources":["../models/user_privilege.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAG7B;IAA2C,iCAAK;IAAhD;;IAQA,CAAC;IALC;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;0CAC3B;IAIhB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;;4CACrC;IAPC,aAAa;QADjC,OAAO,CAAC,MAAM,EAAE;OACI,aAAa,CAQjC;IAAD,oBAAC;CAAA,AARD,CAA2C,mBAAK,GAQ/C;qBARoB,aAAa"} \ No newline at end of file diff --git a/models/judge_state.ts b/models/judge_state.ts index 065f67f..1ba345d 100644 --- a/models/judge_state.ts +++ b/models/judge_state.ts @@ -188,4 +188,14 @@ export default class JudgeState extends Model { await this.loadRelationships(); return this.problem.type; } + + async share() { + this.is_public = true; + try { + await this.save(); + } catch (err) { + console.log("Error while share this judge:" + err.toString()); + throw new ErrorMessage("分享失败。"); + } + } } diff --git a/modules/contest.js b/modules/contest.js index d74f617..85c9ec9 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -291,7 +291,8 @@ function getDisplayConfig(contest) { showDetailResult: contest.allowedSeeingTestcase(), showTestdata: false, inContest: true, - showRejudge: false + showRejudge: false, + showShare: false }; } diff --git a/modules/submission.js b/modules/submission.js index d029602..3e0f9c4 100644 --- a/modules/submission.js +++ b/modules/submission.js @@ -16,7 +16,8 @@ const displayConfig = { showTestdata: true, showDetailResult: true, inContest: false, - showRejudge: false + showRejudge: false, + showShare: false }; // s is JudgeState @@ -188,20 +189,33 @@ app.get('/submission/:id', async (req, res) => { judge.code = await syzoj.utils.highlight(judge.code, syzoj.languages[judge.language].highlight); } - displayConfig.showRejudge = await judge.problem.isAllowedEditBy(res.locals.user); + let isAdmin = curUser === null ? false : curUser.is_admin; + let isAuthor = curUser === null ? false : curUser.id === judge.user_id; + + let currentConfig = Object.assign({}, displayConfig); + + currentConfig.showRejudge = await judge.problem.isAllowedEditBy(res.locals.user); + if (isAdmin || isAuthor) { + currentConfig.showShare = true; + } + if (isAdmin || isAuthor || judge.is_public) { + judge.code = (judge.problem.type !== 'submit-answer') ? judge.code.toString("utf8") : ''; + } else { + judge.code = "作者没有开放此题代码,请联系作者分享。"; + } res.render('submission', { - info: getSubmissionInfo(judge, displayConfig), - roughResult: getRoughResult(judge, displayConfig, false), - code: (judge.problem.type !== 'submit-answer') ? judge.code.toString("utf8") : '', + info: getSubmissionInfo(judge, currentConfig), + roughResult: getRoughResult(judge, currentConfig, false), + code: judge.code, formattedCode: judge.formattedCode ? judge.formattedCode.toString("utf8") : null, preferFormattedCode: res.locals.user ? res.locals.user.prefer_formatted_code : true, - detailResult: processOverallResult(judge.result, displayConfig), + detailResult: processOverallResult(judge.result, currentConfig), socketToken: (judge.pending && judge.task_id != null) ? jwt.sign({ taskId: judge.task_id, type: 'detail', displayConfig: displayConfig }, syzoj.config.session_secret) : null, - displayConfig: displayConfig, + displayConfig: currentConfig, }); } catch (e) { syzoj.log(e); @@ -233,3 +247,26 @@ app.post('/submission/:id/rejudge', async (req, res) => { }); } }); +// 分享评测实现 +app.post('/submission/:id/share', async (req, res) => { + try { + let id = parseInt(req.params.id); + let judge = await JudgeState.findById(id); + + await judge.loadRelationships(); + + let allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user); + if (!allowedRejudge) { + throw new ErrorMessage('您没有权限进行此操作。'); + } + + await judge.share(); + + res.redirect(syzoj.utils.makeUrl(['submission', id])); + } catch (e) { + syzoj.log(e); + res.render('error', { + err: e + }); + } +}); diff --git a/views/submission.ejs b/views/submission.ejs index 7fdffc2..89c3eb6 100644 --- a/views/submission.ejs +++ b/views/submission.ejs @@ -44,10 +44,11 @@ 提交者 提交时间 重新评测 + 分享 - + @@ -229,6 +230,9 @@ const vueApp = new Vue({ }, showRejudge() { return this.displayConfig.showRejudge && (!this.roughData.running); + }, + showShare() { + return this.displayConfig.showShare; } }, methods: { diff --git a/views/submissions.ejs b/views/submissions.ejs index 0de9650..a3dcc17 100644 --- a/views/submissions.ejs +++ b/views/submissions.ejs @@ -97,7 +97,7 @@ - + diff --git a/views/submissions_item.ejs b/views/submissions_item.ejs index f5fb1d4..5c094d1 100644 --- a/views/submissions_item.ejs +++ b/views/submissions_item.ejs @@ -2,141 +2,183 @@ <% include status_label %> <% if (active === 'submission') { %> - + <% } %>