diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 3c6e562f9..5ea0a7f9d 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "3.1.11", + "version": "3.1.12", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/checkers.ts b/packages/hydrojudge/src/checkers.ts index fb93aec6f..46e3d8686 100644 --- a/packages/hydrojudge/src/checkers.ts +++ b/packages/hydrojudge/src/checkers.ts @@ -22,6 +22,36 @@ type Checker = (config: CheckConfig) => Promise<{ message: string, }>; +function parseDiffMsg(msg: string) { + try { + // Note: we only handle first diff + const desc = msg.split('\n')[0]; + if (desc.includes('d')) return 'User output longer than standard answer.'; + if (desc.includes('a')) return 'Standard answer longer than user output.'; + const pt = msg.split('---'); + // Get the first different line + const u = pt[0].split('\n')[1]; + const t = pt[1].split('\n')[1]; + // Split by token + const usr = u.substring(2).trim().split(' '); + const std = t.substring(2).trim().split(' '); + if (std.every((x) => !Number.isNaN(+x))) { + // Number mode, report length not match + if (usr.length > std.length) return 'User output longer than standard answer.'; + if (usr.length < std.length) return 'Standard answer longer than user output.'; + } + for (let i = 0; i < usr.length; i++) { + if (usr[i] === std[i]) continue; + const usrString = usr[i].length > 20 ? `${usr[i].substring(0, 16)}...` : usr[i]; + const stdString = std[i].length > 20 ? `${std[i].substring(0, 16)}...` : std[i]; + return { message: 'Read {0}, expect {1}.', params: [usrString, stdString] }; + } + throw new Error(); + } catch (e) { + return msg.substring(0, msg.length - 1 <= 30 ? msg.length - 1 : 30); + } +} + const checkers: Record = new Proxy({ async default(config) { const { stdout } = await run('/usr/bin/diff -BZ usrout answer', { @@ -35,33 +65,7 @@ const checkers: Record = new Proxy({ let message: any = ''; if (stdout) { status = STATUS.STATUS_WRONG_ANSWER; - if (config.detail) { - try { - const pt = stdout.split('---'); - const u = pt[0].split('\n')[1]; - const usr = u.substring(2).trim().split(' '); - const t = pt[1].split('\n')[1]; - const std = t.substring(2).trim().split(' '); - if (usr.length < std.length) message = 'Standard answer longer than user output.'; - else if (usr.length > std.length) message = 'User output longer than standard answer.'; - else { - let usrString = usr[0]; - let stdString = std[0]; - for (const i in usr) { - if (usr[i] !== std[i]) { - usrString = usr[i]; - stdString = std[i]; - break; - } - } - if (usrString.length > 20) usrString = `${usrString.substring(0, 16)}...`; - if (stdString.length > 20) stdString = `${stdString.substring(0, 16)}...`; - message = { message: 'Read {0}, expect {1}.', params: [usrString, stdString] }; - } - } catch (e) { - message = stdout.substring(0, stdout.length - 1 <= 30 ? stdout.length - 1 : 30); - } - } + if (config.detail) message = parseDiffMsg(stdout); } else status = STATUS.STATUS_ACCEPTED; if (message.length > 1024000) message = ''; return { diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index c16ec109d..886aaeefb 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "4.4.4", + "version": "4.4.5", "bin": "bin/hydrooj.js", "main": "src/plugin-api", "module": "src/plugin-api", diff --git a/packages/onlyoffice/package.json b/packages/onlyoffice/package.json index a465d7ac2..95d1084a7 100644 --- a/packages/onlyoffice/package.json +++ b/packages/onlyoffice/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/onlyoffice", - "version": "1.3.0", + "version": "1.3.1", "main": "index.ts", "repository": "git@github.com:hydro-dev/Hydro.git", "author": "undefined ", diff --git a/packages/ui-default/components/message/index.page.ts b/packages/ui-default/components/message/index.page.ts index 6914a140e..b73698002 100644 --- a/packages/ui-default/components/message/index.page.ts +++ b/packages/ui-default/components/message/index.page.ts @@ -8,7 +8,6 @@ import { i18n, tpl } from 'vj/utils'; const onmessage = (msg) => { console.log('Received message', msg); - if (document.hidden) return false; if (msg.mdoc.flag & FLAG_ALERT) { // Is alert new InfoDialog({ @@ -21,6 +20,7 @@ const onmessage = (msg) => { }).open(); return true; } + if (document.hidden) return false; // Is message new VjNotification({ ...(msg.udoc._id === 1 && msg.mdoc.flag & 4) diff --git a/packages/ui-default/components/notification/index.js b/packages/ui-default/components/notification/index.ts similarity index 78% rename from packages/ui-default/components/notification/index.js rename to packages/ui-default/components/notification/index.ts index 3709dbbaf..f1ad49f2b 100644 --- a/packages/ui-default/components/notification/index.js +++ b/packages/ui-default/components/notification/index.ts @@ -12,12 +12,28 @@ export const AppToaster = Toaster.create({ className: 'recipe-toaster', position: Position.LEFT_BOTTOM, usePortal: true, -}, ToasterContainer); +} as any, ToasterContainer); + +interface NotificationOptions { + avatar?: string; + title?: string; + message: string; + type?: string; + duration?: number; + action?: any; +} export default class Notification { + type: string; + action: any; + $dom: JQuery; + $n: JQuery; + duration: number; + autoHideTimer?: NodeJS.Timeout; + constructor({ avatar, title, message, type = '', duration = 3000, action, - }) { + }: NotificationOptions) { this.type = type; if (avatar) this.type += ' avatar'; if (title) this.type += ' title'; @@ -49,19 +65,19 @@ export default class Notification { setTimeout(() => this.$n.remove(), 200); } - static success(message, duration) { + static success(message: string, duration?: number) { return AppToaster.show({ message, timeout: duration, intent: Intent.SUCCESS }); } - static info(message, duration) { + static info(message: string, duration?: number) { return AppToaster.show({ message, timeout: duration, intent: Intent.PRIMARY }); } - static warn(message, duration) { + static warn(message: string, duration?: number) { return AppToaster.show({ message, timeout: duration, intent: Intent.WARNING }); } - static error(message, duration) { + static error(message: string, duration?: number) { return AppToaster.show({ message, timeout: duration, intent: Intent.DANGER }); } } diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index 4374c2ec6..0877a5c25 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.42.21", + "version": "4.43.0", "author": "undefined ", "license": "AGPL-3.0", "main": "index.ts", diff --git a/packages/ui-default/templates/layout/basic.html b/packages/ui-default/templates/layout/basic.html index 0f179e580..c9c022c37 100644 --- a/packages/ui-default/templates/layout/basic.html +++ b/packages/ui-default/templates/layout/basic.html @@ -7,7 +7,7 @@ {% if UserContext %}{% include "partials/header_mobile.html" %}{% endif %}
{% for item in ui.getNodes('Notification').concat(notification or []) %}{% if item.checker(handler) %} -
{{ _(item.name).format(item.args.args or []) }}
+
{{ _(item.name).format(item.args.args or [])|nl2br|safe }}
{% endif %}{% endfor %} {% block content %}{% endblock %}
diff --git a/packages/ui-default/templates/user_detail.html b/packages/ui-default/templates/user_detail.html index 437ad4143..c26dc3512 100644 --- a/packages/ui-default/templates/user_detail.html +++ b/packages/ui-default/templates/user_detail.html @@ -5,7 +5,7 @@ {{ set(UiContext, 'udoc', udoc) }}
diff --git a/packages/utils/package.json b/packages/utils/package.json index e843ea7de..a57c1f146 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/utils", - "version": "1.4.4", + "version": "1.4.5", "description": "hydrooj utils", "main": "lib/utils.ts", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/vjudge/package.json b/packages/vjudge/package.json index d1418e97b..122e6e921 100644 --- a/packages/vjudge/package.json +++ b/packages/vjudge/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/vjudge", - "version": "1.7.0", + "version": "1.7.1", "description": "Submit problems to remote oj", "main": "package.json", "repository": "https://github.com/hydro-dev/Hydro.git",