richie
5 years ago
41 changed files with 4279 additions and 132 deletions
@ -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
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"article-comment.js","sourceRoot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;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"} |
@ -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
|
@ -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,CAAC,CAAC,iCAAiC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE;;;;;wCACnE,KAAA,IAAI,CAAA;wCAAgB,qBAAM,4BAAc,CAAC,KAAK,CAAC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AQ,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"} |
@ -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
|
File diff suppressed because one or more lines are too long
@ -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
|
@ -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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AAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;sCAClC;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"} |
@ -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
|
File diff suppressed because one or more lines are too long
@ -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
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"contest_ranklist.js","sourceRoot":"","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,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"} |
@ -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
|
@ -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,OA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CAAC,aAAa,CAAC,CAAC;;4BAC9D,sBAAO,IAAI,CAAC,SAAS,EAAC;;;;;KAC5B;;IAzED;QADC,OAAO,CAAC,sBAAsB,EAAE;;4BACtB;IAIX;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,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"} |
@ -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
|
@ -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"} |
@ -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
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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
|
@ -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"} |
@ -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
|
@ -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"} |
@ -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
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"rating_calculation.js","sourceRoot":"","sources":["../models/rating_calculation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAI7B,qCAAgC;AAChC,mDAA6C;AAG7C;IAA+C,qCAAK;IAApD;;IAqCA,CAAC;IA3BO,6CAAiB,GAAvB;;;;;;wBACE,KAAA,IAAI,CAAA;wBAAW,qBAAM,oBAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAA;;wBAAtD,GAAK,OAAO,GAAG,SAAuC,CAAC;;;;;KACxD;IAEK,4BAAA,QAAM,CAAA,GAAZ;;;;;4BACoB,qBAAM,2BAAa,CAAC,IAAI,CAAC;4BACzC,KAAK,EAAE;gCACL,qBAAqB,EAAE,IAAI,CAAC,EAAE;6BAC/B;yBACF,CAAC,EAAA;;wBAJI,SAAS,GAAG,SAIhB;8BAC6B,EAAT,uBAAS;;;6BAAT,CAAA,uBAAS,CAAA;wBAA1B;wBACH,qBAAM,SAAO,CAAC,iBAAiB,EAAE,EAAA;;wBAAjC,SAAiC,CAAC;wBAC5B,IAAI,GAAG,SAAO,CAAC,IAAI,CAAC;wBAC1B,qBAAM,SAAO,CAAC,OAAO,EAAE,EAAA;;wBAAvB,SAAuB,CAAC;wBACJ,qBAAM,2BAAa,CAAC,OAAO,CAAC;gCAC9C,KAAK,EAAE;oCACL,OAAO,EAAE,IAAI,CAAC,EAAE;iCACjB;gCACD,KAAK,EAAE;oCACL,qBAAqB,EAAE,MAAM;iCAC9B;6BACF,CAAC,EAAA;;wBAPI,UAAU,GAAG,CAAC,SAOlB,CAAC;wBACH,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAO,CAAA,CAAC,IAAI,CAAC,MAAM,CAAC;wBACtF,qBAAM,IAAI,CAAC,IAAI,EAAE,EAAA;;wBAAjB,SAAiB,CAAC;;;wBAbE,IAAS,CAAA;;4BAe/B,qBAAM,IAAI,CAAC,OAAO,EAAE,EAAA;;wBAApB,SAAoB,CAAC;;;;;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"} |
@ -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
|
@ -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"} |
@ -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
|
@ -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"} |
@ -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
|
File diff suppressed because one or more lines are too long
@ -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
|
@ -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"} |
Loading…
Reference in new issue